Form object resizing

Hi there everyone,

Something is baffling me here. I'm trying to code a resize event to ensure correct placement of my controls whenever the form is resized. I have a picturebox control that I wish to fill the screen but leaving a gap, of around 3, either side. At the bottom of the form I have a textbox control (txtCallsign) that I intend to keep fixed to the bottom of the form. I've tried the following code:

PrivateSub frmMain_Resize(ByVal senderAsObject,ByVal eAs System.EventArgs)HandlesMe.Resize

' Resize the picture box control as the form

' resizes.

PictureBox1.Left = 3

PictureBox1.Top = MenuStrip.Height + 1

PictureBox1.Width =Me.Width - 6

PictureBox1.Height = (Me.Height - 4) - txtCallsign.Height

EndSub

For some strange reason the picture box control seems to go off the screen to the right and is also off the screen to the bottom, completely blanking the text box out.

Any ideas because it's baffled me. I've managed to get it sized correctly on the right but only after using this line:

PictureBox1.Width =Me.Width - 14

I have no idea where the 14 has come from? Seems like quite a strange random number to me.

Thanks in advance,

Ady

[3356 byte] By [AdrianFoot] at [2007-12-24]
# 1

Ady,

I used to spend a lot of time on these issues. There are indeed better ways.

Take a look in your toolbox and in the help file at panels, specifically the tablelayout panel and splitter panels.

Easy resizing management is what these are for.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Oh and also those numbers... I can't account for the entire 14 but I can account for eight of the fourteen. The two side borders of the form are 4 + 4 and the form is measured from outside boundary to outside boundary. Do controls have a three pixel boundary? if so that would add up to your fourteen

System.Windows.Forms.SystemInformation.BorderSize will provide the boarder width of vertical borders.

ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Many thanks for the reply. I've since found the table layout panel and it's working a treat for what I need. Again thanks a lot for the help.

Regards,

Ady

AdrianFoot at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4
Great !!!!!!!!! :)
ReneeC at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 5
And just as another tip for your toolbox, if you didn't know already you can take advantage of the Anchoring and Docking properties as well to deal with control placement and form resizing. Please mark this thread as answered. :)
AnthonyD.Green at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 6

Hi ya,

Thanks for the tip! I would mark this thread as answered but everytime I try I get an error message. I get the same message any time I make a new post too (though the post is still 'posted').

Error message:

We apologize, but an unknown error has occured in the forums.

This error has been logged.

Ady

AdrianFoot at 2007-8-31 > top of Msdn Tech,Visual Basic,Visual Basic General...