Automatically resize form and move controls when new ones are added or a text in a label grows - winforms

Beginner in Visual Studio here.
I'm trying to create an C# Windows Form application that simply displays a form to show some information about the local system.
I have created this form with the help of the VS designer:
As you can see, it consists of a simple panel with a PictureBox at the top, a label below it (both centered), three table layouts next to each other, and a button at the bottom. Never mind the label texts.
The rows of all the table layouts are set to absolute, this is because I want to programatically add rows to the end middle and right table layout if there are more than one local IP address in the computer and setting the rows to auto size or percentage would make alignment difficult if more rows are added.
Now, my problem is that I can't figure out how to make the form resize and move the controls (specifically move the 'OK' button down) when more rows are added.
I have tried anchoring the button to the bottom edge of the form as well as the bottom of the middle table, both produce the same result: the button stays where it is and the new rows overlap it, like this
I would also like to know how to have the form resize to fit the contents of the labels. For example, if the text in one of the labels inside the layout is bigger than the column width, I'd like to have the form grow to accommodate it. Likewise, I'd like the form to shrink to fit the largest text.
I realize that this may not be the most efficient or easiest way to create this particular form, but it is what I've come up with, I of course welcome any suggestions in that regard. It is important to maintain alignment between the rows of all table layouts.
Thanks in advance.

Use a data grid and add controls to it if an add button is pressed. You can scroll through the rows so you won't need to adjust the height of the form

Related

How could I interactively create an invoice and preview it on WPF?

I'm creating a trial project wherein my window has two grids, left grid is sort of a table that has labels and textboxes each row and asks for a specific part of the invoice like item, name, address stuff like that and the right grid is to show a preview of the invoice that the left side is creating.
I thought about using a document viewer on the right side but I thought that anything I open there would be static and if I put values on the textboxes on the left grid, it wouldn't matter since I opened a standalone document to view on the right grid.
I thought about just creating a table out of the right grid and have the default values and populate the other ones when a user types something on the textbox and make it function as the preview but then I don't know how would I go about and printing it and also, it has about 45 rows which I couldn't fit in the grid without it being unreadable (because I had to cram 45 rows of data inside that small grid)
So is there a tool in the toolbox that could potentially create a interact-able grid? I tried the grid control but I can't seem to only make it show 4 columns because that's all I need, I don't want it to show E and the rest of the alphabet because I want it to resize accordingly with only 4 columns to make it more readable.
Oh and I also have devexpress installed so you guys could also recommend something I can use from there. Thank You.
I think this is the best solution since it does what I wanted it to do.
I created a scroll view and placed a grid inside it then set the length accordingly to show it in a reasonable size and let the scroll bar do its magic for me to see the rest of the grid without compromises of the content's size.

How to resize a responsive list from three columns to one (using responsivegridsystem.com)

