• Welcome to Valhalla Legends Archive.
 

VB8 - Control resizing to fit form

Started by Joe[x86], June 27, 2006, 03:20 PM

Previous topic - Next topic

Joe[x86]

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?
Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

K

#1
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.


Joe[x86]

Quote from: brew on April 25, 2007, 07:33 PM
that made me feel like a total idiot. this entire thing was useless.

MyndFyre

I would point out that I wrote a tutorial on this topic.  I'm in the process of fixing the image links.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.