Customize WPF application user controls - c#

I'm trying to put in my windows a Datagrid and some other things (TextBox, Dropbox).
My problem is that when I resize the windows I can't control the items.
What I want to do is to devide the Windows like the picture below, and want the them to fit the window when I resize the window.
What do you suggest.

Put them in a Grid with two RowDefinitions. One for the toolbar/controls at the top, the other for the DataGrid.
Make the first row height Auto, and the second row height *.
Set the HorizontalAlignment and VerticalAlignment properties on the DataGrid to Stretch.

You should definitely use the Grid class.
Add Rows and Columns and change the Height and Width properties of these object to resize as you want (fixed value, Auto, *).

Related

Scrolling with multiple controls in panel C#

I have a Form with 4 Controls. One panel, which contains 2 DataGridViews and 1 Label. First there is a datagridview, then the label and then the last datagridview. The Form has a specific size like 600x400. I also want that the first datagridview should have the exact height of all cell height + header cell height from the first datagridview. If its bigger than 400, there should be a scrollbar on the right. If the user scrolls down, he should the the label and the 2. DataGridView. If the Height is less than 400, maybe 300, then it should show already the label and a scrollbar on the right. How could I do that?
Thanks!
The Panel control has a property called "AutoScroll" that you can set to true (in the properties pane while you are in design mode.) This will handle showing and hiding the scrollbar based on the size of the child controls. Make sure that the panel has a fixed height, rather than using AutoSize.
If I am understanding correctly, you want the first DataGridView to size itself based on the size of its contents. To do that, just set AutoSize = true on the DataGridView and it will resize based on its contents.
If you want more specific help, you can post your code and what you have tried, and you may get a better answer.

How to handle an empty datagridview?

I am using the datagridview from the toolbox and I want it to look good.
Everything works perfectly but I need some styling advice here.
Because I have a default sized form and when I have many view rows in my datagridview it looks bad because half of the view is the forms background and not my data grid view. But I want it to seem like the whole thing is the table.
DataGridView rows, columns, and headers can change size as a result of many different occurrences:
User resize - Users can make size adjustments by dragging or double-clicking row, column, or header dividers.
Control resize - In column fill mode, column widths change when the control width changes; for example, when the control is docked to its parent form and the user resizes the form.
Cell value change - In content-based automatic sizing modes, sizes change to fit new display values.
Method call - Programmatic content-based resizing lets you make opportunistic size adjustments based on cell values at the time of the method call.
Property setting - You can also set specific height and width values.
By default, user resizing is enabled, automatic sizing is disabled, and cell values that are wider than their columns are clipped.
For more information look here
I am assuming you want the datagrid view to adjust automatically to the size of the form. In this case, Set the anchor property of the control to hook to all sides of the parent - top, bottom, left, and right.
If you want your form looks like a table you can use Dock property for datagridview. and dock this tool to the form
and then you must do some changes on datagridview view like this:
dataGridView1.Dock = DockStyle.Fill;
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.RowHeadersVisible = false;
adding some rows and columns for see the setting result
dataGridView1.Columns.Add("column1", "column1");
dataGridView1.Columns.Add("column2", "column2");
dataGridView1.Columns.Add("column3", "column3");
dataGridView1.Columns.Add("column4", "column4");
dataGridView1.Rows.Add(10);
and then you can set form back color and datagridview back color as same color.

AutoScroll event in WIndows Forms

I have a windows form with two controls, one mail control (Dock = Fill) and a property control (Dock = Right). The property control is set to AutoScroll. It has some expandable panels and if the user expands too many panels the height of the control is larger than the window height and I set the AutoScroll property in order to automatically display scrollbars in this case - this does work. However the scrollbar is plotted over the property controls. The scrollbars of course needs some place but I would like the property window to grow in width as long as the scroll bar is shown (and hence reduce the size of the main control a bit) so that the scrollbar is on the right side of the property control which is completely shown.
Can you give me a hint? Do I need to change some properties of the controls? Or is there an Event "ScrollBarsShown" or something which I could catch and manually extend the width of the property control?
Thank you very much!
Put these controls in a TableLayoutPanel. The arrangement should be two columns, one row. Column0 would be set to 100%, while Column1 would be AutoSize. The Row could be either.
Then just dock fill the TableLayoutPanel in your form.

change the height of statusStrip

I have a simple windows form with a statusStrip in VS2010, and no matter what I tried, the height of statusStrip does not change, what is proper way of changing the height??
thanks
I just changed the StatusStrip size without problems...
Create a new Form.
Create a StatusStrip.
Set its property "Dock" to "None".
Set its property "Autosize" to "False".
Set its property "Size" with Height = 'the height you need' (I have put it to 100).
If you want, now you can Dock to "Bottom" again.
Add a ProgressBar: it will be 100 Height.
Let me know if this works for you
None of the mentioned approaches worked. Eventually this is the working solution for us:
First, use a TableLayoutPanel with a row at 100% and bottom row with absolute height of 24 (or any desired height you want).
Second, drag and drop the ToolStrip control into the bottom row, and setting the Dock property to Fill. This forces the ToolStrip control to fill the bottom cell of the TableLayoutPanel. Now you have a toolstrip with height 24.

Grid row height adjustment

I have two Expanders in a grid, both in Auto sized rows.
When the height of the Expander is very large, the row overflows out of the grid.
Is there a way to have Auto sized rows that take only the grid space that's available?
Try setting the MaxHeight property on either the expander object or the object inside the expander.
You could use a DockPanel instead - and then dock the first Bottom and let the other fill. Or put each Expander inside a ScrollViewer.
i would set the last rowDefinition to Height="*",
then the last row fills out all the space left.
but it doesnt help if not only the last row would overflow..
See my custom auto-sizing panel/grid class here. I wrote it specifically to address this problem--full source is in the question.
(To use it, create a new class that inherits from panel and paste the working code into the class, then use the custom class just like a StackPanel.)
It currently only supports Vertical orientation, but could easily be modified to support Horizontal as well.

Categories