I am using www.responsivegridsystem.com for my columns and here is what I've come up with: ux.stoicdigital.com/#intro-message.
I'd like the list to work like this one: http://doyouimpress.com/#uses-list
The biggest problems are that, above a certain amount of px (can't remember exact), the three column grid is centered, but doesn't LOOK centered due to cell widths, etc. and that below that amount of px (when list is in one-column mode), the off-center problem is even worse.
Again, I realize that this has to do with cell widths, etc. but I can't figure out where to make the changes I need to do the following at both sizes:
Align text and bullets left
Center the list itself on the page
Any advice would be appreciated. Would especially appreciate any details you can give re: changes to make to CSS.
PS: If there is another way to achieve this outside of Responsive Grid System, I'm open to that too.
The text doesn't look centered because it isn't. The container div is centered, but since you align the text to the left its all scewed to the left, just like it'd be scewed to the right if you aligned the text to the right.
You could align the text to the middle, but then your checkbox icons wouldn't be lined up. If you want the text to be centered but still have the icons lined up you need to attach the icons so something else but the text. You could display them as pseudo-elements to the <li>, but the drawback is that there would be varying amounts of space between the text and the icons.
What I'm coming at is basically that you can't center the columns this way (as long as you don't make sure that the text in each <li> is equally wide) - however you can fake it and that's what they do on that site you're referring to.
To fake it, simply give each column div a unique class name (or target them with :nth-child), then move each column manually to make it look like the content is centered. You could give them different width-values (this is what they do in your example), different padding-values or similar. That's entirely up to you.
As for the one-column layout, do something similar where you add a padding-value to push them closer to the center, but obviously use the same value for all column divs.

How to use Blend to create a basic Grid

I'm a developer who's trying to get the hang of Blend. I've always used Blend to mess with control templates and such, but I'm trying to get the hang of using it for basic UI design, since I figure it's probably a bit faster than typing the XAML up manually in Visual Studio.
Right now I'm just trying to create a basic Grid, but I'm seeing two default behaviors that I'm hoping someone can show me how to change.
1) When I hover my mouse outside of the design surface, I see the temporary yellow line to show up, where the new Grid Column / Row will be when I click. The problem is that the newly created rows are set to heights like 0.2297* How do I get Blend to attach regular heights, like 250?
2) Ignoring 1), once I have some rows and columns, when I drag a button, or combo box, etc, onto one of the cells, it drops it exactly where I release the mouse, while adding some large margins to position it there. Is it possible to tell blend to just drop the control into the cell, and leave the margins alone?
Grids are awesome but it takes a bit of play to get proficient at working with them in Blend. Here are some tips to get you started (I cover this in detail in chapter 4 of my book).
1) When you use the snap lines to create rows and columns Blend automatically makes them relative (Star) sized, which is the behavior you are seeing. To change the row/column style to fixed (Pixel) sizes, click on the Padlock icons to the left and top of the desired rows and columns. Then, either edit the values in XAML or you can click near (but not on) the padlock to select the row or column. This will open the sizing properties in the Properties panel.
2) The short answer is "No". Blend will always add Margins when you draw the element in a cell unless you take care to draw them to the borders. This is too difficult and time consuming, so I just make sure I draw it somewhere inside my target cell. Now I can right-click the element and select "Auto Size > Fill" and the element will fill up the cell: no Margins, Width and Height set to Auto, and Horizontal and Vertical Alignments set to Stretch. [FWIW, addressing this is my number one feature request for Blend.]
I hope this helps.
To answer point 1) Blend is creating proportional grids so that the columns remain the same relative widths when you grow or shrink the grid rather than absolute grids. So if you want absolute grid widths you'll have to go in and edit the values by hand.
I find that it's easier to create the basic form in Blend and then tweak the values in the text editor - either in Visual Studio or Blend itself.
As for point 2) I've just tried this and as long as I click inside the column/row on the grid when placing a button it adds it to the correct column/row of the grid as expected. Select the button and then just double click inside the grid - this should add a button of default size where you clicked, but in the grid. (It would be much easier if I could see what you were doing).

Windows Forms (Or GUI development in general) advice

