Is there a way to restrict form resize to certain size? I want to allow user to resize the form to a certain minimum size only, but I'm not sure how to do that. Here's the problem why I want to limit mininum form resize. I've created a couple of textboxes and datagrid. I have two buttons that are below textbox5. The textbox5 is Anchor to Top,Bottom,Left,Right. The two buttons are Anchor to Bottom,Left. The problem is when the user resize the form to smaller size than normal, those two buttons are coming on top of those textboxes and datagrid. If I set the Anchor for those two buttons as Top,Left, then when the form is enlarged by the user, the textbox5 is coming underneath the two buttons. I have tried using the GroupBox, but I can't get rid of the square lines that suround the two buttons. The best way would be to figure out how to not have those two buttons go on top of any object when resizing, but I don't know how that is done.
Yes, I want to allow the user to resize the form. The form have a textbox that may need to be resized to be bigger than I initially desiged for.
Yes, I found the forms property for the minimum size now. I thought it was something harder than that.
Anyway, many thanks for the help.
By the way, just curious. If I would to make those buttons work instead of limiting the minimum size, what are your suggestions on how to make those buttons work with the form when it is resize? Because right now those two buttons are on top of other objects and some time underneath other object if the user resize the form.
Or if you really need to let the user resize for some range(though you need to set the value in the 'siz' variable manually) or never let him resize , do this :
VB Code:
'Class member varaible
Dim siz As New Size
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Get the current size , to use later .
siz = Me.Size
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
'Whenever the user tries to resize , set back the size as it's before
As you can see on the screen in the attachment, the Clear button is on top of the textbox and the other button on the far right is underneath the textbox. This only happens if I resize the form to smaller than I initially designed.
This button moves up as the form is resize to smaller size. This behavour is due to anchoring the two buttons to Buttom and Left. If I specify the two buttons to anchor from Top and Left then the oposite problem occur. The buttons will not move down therefore, the textbox will be underneath one button and on top on another the form is enlarge because this textbox is anchor Top,Bottom,Left,Right.
Umm , I was trying to do some kind of calculations on getting point of controls and then storing that in a point objs , use them later while resizing and maybe increment/decrement the values from x and y . This really sucks . You need to detect when the form is resized(increased/decreased) and even more when this happen horizintally or vertically . Sure this would raise many problems later . Just use this ancoring stuff. Maybe you need to rearrange your controls in a way they fit together or paste them all in a panel control and anchor the panel to your form . This would treat the panel as one obj when resizing . Reconsider .
Here's the thing. Right now those controls are on a panel. The panel is on top of the form. The panel does not have any anchor; however, the panel's Dock property is Fill. So I'm not sure what anchor will do.
You can use one of them , not both .
Set the panel's Dock property to Fill , the textBox and the Button's anchors to Top . This kinda works but fails when the user excessively resize the form .
My advice is to prevent the user from resizing the form . That's all .
I believe Dock keeps the control flush against the side of the container, whether form or panel, etc.
I think anchoring the controls is what you want. They'll resize as the container size changes. You may have to play with what sides you want to anchorwith. If you have a button on a panel, anchor it on the panel, anchor the panel on the form. If the user can resize any side, try anchoring to all 4 sides.
That exactly what I did. I put a limit on how big or small the user can resize the form. This works...however, I just wonder if there is a solution for this problem. Because not all application will have this limit on resizing.
So for my particular situation, the size limit works for now.
I tried anchoring many different ways and it still doesn't work with those buttons if the user resize it beyond the initial designed size. If the panel is anchor all the sides and those two buttons are anchor top left, when the form is enlarge, the buttons will not move down. If the buttons are anchor bottom left then the buttons will move up and down...however the buttons will be moving on top of other controls as showed in the attachment.
In this case , put the two buttons inside another panel , dock it to the Bottom of the form , and the first one should be docked to Fill .I've just tried this and it works .
Yes, that will work. The issue is, in this application, I already have 4 panels in the same form and so I don't want to add too man panels. I'm afraid it will be too slow to load some old computer. That is why I didn't use another panel.