I am doing a WinForms program which should have a fully responsive design in a full screen.
I get an approach which works more or less well. It consists into calculate a ratio between display screen and original form size.
Then I apply this ratio to the width, left, height, top properties of each control inside the form.
My doubt is about to use a native way for doing this, since, using anchors, the controls keep their same distances with parent control borders, but I doesn't do proportionally, for instance:
Form with 100x100
Button 20x20 located in (10,10)
If I resized the form to 200x200 (multiply by 2), the best approach I can do in design view is keeping the four anchors to the button, so button size will be 120x120 at the same position (10,10), while what I need is a button with size 40x40, at position (20,20), since form size was multiply by 2.
Is it possible with winforms native operations in design view? (Avoiding to make calculations)
Yes it is possible.
Using the Property Dock = Fill you can ask for a component to take all the room in its container.
Now using a TableLayoutPanel, you can define cells to put your components in. And giving cell a percentage size, you can make sure the sizes will change when the form is resized...
Here are more information on these things :
Dock Property
TableLayoutPanel Class
TableLayoutPanel Tutorial
Related
I'm having difficulty with resizing controls in two panels...
I have a form with two panels stacked on top of each other. The top panel takes up 38% of the form and the bottom panel takes up 58% of the form and a 4% gap between.I have a tab control in one and group box in the other.
I've been trying to perform fills/docks within the panels that will cause all controls to grow and shrink with the panel's size. In other words I'm trying to keep the same space and size percents for all controls based on the form size. Visual studios keeps crashing when trying different fills/docks and I don't want to calculate size percents and x/y coordinates for each control. Is there a way to set up the fill within the panel or container so that it looks almost the same at most sizes?
In my experience, docking causes more problems than it helps. What I do instead, is undock the controls and then anchor them on all sides. Then I size them within the panel how I want them. Then, if the panel is ever resized, the controls anchored within them will resize accordingly and it will stay within the boundaries like I want it to. Try that.
I am using Visual Basic in Visual Studio 10 .I have a windows form and I have to display a world map(a jpeg displayed in picturebox ) with radio buttons over each of the country . The problem is while resizing the window the radio buttons get dislocated. One way to fix this is calculating the ratio of
Scree.width/(initial x-coordinate of radio box)
and similarly
Screen.height/(initial y-coordinate of radio box)
and using this to generate the new x and y coordinates after resizing but as the number of countries are too large this is very tedious and for smaller countries the difference in the initial coordinates is not much and due to precision loss in higher resolution the radio box are overlapping. Is there a workaround for this. Also the method described isn't working after adding zoom as the portion of image displayed on screen changes and as a followup I would like to ask how can I add sliding functionality to image ( like after clicking the mousedown and moving the pointer should move the image keeping the radio boxes over the respective countries, Is using scroll bars better for this purpose? )
Replace your PictureBox with a Panel.
With the PANEL and your IMAGE set:
PANEL.BackgroundImage = IMAGE
PANEL.BackgroundImageLayout = ImageLayout.None
PANEL.AutoScroll = True
PANEL.AutoScrollMinSize = IMAGE.Size
At last, add all RadioButtons to the PANEL.
I was searching google for a way to size the form and the controls with it and came across something that mentioned Control.scale. How do I use the control.scale method to size everything down to the way I want it.
Also, is there a way I can zoom the form out in the designer. I want to create a 1280X800 form, but my screen is 1024X768. I want to be able to zoom out to see the entire form wile still having it's size be 1280X800.
You can use tablelayout panel in order to fit your form in all resolutions.similary a property called anchor, which is also need to be assigned for the controls inside tablelayout panel according to your requirement [top,bottom,left,right] to achieve the same.
By the way you have to use percentage for setting the column's width and row's height in that.
Simply, this way of designing is called as fluid designing.
Table layout panel
I have designed a form in VB.NET. At design time I have placed two buttons on it.
When I run it, the form size looks smaller and the buttons I have placed at the bottom are not visible. Also the alignment of the text and picture box is also different from what I set at design time.
Computer at which I am running the form is using a different resolution.
change the properties (F4) of the buttons: in ANCHOR put Bottom, Right
your buttons will be tied to the bottom and the right of the screen, instead of to the top, left, which is the default.
Grab the screen size at runtime with
Dim screen as System.Windows.Forms.Screen = System.Windows.Forms.Screen.PrimaryScreen
and using a scale factor depending on the current size (in design), scale the window to match. Check the coordinates of the buttons by hand to make sure they are not outside of the visible portion of the window.
You may not have to leave this feature in if you can debug it to the point that you know the exact resolution that you need.
Is there an easy way to grow / zoom a VB.NET application and all controls within it to fill a larger screen resolution (or must I adjust each form element individually)?
NOTE: Adjusting the resolution back is not a permanent (or preferred) option in this case.
Please don't design your forms so they always fill the screen. Your customer has bought that nice expensive monitor to see more windows, not more of your form.
A well designed form is otherwise always resizable. Use the Anchor and Dock properties, TableLayoutPanel and FlowLayoutPanel to ensure that your controls move and size themselves properly. If your customer wants it big, she'll just click the Maximize button.