Valhalla Legends Forums Archive | .NET Platform | VB8 - Control resizing to fit form

AuthorMessageTime
JoeTheOdd
I'm sure anyone who's written a bot has seen code somewhat like this:

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

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).

[code]    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[/code]

However, the form doesn't seem to have Width and ScaleHeight. How would I finish porting that original code?
June 27, 2006, 8:20 PM
K
Take a look at the Anchor and Dock 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.

June 27, 2006, 10:53 PM
JoeTheOdd
Huzzah, it works!
June 28, 2006, 5:18 AM
Myndfyr
I would point out that I wrote a tutorial on this topic.  I'm in the process of fixing the image links.
June 29, 2006, 3:24 AM

Search