What is the standard size for winForm application? - c#

I want to do full screen application. But when window state maximize it is not my expected result.
Btw I'm new to visual studio
When minimized
When maximized

There's not a standard size. You should check your form to make sure it will work at the different likely screen sizes and aspect ratios.
In your example, you can use the Anchor property of controls to cause them to expand and contract with the form. For example, the "Welcome to WasteAid" section of your form can be put into a container (such as a panel), and the anchors of that container can be set to Top, Bottom, Right. The left side could be set to Top, Bottom, Left. You can anchor controls with a container, or anchor the controls individually without a container. You can drag a corner of the form around in design mode to see how it will work at different sizes and aspect ratios.

Related

Best Way to make a Windows Forms scalable?

What would be the best way to make a WinForms application fully scalable, for example when the Form resizes?
In WPF i would use something like a Viewbox and/or a UniformGrid, but something like this doesn't exists in WinForms.
Is there an easier (and maybe faster) way to rescale controls on a from after resizing it, instead of resizing them all by calculating their new Size/Location etc.?
Thanks in advance
In Windows Forms, you use the Anchor and Dock properties for each control.
Here's an article about using them: http://www.techrepublic.com/article/manage-winform-controls-using-the-anchor-and-dock-properties/
You should also look at FlowLayoutPanel and TableLayoutPanel
you can use anchor and dock, depending on your need:
Anchor - the edges of the container to which a control is bound and determines how a control is resized with its parent.
Dock - which control borders are docked to its parent control and determines how a control is resized with its parent.
for further read: Dock and Anchor
Have a look at the Anchor property found on pretty much any control. This allows you to lock a control to any (or all) of the four borders of a window.
Once one distance is anchored (e.g. Top or Right), the control will always try to keep that distance, no matter how you resize your window.
For example, you'd set Anchor to Bottom and Right for a button that is supposed to always stay in the bottom right corner of a window. A text box, that should always fill the window from left to right would use Left and Right.
Similar things can be achieved utilizing Dock, but a docked control will always try to fill as much space as possible (there are different strategies available, like "fill everything from here and upwards) based on its container. Depending on your use case, this can however be a lot harder to control (and I usually only use it if I want a single control to fill a full window, e.g. a TextBox).
If you need more complex alignment, like widths scaled on some kind of ratio (e.g. 30%), then there are several different containers available.

Windows Forms: Resolution Issue

I am C++ programmer, and I am working on a migration project where I need to convert C++ code to C# and I have little knowledge on C#. Also, Clients want the application in .net 2.0
Issue:
When the screen resolution changes to low resolution, the form is adding a scroll bar to show all the controls in the screen. But, Client wants without any scroll bar such that all the controls should be visible.
Font applied to the controls should fit to the control dimension even if we change the resolution to high or low.
Any suggestions?
Use containers to house your controls. TableLayoutPanel would probably be a good choice. Set the TableLayoutPanels DockStyle to Fill. TableLayoutPanels only allow you to put one Control in each section, but Panels allow multiples so put a Panel in each section and set each Panels DockStyle to Fill. Arrange your controls in the panels and set each controls Anchor or DockStyle properties to keep them in location. Now, set your resolution to the lowest possible setting and build your form. If you follow the above steps, when you raise the resolution everything will be in the same relative location with the same relative size.
Why it works: Setting the tablelayoutpanels DockStyle to Fill makes it autosize with the parent form. Setting each panels DockStyle makes it autosize with the TableLayoutPanels sections. Anchoring/Docking controls inside the panels keeps the controls sizing and spacing relative to the panel.

Resizing componenets on a c# form

typically in java if you have a layout manager of somesort, when you resize the page then the components in that panel will resize accordingly. I think my app is missing some sort of layout manager to control resizing as at the moment everything is just static
Is there a way to make it resize on the changing of the form size? say the user makes the page bigger, then the componenets adjust and so on.
Thanks
.NET has layout managers as well.
Personally, I prefer the TableLayoutPanel for my WinForms apps.
Once you layout the Table (using a combination of static/dynamic sized rows/columns) you add your child controls to the table cells. Once you add your controls, you can dock or anchor the controls to the cell so that they are automatically adjusted when the window is re-sized.
Two main options:
Anchoring. Set your control to "anchor" to the sides of your form. This means that if the form resizes, the control will stay a constant distance from that side. So, if you anchor Top, Left and Right, then your control will stay in the same position, but resize horizontally with the width of the form. Play with it. It'll be obvious.
Docking. Set your control to "dock" to a side of the form, or the center. This is usually done with containers, and it will make the widget take up that entire portion of the form no matter how large it gets.
In Windows Forms you make use of the Control.Anchor property, which will cause the control to adjust accordingly when the window resizes.
To do this with windows forms you use the Anchor and Dock properties of the control
See this for a guide on how to use them

Maintaining the size of the control which is located on the form when form is resized

I have one form which size is (325,325) and on which one browser is there and the size of the browser is (321,298) means browser is in the middle of the form.And I want to maintain the size of the browser when form is resized like there should be the same difference of the size between form and browser as it was before resized.
Like the previous answers stated, you should Anchor the control.
You should set the Anchor property to Top, Left, Right, Bottom to let the browser grow/shrink when the form is resized, but maintaining the margins.
You should Anchor the control on the form.
Have a look at
Manage WinForm controls using the
Anchor and Dock properties
Control.Anchor Property
Manage WinForm controls using the
Anchor and Dock properties
Anchoring a control to its parent
ensures that the anchored edges remain
in the same position relative to the
edges of the parent container when the
parent container is resized.
Setting the WebBrowser's Dock property to Fill is the correct answer here. This completely eliminates the possibility that you'll have layout problems when you run your program on a machine that has a different system font size or a different video adapter DPI setting.
If you need room for some kind of gadget or toolbar, be sure to dock it as well (usually Top). Use Format + Order if the browser ends up underneath the gadget.
Use the control's Anchor property to anchor it to all 4 edges of the form. The control will automatically change it's size when the parent form resizes then.
The MSDN article explains the basics. Google finds quite a few interesting links as well.

How do I make a child control re-anchor to its parent Form when it has been cut off on a small resolution screen?

I have a Windows Form with a default size of 1100x400, and I have a DataGridView control on it anchored to Top, Left, Bottom, Right.
Resizing the form on a screen with resolution higher than 1100x400 works fine, and the anchoring works well, resizing the DataGridView control as expected.
When I launch the form on a screen with resolution 800x600, the form is cut off, and made to fit the 800x600. The DataGridView is cut off, and cannot be seen entirely - it bleeds off the form to the right, so it's not respecting the right anchor. Resizing the form in this situation doesn't respect the anchoring settings for some reason: the DataGridView control does not resize when the form is resized.
Is there a way programmatically (on a resize event or something) to force the child DataGridView control to anchor to the sides of the form?
I've already tried calling a PerformLayout and Refresh in the Form's resize event but it's rather redundant, isn't it?
I would recommend you to play with MinimumSize/MaximumSize of the form and controls
We usually set MinimumSize for the form and controls to the value, when we can see at least small part of each control. There is no use to allow resizing a form to the size, when you cannot do any usefull work with the controls on it
As for MaximumSize for the form - I'll recommend you to try setting this value on Form_Load to be less or equal current screen resolution or current working area (which is the screen area without taskbars, docked windows, etc.)
see
Screen.PrimaryScreen.Bounds
Screen.PrimaryScreen.WorkingArea

Categories