panel autoscroll turns off when switching between windows - vb.net

I created an interface it has several forms you can switch between using a panel as the parent form. My problem is that when i switch between my forms on the second time i open a form if that form has autoscroll on a panel it will not allow you to scroll and the window is stuck on the view you previously had.
In this image i open the form internet. after doing so i will click on instruction( any form switch triggers this)
now i open the same form again and the scroll bar is gone and it locks in on the last position the form was in.
the very curious thing in this is that this only happens on the internet form word also has a scroll bar however even though the properties and settings for both are identical only one does not work.
What could be causing this and how do i go about troubleshooting errors like this.
The forms are removed from the panel and re-added, they are not closed.

Assumption 0:
The forms are removed from the panel and re-added, they are not
closed.
Store the state of panel autoscroll and set it after you have re-added it. Note that if you add controls to the panel first and panel is not docked, then scroll will not appear because panel dimensions can be huge. You should set following property as well:
vScrollBar1.Vericalscroll.Value = 0
Assumption 1:
I assume what is actually going on is that you do not add controls to that panel, but to the form behind it or something similar. In that case - program is correct, you just asked it to do a wrong thing.
Assumption 2:
Assuming is panel is anchored top, left, bottom, right. There is currently a limitation in Windows Forms that prevents all classes derived from ScrollableControl from acting properly when both RightToLeft is enabled and AutoScroll is set to True.
Manual : link
Assumption 3:
You add the controls back, by recreating them, but forget to add handlers or create them in order where scrollbar is out of view. Instead of absolute positions you could use dockstyle:
Dim vScrollBar1 As VScrollBar = New VScrollBar
vScrollBar1.Dock = DockStyle.Right
Controls.Add(vScrollBar1)

Related

Can we keep the Form scrollbar but prevent the form from auto-scrolling to the focused control?

I want to prevent my form from automatically scrolling when a control at the bottom is focused but still keep the scrollbars if they ever appear.
Since some users have a slightly lower screen's resolution than the form, the scrollbars do sometimes appear. This created a problem with some DataGridView. Since the AutoScroll option is enabled, when clicking the DataGridView, it does a multiselect since we click and it moves.
When I disable the AutoScroll property, the scrollbars go away. Therefore, the user can't see everything.
Is there a way to disable the AutoScroll, but still keep the scrollbar?
If I understand your situation correctly, you basically want the user to have the ability to scroll the form manually but prevent the form from scrolling automatically to the control that gets focused.
Put this code in your form:
Protected Overrides Function ScrollToControl(activeControl As Control) As Point
'Return MyBase.ScrollToControl(activeControl) ' <-- Keep this line commented.
End Function
Result:

How to make VB.NET application full screen without moving my controls

I want to make my application so that when it has been maximized the control will automatically position itself it the right place.
Assuming that this is a WinForm project, you need to set the Anchor property of the button to Bottom, Right.
The most useful control is the TableLayoutPanel. You should put all the controls on the panel -> set dock: Full and every time the form resized, the controls stay in their container.

How do I scroll with the scrollbar?

I am currently working on a project in VB.NET and I have a fixed-border form with the AutoScroll property set to True. Under the Load event, I have some loops that add a bunch of controls to the form, so I have AutoScroll create the scrollbar for me automatically.
Now when I open up this form, all the controls load up with no problem, it focuses on my first text box, and the scroll bar shows up. However, the mouse wheel does not do anything whatsoever.
So my question is, how do I, no matter where my focus or mouse is, scroll with the AutoScroll property enabled, in VB.NET?
as far as i know, scrolling is only enabled when focusing the appropriate element. but should be able to trigger scrolling by catching onmouseover() or similar...
this is somthing similar (just for a datagrid) scrolling datagridview without get focus

VB.NET overlaying panels is not working

I am overlaying a bunch of panels on top of one another. I want to be able to click a button to display which ever panel is in the stack referred to by unique names (panel1, panel2...).
However, the bottom panel some how is always the parent of whoever is on top of it. Therefore, If I were to set the visibility of the bottom panel to false, then nothing on top of the bottom panel can be made visible.
How do I make these overlayed panels independent to each other instead of having a parent-child relationship?
I faced the same situation a time ago. The more pragmatic way that I found was to use a tab control and hide/show tabs accordingly. It is possible to get rid of the label of the tab, so users dont even know about its existence. The rule is to have one and only one tab visible in any given time.

vb.net controls in separate files

Short version: VB.Net Windows forms feature controls that are often dragged from the toolbox onto the form. The code for the control goes right into the form. Usually this is great, but is it possible to write the code for a UI control (like a panel) into a separate file which can then be imported or otherwise included into the main Form Class?
Context (a.k.a. long version): I have a form with an unchanging column of navigation buttons on the left hand side. The rest of the form is taken up by different panels, which in turn have different controls of their own. Clicking the different buttons on the left should cause these different panels to appear (clicking button "A" brings up panel "A"; button "B" brings up panel "B", etc.), but the left-hand menu should stay unchanged.
I'm having a hard time implementing this design in an elegant way in VB.Net. If I make each panel a separate Form, I have to duplicate the code that builds the unchanging left-hand menu in every file, which is terrible. I tried using inherited forms so the separate panels would inherit the left-hand menu from a master form, but that means each click on the menu sprouts the new form in a new window, and although the left-hand menu is inherited, the menu that I clicked and the identical-looking menu in the new window are not the same objects in memory and have no knowledge of each other.
I just want one window with central content that changes based on what you click on the left-hand side. A solution to this would be for the panels to be just that - panels - and not separate forms as I'm currently doing it. But this gets messy organizationally because the code for all of the panels has to be in the one massive master file. Hence the short form of my question (see above): How can I code a panel in a separate file and then bring it into the fold of the main form?
It sounds to me like you want to use usercontrols. Create a usercontrol for each of the four things you want and then add those to a panel, making each one visible or invisible according to which button was pressed.