Dear All,
In VB.net,
(1) Place a textbox on the form with bigger size and multiline property TRUE
(2) Allow AutoScroll of the form TRUE
(3) Run the application
(4) Resize the form in such a way that there should be vertical scrollBar along the form
(5) Now click on the textbox

Imazingly, Some area of textbox has been selected.
Why?
How should it be controlled?

Please response soon.

Thanks.

Regards,
Amir Ali.

Not sure I follow what you are saying. I did try it. By default the text (as the name of the textbox, in my case TextBox1) is automatically selected on startup. Why? That is because the control has focus.

If that is not what you want, then set the focus to another control on startup. In this case there is nothing else except the form itself.

Not sure if this helps, but maybe you could explain a little more by what you see as the problem with this?

Dear Paladine,
Thanks for your response. I again try my best to make you clear about my problem.
Actually, when there would be vertical scrollbar along the form and position of scroll is most up. In this condition when we Click on RichTextBox, form will be scroll down. Thats why some area of RichTextbox is selected automatically. Position of form should not be changed by interacting with controls but it happens.

If you still not understand, then please just guide me how can I come to know that Windows scroll event is triggered and how I can prevent Form from being scrolled.

Many many Thanks.

Waiting for your reply,
Amir Ali.

Dear Paladine,
Thanks for your response. I again try my best to make you clear about my problem.
Actually, when there would be vertical scrollbar along the form and position of scroll is most up. In this condition when we Click on RichTextBox, form will be scroll down. Thats why some area of RichTextbox is selected automatically. Position of form should not be changed by interacting with controls but it happens.

If you still not understand, then please just guide me how can I come to know that Windows scroll event is triggered and how I can prevent Form from being scrolled.

Many many Thanks.

Waiting for your reply,
Amir Ali.

Ok Amir, from the description you have given, I am sorry to say I do not see the issue. I resize the form and the scroll bar appears. The Textbox is now partially covered, and I can use the scroll bar to see the non-visible portion. Clicking on the textbox does nothing but place the cursor in the textbox.

So I am not sure what the issue is? This is what should happen. :confused:

Position of form should not be changed by interacting with controls but it happens.

This does not happen for me? Interacting with the control does not change the window position. But saying that, if you have another control (even another textbox) on this form and press the tab key the focus does go to the next control and the viewable portion of the resized form does change to the new control. Problem? Nope, that is a fact of life. Not a problem. This is how windows works. Otherwise you could type or select a not in view an have no Idea where you cursor was, or if you have selected the control you want. :confused:

So a way around it? Not that I know of or see a reason to have one.

The only thing I could suggest is prevent resizing of the form.

Hope this helps, but if I am still not getting it...please clarify.


:D

Thats good you followed to some extent.

Now please give some more attention.

You resized the form and there is scrollbar. Now scroll should be must up. Means its vertical position value should be 0. And textbox should be large enough that we may see at least five lines at a time. Now click on textbox. Text will be selected even you are not likely to do that.

Thanks for your patience.

Amir I am paying attention, the text is not selected as you suggest. When the program/form is first started it is, but that is by default. As I mentioned before this is the result of the set focus method. Focus is set to the only control on the form by default.

I do exactly as you state, but my result is not what you say it should be.

Sorry dude, maybe someone else can make sense of this, but I see no issue what so ever.

OK, no problem. Please do not mind. I could not describe my problem in a right way. Anyhow

Please just guide me how I come to know that when form's vertical scroll's position is changed (By coding or by user interaction) and how can i prevent it from scrolling.

Thanks for your patience.

Amir Ali.

Did you ever find a solution to this problem? I am currently having the exact same problem you were trying to describe, and I can't figure out how to prevent the control from scrolling so that the textbox is aligned at the top of the window.

If you, or anyone else could help me out that would be greatly appreciated.

To try and describe the problem again as understandably as I can:
- I have a textBox (in fact it is a custom HtmlEditor that inherits from WebBrowser, but from this thread it seems the same thing can happen with a RichTextBox) that is larger than the control hosting it.
- I scroll so that an area in the middle of the textbox is visible.
- When I click in the textbox, the control automatically scrolls so that the top of the textbox is just visible.
- This scrolling seems to happen on mouseDown, because the result is the same as if i press the mouse button, scroll, and release the mouse button, so that lines of text are selected.

Eirik Ree

Hello. I too ran into this problem. It occurs when a control obtains focus. It calls ScrollControlIntoView on its parent which moves the autoscroll position so the entire control can be shown. Since my issue was occuring in a panel, I just created a new class NoAutoScrollPanel, and inherited from Panel. I then added the following code:

protected override Point ScrollToControl(System.Windows.Forms.Control activeControl)
        {
           return this.AutoScrollPosition;
        }

ScrollToControl gives the position ScrollControlIntoView shoulds scroll to. This overriden version returns the current position. Now when you click a control the window won't scroll and no text will get selected.

Hello. I too ran into this problem. It occurs when a control obtains focus. It calls ScrollControlIntoView on its parent which moves the autoscroll position so the entire control can be shown. Since my issue was occuring in a panel, I just created a new class NoAutoScrollPanel, and inherited from Panel. I then added the following code:

protected override Point ScrollToControl(System.Windows.Forms.Control activeControl)
        {
           return this.AutoScrollPosition;
        }

ScrollToControl gives the position ScrollControlIntoView shoulds scroll to. This overriden version returns the current position. Now when you click a control the window won't scroll and no text will get selected.

Exactly the same thing happens to me. But I do not find a way to correct in VB Net.. Any help would be appreciated

Hello guyz....Can please any junior/senior poster guide me through the code of decrementing a counter on each keypress event?
Im doing this for my SMS application (originally set to 160 characters remaining).
Thanks. (assaf.rawad@gmail.com)

Hey,
Any dumb :angry: can understand that this is not hardware issue.
Check these links below:
http://www.ca.com/securityadvisor/pest/pest.aspx?id=46367
http://www.ca.com/securityadvisor/pest/pest.aspx?id=46369
http://www.ca.com/securityadvisor/pest/pest.aspx?id=453076592
http://www.ca.com/securityadvisor/pest/pest.aspx?id=2420

I had the exact problem on my three machines, XP, 2003 & Vista ultimate and all I did was scan my machine with the trusty Etrust and it worked like a charm. :cool:
I no longer have the irritating problem with abnormal or automatic scroll.

This article has been dead for over six months. Start a new discussion instead.