How should I develop a form that can resize nicely?
While that sounds like a simple question the problem I'm struggling with is the fact I'm reproducing an existing application I made in Swing several years back. Its built around a single form that hides/reveals panels as you select different options.
Its around 600 x 700 pixels wide say but its a fixed size window.
Is this good practice? The GUI works fine this way but if you look at other applications you can resize them easily. Granted some applications look stupid full size but should the option be there?
The main screen consists of about five buttons, when maximized this looks ridicilous, but at the same time if the form is resizable the moment you start resizing the form it becomes stupid.
I'm aware of layout managers and so forth so no need to tell me to check these out, my main problem is the fact I can produce an excellent fixed width application but that's about it.
Any advice/links for this?
Personally, I think fixed size forms are a horrible User Experience.
I always try to build mine so that they can be gracefully resized (even if they do look a little odd).
If you're using .NET for your WinForms development, you can easily use a table layout and then anchor your controls so that they resize politely.
A fixed size gui is generally a bad idea because most forms have a user interface element that can sensibly be resized.
First consider a form that only contains two buttons. (A silly form, yeah, but for the sake of discussion we'll assume that it's the right thing for the job) When sized initially in the right way (appropriately for localization, e.g.), there's no good reason to make the form resizable. If you enlarged or mazimized the form, you'd only make the area to click the button bigger, but you'd be clicking a smaller area than the button to resize it, so there's no reason. In this case, it doesn't make sense for the form to be resizable because there's no user-benefit for adding the extra control.
Now consider a form that contains a listview. There are clear usability benefits to making this form resizable in both dimensions. The listview may contain more items than can be shown in a smaller area, both horizontally and vertically, so it makes sense that this form be fully resizable to allow the user to display as much or as little of the data as they want.
Every form control implicitly has certain degrees of freedom either by constraint or by convention. Conventionally, buttons don't resize, so they have no degrees of freedom (even though they can resize). Listviews and listboxes have two degrees of freedom, horizontal to display more data per row and vertical to display more rows. Single line textboxes have one degree of freedom, horizontal. Because they're single line, they don't expand vertically, but they do expand horizontally.
These degrees of freedom help you determine the layout of your form. Form elements that have degrees of freedom should resize in the appropriate direction when the form is resized. I prefer to design my forms with only one control that has two degrees of freedom in an area where areas are typically separated via splitters. I prefer to avoid the explicit table layout panel unless there's a very specific need for it because it's easy to make a form overly complex when there's a table layout to work with. The anchors in WinForms provide an extremely powerful and flexible abstraction for control layout, however, so I strongly encourage their usage.
Aside from the layout panels (my favorite is the table layout), become familiar with the Anchor, Dock (more for the table layout), and MinimumSize properties. They do a lot of work for you when it comes to resizing forms.
Most of your forms will look goofy maximized but my general rules were these:
Buttons stay the same size
regardless of form size (no Top and
Bottom anchor; no Left and Right
anchor).
Buttons stay in the same place with
respect to a border (Anchor
combinations: {Left, Top}, {Left,
Bottom}, {Right, Top}, {Right,
Bottom})
Only the right-most textbox grows
when resizing (Anchor = Left and
Right).
Single multiline textboxes rule the form
(Anchor = Left, Right, Top, Bottom)
With multiple multiline textboxes, the lowest one rules the form.
MinimumSize is less that 640x480 whenever possible; 800x600 max.
The default size is the MinimumSize -- let the users make it bigger if they need to.

Spreading controls to fill space as a dialog resizes

I have a dialog with column down the right side filled with buttons. The dialog is built with Windows Forms. I have a mockup at the following link:original dialog
(I would have included it but apparently i'm not allowed to use image tags)
I would like for the buttons in the right column to resize themselves to fill the remaining vertical space when the dialog resizes. It doesn't particularly matter to me whether or not buttons simply increase in size or whether the buttons remain the same size while the gaps between them increase. I'm simply want the buttons to go from the top to the bottom. (I have a mockup for this as well but apparenlty i can only include one link)
I've tried hosting the buttons in a FlowLayoutPanel but they do not increase as the dialog stretches, I only get whitespace at the bottom after I run out of buttons. I also tried a TableLayoutPanel and had the same result but I may have misused it. Does anyone have any ideas how I could accomplish this?
Thanks in advance,
Jeremy
To get you started. Use the TableLayoutPanel, set its Anchor property to top, bottom, left, and right. Set the rows and columns to percentages as needed. I suggest each control have it own cell. Note that each control in a "cell" can have its Dock and Anchor property set as needed.
You can do this with a TableLayoutPanel. Create a column for the buttons, with each button having it's own row / cell in the column. Set each row to be an even percentage for height (if there are 10 buttons, each row would be 10%), and dock the TableLayoutPanel to the right side of the screen. Then, put the buttons into their rows and set them to full docking. Then, when the dialog expands, the TableLayoutPanel will expand to fill the entire right side of the screen, each row will adjust proportionally, and each button would expand to fit the new row size.
You may have to adjust this a bit to fit your needs, especially in how it relates to the other content in the window.

Resources