Results 1 to 20 of 20

Thread: How to restrict form resize?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Question How to restrict form resize?

    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.

    Any help is greatly appreciated.

    ljCharlie
    Last edited by Chong; Dec 18th, 2003 at 04:23 PM.

  2. #2
    Addicted Member Rally2000's Avatar
    Join Date
    Dec 2003
    Location
    Central USA
    Posts
    134
    Does it have to be sizeable?
    Not that I’m questioning why, just curious

  3. #3
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    you could do something similar to:

    Code:
    if form1.size > x,x then
    form1.size = your maximum size
    else if form1.size is < x,x then
    form1.size = your minimum size
    seems like there is a way to do this though in design time from the properties window.

  4. #4
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    yeah, I just looked. there is a minimum size property and a maximum size property

  5. #5
    Addicted Member Rally2000's Avatar
    Join Date
    Dec 2003
    Location
    Central USA
    Posts
    134
    Sure!
    but what I was getting at is simply the fact that if he could get by with a set size, all he'd have to do is set his window to fixed state

  6. #6
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    oh, absolutetely. That's what i'd do as well. He must have some special purpose for being able to re-size at all, huh?

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219

    Thumbs up

    Many thanks for all your suggestions.

    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.

    ljCharlie

  8. #8
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489
    you need to set the z order. I'm not sure what the correct syntax is. I looked on msdn but it didn't really help any. Look into that.

  9. #9
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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:
    1. 'Class member varaible
    2. Dim siz As New Size
    3.  
    4. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    5. 'Get the current size , to use later .
    6.         siz = Me.Size
    7. End Sub
    8.  
    9. Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
    10. 'Whenever the user tries to resize , set back the size as it's before
    11.         Me.Size = siz
    12. End Sub

  10. #10

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    Thanks! I got the resize thing works now.

    However, I was wondering if anyone have any idea on how to fix the buttons problem.

    And thephantom, thanks! I'll try to look into that too.

    ljCharlie

  11. #11
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I don't know exactly what do you mean (maybe I've never had that situation before) . Can this help ?
    VB Code:
    1. Me.Button1.BringToFront()
    Or if you don't mind , can you show some screenshots of your problem ?

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    Pirate, thanks for interested in helping me.

    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.

    ljCharlie
    Attached Files Attached Files

  13. #13
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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.

    ljCharlie

  15. #15
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  16. #16
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950
    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.

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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.

    ljCharlie

  18. #18

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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.

    ljCharlie

  19. #19
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    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 .

  20. #20

    Thread Starter
    Addicted Member
    Join Date
    Feb 2003
    Posts
    219
    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.

    ljCharlie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width