Resize Panel Size On Windows Form Vb.net - vb.net

I have 2 panels on windows form and both occupied the equal portion on form (i.e. 50%- 50%). Once i run the application, I want to resize the panel size by dragging form with mouse (i.e. 25%-75%). The portion given is not fixed it can be in any size. I just want to resize the panel by dragging/streching mouse.
Please help to resolve the issue.
Thanks,
Soorajbhan kuntal

I think you want to use a SplitContainer control on your form. Put the Panel controls into the two different containers of the SplitContainer, and set their Dock property to Fill. You can set the SplitContainer to Dock.Fill too or set the Anchor properties such that the SplitContainer stretches along with the form.

Related

How to have a TextBox control fill a Split Container panel?

I am running Visual Studio 2010 Professional (10.0.40219.1 SP1Rel) with no updates showing in Windows Update. When I drop a TextBox control into a Split Container panel, make it Multiline, then Dock in Parent = Fill, it shrinks down to 1 pixel wide and disappears. Of course, at runtime it is invisible.
Is this a bug? Is there a fix? I actually don't need text input - what I want is to display text in a resizable panel, with scroll bars. I could perhaps put code on the events (SizeChanged, SplitterMoved, SplitterMoving...) but that's an ugly solution. Is that the only one?
Apparently I didn't realize I had put a Flow Layout container inside the Split Container panel. This was preventing it from filling the panel.

Elements floating around the form container

I've set my main form as a container but whenever i open a child form, the buttons inside the container stays on top. How can i get around with this? Thank you so much! I've attached a snip shot of my problem. Thank you again.
http://s26.postimg.org/7l3mdyli1/image.png
You can use Panel from toolbox and populate the Panel with your controls/buttons.
The good thing about panel is, the x,y of your button controls within panel will be relative to the panel (e.g the 0,0 of your button left,top will be always be on the left top of your panel) this has significant advantage for positioning, rather than calculating the position of a button using your form coordinate.
Hope this help.

WinForms SplitContainer and its spacing and resizing

