Resize a .NET form

R

Rob

I want to resize the height of a form without resizing the width,
therefore I tried:

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize

Me.Width = 226

End Sub

However this causes a lot of flickering on my form. How can I turn
off the flickering ?

Please help, RS
 
A

Armin Zingler

Rob said:
I want to resize the height of a form without resizing the width,
therefore I tried:

Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize

Me.Width = 226

End Sub

However this causes a lot of flickering on my form. How can I turn
off the flickering ?


Example:

Imports System.Runtime.InteropServices

Public Class Form1

<StructLayout(LayoutKind.Sequential)> _
Private Structure MinMaxInfo
Public reserved As Point
Public maxSize As Point
Public maxPosition As Point
Public minTrackSize As Point
Public maxTrackSize As Point
End Structure

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)

Const WM_GETMINMAXINFO As Integer = &H24

MyBase.WndProc(m)

If m.Msg = WM_GETMINMAXINFO Then
Dim mmi As MinMaxInfo

mmi = DirectCast( _
Marshal.PtrToStructure(m.LParam, GetType(MinMaxInfo)), _
MinMaxInfo _
)

mmi.maxTrackSize.X = 226
mmi.minTrackSize.X = 226

Marshal.StructureToPtr(mmi, m.LParam, True)
End If

End Sub

End Class




Armin
 
P

Phill W.

Rob said:
I want to resize the height of a form without resizing the width,
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Resize
Me.Width = 226
End Sub
However this causes a lot of flickering on my form.

Fix the width of the form using MinimumSize and MaximumSize:

Me.MinimumSize = New Size( 226, 0 )
Me.MaximumSize = New Size( 226, 600 ) ' say

Better still, get the current screen size and use that for the maximum
height instead - I can't' remember the code just at the moment.

HTH,
Phill W.
 
R

rowe_newsgroups

Better still, get the current screen size and use that for the maximum
height instead - I can't' remember the code just at the moment.

I'm guessing you're referring to either
Screen.PrimaryScreen.Bounds.Height or
Screen.PrimaryScreen.WorkingArea.Height

Thanks,

Seth Rowe
 
P

Phill W.

rowe_newsgroups said:
I'm guessing you're referring to either
Screen.PrimaryScreen.Bounds.Height or
Screen.PrimaryScreen.WorkingArea.Height

That's the ones!

WorkingArea is the better of the two, taking into account those awkward
people (like me) who move the Start bar around the screen and make it a
different size ... ;-)

Regards,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top