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.
Related
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.
I am using vb.net, I have created a form and there are two listviews in that form which are getting filled by button event. Every thing is going smooth, but the problem is when my exeute my project and in the form, when I maximize the form window(by clicking maximize button provided in the top right corner) the size of listview remains same while form maximizes, this looks odd, what i need is to maximize the listview also with the increase in the form window size.
I searched in google a lot and i found one property 'dock' of listview which i can set left, full, right,bottom,top or none, but this doesn't serve my purpose.
Snapshot when I am using Anchor property
On Starting:
After Maximizing:
Please guide me in the right direction, what I need to do
when no propety is set then image on maximizing is:
Thank you
With Regards
Better than Dock property, you have to use "Anchor" property. All controls on the Form has Anchor Top,Left by default, but you can change it in the property window or directly by code. You can know more about anchor on this site: http://www.homeandlearn.co.uk/NET/nets13p1.html
Anchoring two Listviews on a form depends on the form design, but SplitContainer control will be really usefull if you want that both Listview changes the size on form resize.
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.
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.
I'm working on a UI for a WPF application. I have in my window Stack Panel with some Expanders inside. In each Expander are some controls, one being a List Box. What I want to do is have the List Box resize (shrink or grow) when the window is resized. At the moment, when I re-size, the expander are getting clipped off but the listbox (sometimes very long in height) remains unchanged. How do I go about making this happen.
A good example is in Outlook 2007, the "Mail Folder" on the left shrinks with window size but the other controls don't.
Thanks in advance.
The StackPanel won't push a height on its children - it allows each child to size as big as it likes. You might try using a Grid around the Expanders, and giving each Row a star height so that the contents resize.
Thanks Paul,
I've found something interesting myself.
I've extended the grid control with a simple method that fires when the expander is expanded, I would call this.
RowDefinitions[GetRow(expander)].Height = (expander != selectedExpander) ?
new GridLength(1, GridUnitType.Auto) :
new GridLength(1, GridUnitType.Star);
This worked very nicely.