I seem to have a lot of trouble getting a SplitContainer adjusted the way I like it. I have the following form called frmMain:
In the form Load code I have to following code:
With MainContainer
.IsSplitterFixed = True
.Dock = DockStyle.Fill
.SplitterDistance = 200
.FixedPanel = FixedPanel.Panel1
.Panel1.BackgroundImage = Resources.My.Resources.ResourceFile._001
.Panel2.BackColor = Color.White
.Panel2.AutoScroll = True
End With
When I run the code I get the following:
I want to remove the gray splitter since there is no use to it. Is this a common beauty
bug and is it possible to remove it?
My second problem with the SplitContainer is if I resize my window, the backgroundImage in Panel1 and the white color in Panel2 don't adjust with the window. I searched high and low to the Resize code but I can't find it. The Panel2 has User Controls, eg. Dashboard and are loaded this way: MainContainer.Panel2.Controls.Add(Dashboard).
Is it also possible that Panel2 automatically adjusts to the weidht of the window so thay you only have a hortizontal scrollbar?
Thank you for reading my question and hopefully you can help me solve my problems with the SplitContainer. Have a nice day.
I want to remove the gray splitter since there is no use to it. Is this a common beauty bug and is it possible to remove it?
If you don't want the user to see or move the splitter, why use a split container? As an alternative, consider using a TableLayoutPanel configured with 1 row and 2 columns. The first column would be an absolute 200 px wide while the second column would be set to 100% wide. In each of the two cells, you could place a panel which is docked and set to have a margin of 0,0,0,0.
My second problem with the SplitContainer is if I resize my window, the backgroundImage in Panel1 and the white color in Panel2 don't adjust with the window. ... Is it also possible that Panel2 automatically adjusts to the weidht of the window so thay you only have a hortizontal scrollbar?
While I did not mock up your current solution, I was not able to replicate these problems with a quick mock up of the solution I proposed above. With regards to auto-scrolling, the only reason that scroll bars should appear would be if a control is off the edge of the screen or the available screen space is less than the minimum size of the panel.
You have 2 options:
Use TableLayoutPanel (as #erdomke suggests)
Use 2 Panel controls
For 2 panel controls, dock panel1 to Left, and dock panel2 to Fill. To fill panel2 with a UserControl that resizes, set it's Dock property also to Fill.

winforms - usercontrol with dockstyle fill not correct size during form load

My main form has two panels, left docked and right docked. The right side panel has two child panels with top dock and bottom dock settings. The usercontrol is added to the right side top panel.
My usercontrol has a panel and a label. The panel is anchored on all 4 sides, the label is anchored on all except the bottom. At runtime I create this usercontrol and set it to dockstyle=fill and then I add it to my top right panel.
With everything set to "fill" I expect that when I add my usercontrol to the panel it will take on the appropriate width and height and pass that info to the child controls (labels) inside of my usercontrol.
My problem is that this stretching of the size does not happen when I create my objects during the Load event on my usercontrol. Even though initializecomponent has ran for the usercontrol the panel inside of it (4 corners anchored) has not taken the x/y values of the available space. As a result my usercontrol shows up about 50% of the width I want.
Lets say that instead of creating objects during usercontrol load that I instead start a timer and have the timer call my create routine when it raises the tick event. When I do things like this my objects are created with the full width/height that I expect. The only issue here is that this causes a delay in my interface.
Can someone help explain this behavior? My mainform is calling a "load gui" routine which is instantiating usercontrols, setting panel sizes, and then adding usercontrols to those panels. This particular user control is the last to load into the panels from that load gui routine so it does not make sense that the parent panel width/height would not be known yet. This is one of my first apps where I am purposely trying to use dockstyle=fill to keep things consistent across different main form sizes without writing all the extra size_changed code handlers. I'm sure this one is easy to work around once I know where the problem lies.
Thanks for any help provided!
this turned out to be a padding issue on the parent usercontrol. I also had to allow a bit of wiggle room to make sure that the controls didn't overflow the panel so I did a parent.width - 15 and that along with the padding made everything work much better.

How can I show scrollbars on a PictureBox control?

Sometimes, I have a picturebox lets say 100x100. But the image it will display is actually 100x400.
I don't want to increase the size of the picturebox itself. Instead, I would like to create a vertical scrollbar (or horizontal if needed).
I could not find a scrollbar in the toolbox, so I guess I have to code it. But, how?
And I still wonder if I didn't make a mistake and didn't see the scrollbar in the toolbox. My apologies then :(
I suppose you could add separate scrollbar controls and sync their Scroll events up with the offset at which the picture in the PictureBox is drawn, but that sounds like actual work. There's a better way.
Add a Panel control to your form, and set its AutoScroll property to "True". This will cause the control to automatically show scrollbars when it contains content that lies outside of its currently visible bounds. The .NET Framework will take care of everything for you under the covers, without you having to write a single line of code.
Drag and drop your PictureBox control inside of the Panel control that you just added. The Panel control will then detect that one of its child controls is larger than its visible area and show scrollbars, thanks to the AutoScroll property. When the user moves the scrollbars, the portion of the image in your PictureBox that is visible will be automatically adjusted. Magic.
(The reason you have to use a Panel control as a container is because PictureBox does not inherit directly from the ScrollableControl base class, which is what provides the AutoScroll property.)
I tried this and it worked well. But I noted that if the picturebox is docked in the panel, the picturebox is automatically set to the size of the parent panel, and can't be set larger (at least not in any way I could find). This defeats the purpose of the technique. So -- put the picturebox on the panel, but don't dock it, and it will work perfectly.
There are no automatic scroll bars on a picture box, but you can add the VScrollBar (and HScrollBar) control to the form and handle the image scrolling manually by redrawing it at a different offset each time the Scroll event is fired.