Valhalla Legends Archive

Programming => General Programming => .NET Platform => Topic started by: Joe[x86] on June 27, 2006, 03:20 PM

Title: VB8 - Control resizing to fit form
Post by: Joe[x86] on June 27, 2006, 03:20 PM
I'm sure anyone who's written a bot has seen code somewhat like this:

Public Sub frmMain_Resize()
    With rtbOutput
        .Top = 200
        .Left = 200
        .Width = Me.Width - 400
        .Height = Me.ScaleHeight - 400
    End With
End Sub


Now, for my .NET Bot that I'm writing, I'm looking to make similar code.

First, the menu is now an object on the form and no longer a part of the form itself, so I had to increase the top margin to make room for it. Also, it's no longer measured in twips, but in pixels (I think). Therefore, I'm having the top left corner of the RTB at (25, 10).

    Private Sub frmMain_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        With rtbOutput
            .Top = 25
            .Left = 10
        End With
    End Sub


However, the form doesn't seem to have Width and ScaleHeight. How would I finish porting that original code?
Title: Re: VB8 - Control resizing to fit form
Post by: K on June 27, 2006, 05:53 PM
Take a look at the Anchor  (http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.anchor.aspx)and Dock (http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.dock.aspx) properties of the Control.  You do not need to add custom code to resize elements on the form. 

Simply place your textbox at the correct Left/Top position with the designer, and size it to be N pixels from the right/bottom of the form.

Now click on the Anchor property, and select all the options. (Top,Left,Right,Bottom).

Now try resizing the form.  Huzzah, the textbox will stay the same number of pixels away from each border, even after being resized.

Title: Re: VB8 - Control resizing to fit form
Post by: Joe[x86] on June 28, 2006, 12:18 AM
Huzzah, it works!
Title: Re: VB8 - Control resizing to fit form
Post by: MyndFyre on June 28, 2006, 10:24 PM
I would point out that I wrote a tutorial (http://forum.valhallalegends.com/index.php?topic=10716.0) on this topic.  I'm in the process of fixing the image links.