I am very new to win form.
I want to develop a form which has a height of around 992*1403.
i tried to give the size of the win form as 992*1403, but its taking only 992*876.
i am setting an image of size 992*1403 as the background. i need to put a vertical scroll bar. i put that scroll bar but i dnt know how to write the code when the user scrolls that scroll bar.
Please give me some sample codes or links
For what you are describing, you just need to set the form's Autoscroll property to true. (It is under the "Layout" section). Right-click on the form and select "Properties"
This will add scroll bars if the form doesn't fit into the current window size. No code is required. The scroll bars will only appear when there is a control outside the current view.
Reading your description again, what you might be looking for is a large panel in your form. Add a Panel to your form and make set the location to 0,0 and the size to 992,1403. Then add your controls to the panel. Don't forget to set the form's Autoscroll as mentioned above.
Related
i have a Form and it have a very big dataGridView(please ignore the datagridview) and so many other things. my Form is maximized and i set AutoScroll True and there is a Button on top of the Form when i scroll down Button goes out of user's view. i wanted to be like fix position in HTML so i tried to use VerticalScroll.Value somehow for Button.Location.Y in Form Scroll event but it didn't go well because i even don't know how this value of VerticalScroll will be calculated and have it nothing to do with Form.Height or not and the max value(when scroll is at bottom of form) is changing when you resize the Form.
have anybody any suggestion or solution for this?
A Windows Form application displays a main form. This main form contains few different Panel controls. Depending on some condition in that form one of these Panel controls is to be made active while the others are made invisible.
First panel contains a DataGridview, Second panel contains controls to display the details of the DataGridView. On Add button click (or) On selecting a record in DataGridView the second panel should be visible. I am using Visible property to show and hide panel, but the gap is showing there as shown in screenshot.
Please suggest best way to handle this.
You just need the panels to share the same location. You probably don't want to do that at design-time, as it makes future maintenance of the form difficult.
In the Form.Load event, set the location of the bottom panel to match the location of the top panel.
PanelDetails.Location = PanelDataGrid.Location;
Now when you hide one and show the other, they'll appear in the same place.
The smartest way is to keep the panels separate at the designer. This way any editings made on them can be done more easily, and all actual objects can be seen immediately.
In the designer, set the other panels' Visible properties to False, excep the first one on the top.
Form.Load:
Set all the other panels' locations to match the location of the first panel (on the top)
Set the form's height to match a desired height, which fits to your heightest panel
Use the buttons to toggle panels visibility (and possibly the form height too)
What are the rules which I have to respect to make the Form scrollable...
I simple set the Property AutoScroll to true.
I also tried while Auto Scroll is true, to set AutoSize to true/false, but none of these worked... also tried to put Panel and added all components in there... still nothing...
Maybe using V or HScrollBar can help, but i really don't know how to link it with the Form...
form.AutoScroll = true;
formMainLayout.AutoScroll = true;
rootPanel.AutoScroll = true;
The content controls the scrolling. The scrollbars do not appear unless they are needed. Usually, there is a property available that you can set to force them to be visible always, and simply disabled until needed.
The AutoScroll property must be true, as you have already found. But then the content of the scrollable control must force the parent control to display the scrollbars. This part is up to how the controls are embedded within the parent.
Try these two experiments:
Place a Panel on your form and dock it to Fill. Set the AutoScroll property of the Panel to true. Into that panel, place a TextBox and set it to dock as Fill as well. Also set MultiLine to true. Run the application, and you will notice that the size of both is simply using the available space...no scrolling can occur because neither the Panel, nor its TextBox become larger than the space they occupy.
Perform the same steps as in #1, but this time, do not dock the TextBox. Instead, set it to a large size, something that you know will be larger than the amount of Panel that is visible. Running the application should now produce a scrolling Panel.
Hopefully this little test helps to demonstrate what is controlling the scroll on a form.
I was also having the same problem, I managed to fix it...
All the child controls inside the panel had a Left & Right anchor, and when I only set the anchor to Top, the scrollbars where working fine.
I am not sure as to why the Left and Right anchor (of the child controls) forces the panel not to show scrollbars.
But anyways... hope this will help anyone as of this date.
The AutoScroll property should work fine, but most likely you are not using it right: the bar appears only when required. Example: minimum Y of the Form is 0 and minimum Y of one of the controls in it (a TextBox) is -20.
If you want to include a scroll bar no matter what (controls inside the boundaries of the form or not), you can also do it. Sample code (from MSDN) for a vertical scroll bar:
// Create and initialize a VScrollBar.
VScrollBar vScrollBar1 = new VScrollBar();
// Dock the scroll bar to the right side of the form.
vScrollBar1.Dock = DockStyle.Right;
// Add the scroll bar to the form.
Controls.Add(vScrollBar1);
You need to set the properties for the parent panel.
Dock = Fill
Anchor = Top, Left
AutoScroll = true
That's it. Good luck! ^^
note its for vertical scroll
Turn On auto scroll property of your Form. insert one panel and
set panel width to the form width and panel height
equal to length of your total content or may be 1300 or 1500 as
required.
Place panel location as you want set panel anchor
property to top. place your all
content inside panel.
hope it will solve your problem
I had the same problem.
You have to add only this:
this.AdjustFormScrollbars(true);
I'm not sure what it's called in the land of WinForms, but in web development terms, I'm looking for a frame type element that can be added to a winform.
I want a panel that is anchored top,bottom,left,right but if the form the panel is resized to a smaller size than the elements in the panel, scroll bars will appear around the panel allowing the user to see the contents of the panel without expanding the form.
I hope that makes sense, and that such a thing exists.
Thanks!
Yes, a Panel control. Set AutoScrollMinSize to the minimum size you want before scrollbars appear. Set AutoScroll to True. Set MinimumSize if necessary, it shouldn't be.
The controls inside the panel need to auto layout by themselves so they'll move as necessary when the panel gets smaller. Use their Dock or Anchor properties. If the layout gets complicated then switch to a TableLayoutPanel or FlowLayoutPanel control.
What about a panel? System.Windows.Forms.Panel
You are looking for a "Panel" control. Just set the "Dock" property to get docking going..
You add a Panel to your form and set Panel.Dock = Fill. Your Panel will auto-resize when you resize the form.
Set Panel.AutoScroll = True
Then, you add controls to your Panel. Set the controls' Dock property accordingly. Now, when you resize the form, scrollbars will appear if controls are covered up.
There are a couple of different panels in the standard windows controls that do what you want... just look in the toolbox when editing a windows form, under 'container'
What do you want it to contain? A web page, or just windows form controls?
I have a form that has several controls:
ProgressBar at the top of the form (docked)
A TabControl at the top of the form (also docked but underneath the progress bar)
Buttons, TextBoxes and labels inside TabPages of the TabControl
FlowLayoutPanel at the bottom of the screen (docked) with a few buttons in it
Label at the bottom of the form to act as separator (also docked, but above the FlowLayoutPanel)
I am trying to auto size the form to fit its content. What needs to happen is:
Tab pages wrap around its content
Tab control wraps around the largest tab page
The form wraps around the tab control, progress bar and buttons.
Here's an example of how the form looks without AutoSizeMode set to GrowAndShrink (just Grow):
alt text http://www.fusyion.net/images/Form%20no%20shrink.png
And this is how it looks with AutoSizeMode set to GrowAndShrink:
alt text http://www.fusyion.net/images/Form%20with%20shrink.png
Please advise.
To get this to work, you have to set the MinimumSize of all your controls to a value. This will be respected from the Shrink-Mode, thus leading to a well sized form.
Make sure the direct children of your form have anchors set exactly to Left and Top. You could set the Form.MinimumSize Property and Form.MaximumSize Property as a precaution.