How to save the form width and height in a variable?

  • Thread starter Thread starter Tinus
  • Start date Start date
T

Tinus

Hello,

What is the best method for saving the width and height of a form?
What event can I use best for this?

In other words, where to put the code: frmWidth = Form1.Width;

Thanks,
Tinus
 
probably in the SizeChanged event of the form. This is fired whenever the
Size property changes - either width or height. That way you'll have the
current width and height of the form in your variables.


Imran.
 
Yet I don't see the need for another variable if the form's dimensions are
already available.
 
Then use the OnSizeChange event handler.
Get the difference first before updating your previous dimension variables.
 
But how do I calculate (get) the difference without storing the original
width/heigth before the resize?

Am I overlooking something or ....

Tinus
 
What do you want to do with the original size?

Here's one solution in VB that will give both Old and Current Size in one
variable.

\\\
Structure FormSize
Public OldSize As Size
Public CurrentSize As Size
Public Sub New(ByVal Old As Size, ByVal Current As Size)
OldSize = Old
CurrentSize = Current
End Sub
End Structure

Private MyFormSize As New FormSize(Size.Empty, MyBase.Size)

Protected Overrides Sub OnResize(ByVal e As System.EventArgs)
MyBase.OnResize(e)
MyFormSize = New FormSize(MyFormSize.CurrentSize, Me.Size)
End Sub
///
 
Back
Top