DataGridView anchors - c#

I have a Windows Form with 2 DatagridViews placed side by side, but when I maximise the form they either remain with their original sizes or one overlaps another, depending on how I've set the anchors.
Is there a way I can limit how much those controls can grow to each direction?

Yes, you can.
Use MaxiumSize.Width, MaxiumSize.Height to set the maximum size of your control. You'll need to set minimum size as well using MinimumSize.Width and MinimumSize.Height properties.

Related

How to expand winform controls an equal amount as the form expands

I have a row of buttons across a Winform, and as the form increases in size horizontally, i want the space between the buttons to increase the same amount but relative to their position on the form. Rather than them being anchored left or right or middle, for it to be almost organic. Does anyone have any suggestions as to how to do this?
I was always able to get acceptable results from using the anchoring, sometimes combined with frames. Alternatives I looked at to get further control over behavior were frameworks both paid and free as well as using form events to capture when the form is resized and then using code to adjust control sizes.

Scale the size of windows form and it's control

I am working on a windows form application where I want my windows form to scale as I grow the size of the form. For instance,
What I want here is when the user resizes it to bigger size, the controls should also resize with it. What's happening now is:
Can anyone please suggest a way to achieve it? Thanks in advance!
Please take a look at the Anchor-Property. What you want to do is achor the textboxes left, right and top. The elipsis-Buttons and compare button should be anchored top right. The large textbox should be anchored to all sides. And so on.
You won't need docking. If you also want to support environments with large fonts (larger dpi) you should use a table layout contron instead. In that case forget about the Anchors and set every Docking-property to fill.

How to run or adjust Windows application efficiently in any screen resolution in C# 4.0?

How to run or adjust Windows application efficiently in any screen resolution in C# 4.0?
I have done it in 1600 x 1200 resolution but if I try in lower resolutions only some part of the forms are visible.
How to solve this problem? I have searched a lot and got to know about Anchor & Dock will be useful but also to came to know that these should be used from the beginning of designing but I have completed my application while this resolution is now causing the problem when I install the application in any system
The quick and dirty method of making sure your controls remain visible would be to place a Panel on the form, set Dock = Fill and AutoScroll = True, then place every other control in your form inside it. Your controls won't get cut off, but your program won't win any awards for asthetics. If the program is brand new, that's really not the way you want to start things off.
You could redesign it to make use of Anchors and Docking, as you mentioned. You could also place items such as a row of Button controls or a series of TextBox controls in a FlowLayoutPanel, which will take care of repositioning them as you resize the form.
But if adjusting for screen resolutions is important to you, a better way would have been to use WPF from the start. Controls are automatically resized and repositioned as needed, based on their container control.
The real question should be:
How do I want the controls to resize themselves with their parent?
The answer is that you need to specify anchors. Anchors are used to tell your controls how they should react on resize, and what the concerns should be.
Lets say you have a form with two [Cancel] and [OK] buttons. They are usually seen fit at the bottom right of your window. But the default Anchor property is set to Top, Left, so on your form's resize, they stick to the Top, Left corner where they belong according to the default settings. This won't be any trouble if your maximize your form, thus you'll have your button probably in the middle of the screen. But at least, you will see every controls adequately.
But what if resize your form smaller and smaller? Do you still want them to stick at the Top, Left, or Bottom, Right would be more useful? My guess is that you should set the Anchor property to Bottom, Right, for those two.
This might come in handy to have different Anchor property settings depending on how you want your control to react to your form resize. Let's take three TextBox controls aligned horizontally with each other. Perhaps your longer field will be your object Description property located on horizontal-center of your form. Then, when you risize, you have to think what would make more sense on resize. If it is to make it longer on resize in order to fill your form width with all your control, then perhaps you want the DescriptionTextBox to get wider and wider, and the contraray should also be true, on form's resize, you probably want this field to be resized smaller too. Then, to make this happen, you have to set the Anchor property to Left, Right, so that the edge of your DescriptionTextBox control remains at the same very distance of your form's edge at any time.
Another thing is of concern in case of resizing to smaller window, is its MinimumSize property. One shall agree that there is use to have a form of size 34x34 pixels. So, setting your MinimumSize property to a certain size which makes sens for the form to exist, you will avoid display glitches of controls getting one over another.
For more details on the Anchor property: Control.Anchor Property
For more details on the MinimumSize property: Control.MinimumSize Property

Infinite Vertical Scrolling

I have a WinForms application and a Panel Control. The panel control has a VScrollBar control for vertical scrolling. Everything works fine except right now I have my VScrollBar maximum value set to 100. The problem is, I need the Maximum property to be about 4 billion, however, since Maximum is only an Integer, I can't set it to the proper value. So, my question is, how do I get around this? I know there are text editors and file viewers that claim to view more then 4 gigs of data, so how would a scrollbar in an application like that work?
A scrollbar is a GUI control. Innately, the number of steps it can display is limited to the number of vertical pixels on your screen. Therefore, you could consider setting the maximum value to anything above that to be simply for developer convenience, to make the math easier.
How do applications deal with scrollbars? In theory, you'd want to parse the file first, to find out how many lines are in the file, and use that as your logical maximum. In reality, reading 4 GB of data when the file is opened would kill performance, so that wouldn't work.
If I were implementing this, I would set the scrollbar maximum is set to a large value, say 10,000. When the scrollbar is used, the scrollbar value is divided by 10,000 to get a percentage, and the editor shows that section of the file.
Don't think of things in terms of scrolling down so many lines. Instead, think of it as jumping to that percentage offset of the file, reading the data there, and displaying that.
Well, you could just set Maximum to int.MaxValue and scale the retrieved value to your real maximum value. This should be enough precision to avoid loading too much data.
You use a percentage. There is no need to set it to the same as the number of lines.

Constrain the movement of a SplitContainer in C#?

I have a SplitContainer in my form.
On the 1st panel I have a TreeView and a ListView on the 2nd. (Classic)
Now I want to limit the size of the 1st panel (with the TreeView) to 250 pixels wide.
I wish to block the separator from moving too much (or too less).
How do I do that?
You can use SplitContainer.Panel1MinSize property.
SplitContainer1.Panel1MinSize = 250;
First, if you want to constrain the TreeView to be EXACTLY 250px, set the FixedPanel to be Panel1, set the IsSplitterFixed property to True, and set the Panel1MinSize to 250. This basically makes the split graphical only; the splitter will default to a size large enough for the TreeView, and will not move.
If you want to constrain the TreeView to be AT LEAST 250px, simply set Panel1MinSize to be 250. This will prevent the user from making the panel SMALLER than that, though they can make it LARGER. There is no maximum constraint, but you can get the effect of one by setting a maximum size for the window and a minimum size for the other panel of the SplitContainer.
Just a little addition.
Here is the code to place in the frmMain_Load() (or whereever). In the code, the minimum is 250 pixels and the maximum is 400 pixels.
this.splitContainer1.Panel1MinSize = 250;
this.splitContainer1.Panel2MinSize = this.splitContainer1.Width - 400;
Do not forget to place the same code in the resize event frmMain_Resize()
I guess you should take look at the FixedPanelProperty of the splitContainer. I allows you to only let the other panel grow and shrink on rezise operations:
The resizing is much smoother.

Categories

Resources