Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Go Back  Xtreme Visual Basic Talk > > > Scrollable panel automatically jumps to the top


Reply
 
Thread Tools Display Modes
  #1  
Old 10-30-2012, 07:19 AM
cmM's Avatar
cmM cmM is offline
Regular
 
Join Date: Jun 2004
Location: Chicago, IL
Posts: 73
Default Scrollable panel automatically jumps to the top


Hello,

I've been trying to find a solution for this, with no success so far. I have a scrollable panel on a form, with a few text boxes at the top, and a bunch of menuStrips underneath (see attached image).
My problem is, whenever a menuStrip is clicked, it does what it's supposed to do, but then the form focuses on one of the textboxes at the top. How can I make the panel maintain its current position?

Thank you in advance for your help.
cmM
__________________
cmM.
Engineer
(almost)VB Programmer

Last edited by cmM; 10-30-2012 at 02:05 PM.
Reply With Quote
  #2  
Old 10-30-2012, 07:42 AM
DrPunk's Avatar
DrPunkScrollable panel automatically jumps to the top DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

Not sure how best to ask this question, but how are you doing the scrollable panel? What's handling the scrolling?
__________________
There are no computers in heaven!
Reply With Quote
  #3  
Old 10-30-2012, 08:55 AM
cmM's Avatar
cmM cmM is offline
Regular
 
Join Date: Jun 2004
Location: Chicago, IL
Posts: 73
Default

DrPunk,

The scrolling is manual, there isn't any handling of it, I just created multiple objects within the panel which automatically made the panel scrollable.

The problem I'm having is with focus jumping back to the text boxes, If I can prevent that, I imagine the scroll position won't change.

Thanks,
cmM.
__________________
cmM.
Engineer
(almost)VB Programmer
Reply With Quote
  #4  
Old 10-30-2012, 09:16 AM
DrPunk's Avatar
DrPunkScrollable panel automatically jumps to the top DrPunk is offline
Senior Contributor

* Expert *
 
Join Date: Apr 2003
Location: Never where I want to be
Posts: 1,403
Default

The problem with trying to prevent focus of a control is the amount of code you'd have to start adding and then maintaining it becomes difficult too (add something new to the form, have to remember to put in all the right focus code).

I'd be more tempted to try and stop the Panel from doing it.

It's a Panel's ScrollToControl function that's doing it. What you can do is create a new Class, called say OwnPanel. This class then Inherits Panel and overrides the ScrollToControl function and then returns the control's DisplayRectangle.Location to stop it scrolling to the control with focus.

What you end up with is a class that looks like...
Code:
Public Class OwnPanel
    Inherits Panel

    Protected Overrides Function ScrollToControl(ByVal activeControl As System.Windows.Forms.Control) As System.Drawing.Point
        Return Me.DisplayRectangle.Location
    End Function
End Class
Then, instead of using Panels on your Form you use the OwnPanels.

It might seem a pain to delete all the Panels and create everything again using OwnPanels, but at the top of the Solution Explorer is a Show All Files button. Click that and your form in the explorer should have a + next to it. Click that and you should see the FormName.Designer.vb file. Open that and it has all the design for the form in it. In InitializeComponent you should see the declarations for your panels (i.e. Me.Panel1 = New System.Windows.Forms.Panel). You can change that to be OwnPanel instead (i.e. Me.Panel1 = New OwnPanel) and you won't have to do anything with the designer. Any Panels you change should now not automatically scroll to the control with focus.
__________________
There are no computers in heaven!
Reply With Quote
  #5  
Old 10-30-2012, 11:10 AM
cmM's Avatar
cmM cmM is offline
Regular
 
Join Date: Jun 2004
Location: Chicago, IL
Posts: 73
Default

DrPunk, thanks for taking the time to reply.

I tried the method you suggested. The issue I have is, my panels are not declared in the form.designer.vb file because they are part of a split container. Only thing that is declared is the split container, and the child panels have the properties asssigned, but no declarations.

How do I make these panes belong to the OwnPanel class?

**Edit: On second thought, the split container wasn't really necessary, so I replaced it with 2 individual panels, which I declared as part of the custom class, and that worked great. Thank you for all your help, DrPunk.
Thank you,
cmM
__________________
cmM.
Engineer
(almost)VB Programmer

Last edited by cmM; 10-30-2012 at 02:04 PM.
Reply With Quote
  #6  
Old 10-30-2012, 02:05 PM
passel's Avatar
passelScrollable panel automatically jumps to the top passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

If you set the TabStop property of the textboxes to false, does that prevent the focus from jumping to the textboxes?
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
  #7  
Old 10-30-2012, 02:07 PM
cmM's Avatar
cmM cmM is offline
Regular
 
Join Date: Jun 2004
Location: Chicago, IL
Posts: 73
Default

Quote:
Originally Posted by passel View Post
If you set the TabStop property of the textboxes to false, does that prevent the focus from jumping to the textboxes?
That was my first thought, but it didn't work.
I used DrPunk's solution, and that did the trick.

Thank you,
cmM
__________________
cmM.
Engineer
(almost)VB Programmer
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
 
Scrollable panel automatically jumps to the top
Scrollable panel automatically jumps to the top
 
-->