0

I'm using RichTextBox Control in Winform.

Recently I found a weird thing such like a Bug, I really can't find a way to fix it.

1.I have a RichTextBox in Form.

2.I clicked and selected some place in RichTextBox.

3.I clicked any other place on desktop (just for Deactivate the Form).[important]

4.Then I use mouse wheel change the RichTextBox scroll bar to some place (but the Form still in Deactivate state).

5.Now I click the RichTextBox after scrolled by mouse wheel. But you will find the current scrollbar position change to the old place.

This is the gif image for display the details:

enter image description here

I really hope the new clicked place will selected, and the scroll bar not changing to old selected position.

Is there any one know Why this is happening? Is there any way to fix this? Thanks.

Update:

I think maybe the problem is because the cursor in the RichTextBox, If we could remove it, maybe it will not go back to the old cursor position when we click next time, Is there any way to do it? Like remove the cursor everytime when the RichTextBox lost focus.

Another way might be possible is: turn current cursor position to the current scroll bar position every time when you move scroll bar or use mouse wheel.

Update2

I uploaded the project file and record video : https://drive.google.com/file/d/1rY_5mxKR6zOPqHBIOVaARee14-Ietise/view?usp=sharing

You could download and check.(I will delete it later.)

Version Windows 10 Professional
VersionNo   22H2
NT version  19045.2251
qakmak
  • 1,287
  • 9
  • 31
  • 62
  • Read the notes here: [DropDown List separated from the ComboBox in a scrollable Panel](https://stackoverflow.com/a/68011637/7444103) (you though that the effect you see on the RichTextBox is *weird* :) – Jimi Nov 22 '22 at 12:14
  • Anyway, the Form should activate first in this case (which should update the position of ScrollBars). Do you have any code in there? -- What .Net version? – Jimi Nov 22 '22 at 12:46
  • @Jimi Nope, I don't have any code in it, I just put a `RichTextBox` in `Form`, That's all. I'm using `.Net 7 (.Net Core)` with `Win10`. – qakmak Nov 22 '22 at 14:37
  • In this specific case, I cannot replicate the behavior described -- Unless it's something related to the software that generates the animation, there's something weird there: when you move the Mouse Pointer outside the RichTextBox Control, the Pointer retains the I-Beam shape, instead of changing (immediately) to the Arrow shape. If that's what is actually happening, you have something else going on (not saying something you did. Is that Form shown as usual, or are you creating it in some specific way? Is this a WinForms app or Console app / PowerShell that shows a Form?) – Jimi Nov 22 '22 at 14:52
  • @Jimi, I think that's a video recording issue(I mean the mouse icon), so don't worry about it, can't you replicate it? That's really weird. Do you click the desktop let the `Form` turn to `Deactivate` before scrolling by mouse wheel? I'ts just a ordinary Winform application. – qakmak Nov 22 '22 at 15:01
  • I did replicate the steps you mentioned. The first click inside the RTB activates the Form, the RTB is not selected. A second click sets the caret to the insertion point, the Control doesn't scroll to the previous insertion point. It does scroll if you use, e.g., the arrow keys instead of the Mouse pointer, but that's expected – Jimi Nov 22 '22 at 15:12
  • @Jimi, It's 3 clicks. 1- click in RTB, 2- click on desktop (out of Form), then use mouse wheel change scroll then 3- click in new position in RTB. – qakmak Nov 22 '22 at 15:21
  • That's what I said. I'm just referring to what happens **after** the Form has been deactivated. The first click re-activates the Form, the second sets the focus to the RTB and also sets the insertion point. Also, as mentioned, if instead of clicking I use the arrow keys, then the RTB scrolls to the insertion point previously set, otherwise it doesn't -- The possible difference is that I'm forced to test this in a Windows 10 1809 Enterprise. I don't remember a similar behavior in more recent versions of the System, maybe someone else can do that and report back – Jimi Nov 22 '22 at 15:32
  • I've tested in other Systems, including Window 11. I cannot reproduce the behavior described here. Can you post a link, to download that Project? – Jimi Nov 25 '22 at 00:03
  • I've tried same, but in my case scroll position is change to last position when I'm trying to type in textbox. – Hiren Patel Nov 25 '22 at 05:07
  • @Jimi I uploaded the project and video record, you could download. – qakmak Nov 25 '22 at 08:25
  • [Test result](https://imgur.com/VFCXbyO), but there's nothing to actually *test* there. I cannot reproduce the behavior, see the animation. I suspect it's something related to either your Mouse or the System configuration, but I cannot say what that is because I've never seen it before. It's not the Project or the Framework – Jimi Nov 25 '22 at 09:58
  • @Jimi, I don't know why this is happening only my side. but still really thank you for analize it for me. – qakmak Nov 25 '22 at 15:26

1 Answers1

0

I've aslo trid same thing that you have tried,but there no obesrvation as you described .

But after that I've called ScrollToCaret() method for text box on form Activated event. Then only same scenario generated.

Code I've tried

namespace Text_Extration
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Activated(object sender, EventArgs e)
        {
            txtExtracted.ScrollToCaret();
        }
    }
}

I hope this will help to you.

enter image description here

Hiren Patel
  • 1,071
  • 11
  • 34