C# WinForms Button that Triggers Form Extension - c#

How would I go about creating a program that contains a button. This button does the following function:
When clicked, it extends the Form size and adds what I want added onto the form.
The extended form can also resize itself back to normal.
Example here would be a gif of how Steam does so.
https://gyazo.com/7330b65d05573208db0eb71a7587d21f
See how it does that addition here.
Extension in Picture --

First design the form in its expanded view. Put everything that belongs to the red box (in your example) into a panel. Set all control's 'Anchor' properties below this box to "Bottom". Then you simply have to set the .Visible property of the panel to true or false, and at the same time, adjust the form's size. When you hide the panel and reduce the form's size, the controls below then panel will move up and close the gap.

Related

Overlay two panels in a windows form application

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)

How to resize the window without hiding controls

How can I resize a windows form without hiding controls that are positioned outside the form's new size?
Check out the .Anchor property of the buttons you want to avoid hiding. The anchor property can be set such that the placment of the buttons is alwas relative to one or more edges of the form. This way, when the form is resized, the buttons location is "anchored" to (for example) the Bottom and right edges of the form.
This will not prevent the user from making the form smaller than the minimum space required by the buttons, but I believe you can also set a minimum size property for the form.
set the anchor property of your buttons or items in form.
If still you have issues, put the buttons or controls to pannel or groupbox and dock the buttons to parent container. Then apply anchor property for controller.
I Have found the similar issue and what i tried is to put all the buttons in a TableLayoutPanel and set the Anchor property of the buttons that way i am able to resize the button corresponding to the size of the form.
If any body has a better idea kindly suggest........

How to auto size a form around a tab control + more 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.

how to set vertical scroll bar in win form

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.

Best Layout of a WinForms UserControl with both Static and Dynamic Content?

I have a user control that has:
a) a buttons panel at the top (it always has to be visible)
b) a panel with controls that are dynamically added and re-sized at run-time. The controls can be many, so the panel has to be scrollable.
This user control will be hosted in a form, with the following requirements:
a) The initial size of the form will try to fit in maximum part of the dynamic content.
b) On changing the form size, the control has to be re-sized accordingly.
I had played with various anchoring, docking, and auto-sizing and I don't quite get it working in the way I want to. Sometimes, it is the scrolling that messes up, sometimes it is something else.
What combination of anchoring, docking, and auto-sizing of the panels, usercontrol, form should work best to achieve the desired outcome?
I succeeded to meet the requirements. Here is my solution:
The dynamic panel is anchored to the top and the bottom of the control. It does not AutoSize, it manually changes its MaximumSize and PreferredSize after change in the contents.
The form hosts the form using:
cntrl.AutoSize = true;
cntrl.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
cntrl.Dock = System.Windows.Forms.DockStyle.Fill;
The form subscribes to a custom control's event that notifies for the preferredHeight and it changes its own Height accordingly.
I'd go with a table layout panel. You can specify two rows by one column with the exact size for the buttons at the top and fill the rest with the bottom. Then put put either a normal panel or a flowlayoutpanel for the dynamic content in that area.
Without knowing the specifics of your problem I find multiple fill docked split containers with one fixed panel and/or a fixed slider usually creates a really handy resizing experience. You can also collapse panels very effectively too.

Categories

Resources