HighTechTalks DotNet Forums  

Change of Form Location Using System.Drawing.Point Ignored When FormMaximized

VB.net microsoft.public.dotnet.languages.vb


Discuss Change of Form Location Using System.Drawing.Point Ignored When FormMaximized in the VB.net forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Marc the Demi-Programmer
 
Posts: n/a

Default Change of Form Location Using System.Drawing.Point Ignored When FormMaximized - 11-06-2006 , 11:22 AM






I am overriding WncProc to make sure my form's location stays within
specified parameters. Basically, it has to stay at the top of the
screen and not be off to either of the sides. All that works when the
form is in its minimal size. However, when the form is maximized using
the appropriate button the code that is supposed to set the location is
ignored. When the form is switched back to the standard dimensions
through the restore button the location setting works again. My
debugging information shows that the code used to set the location is
processed when the form is maximized, as it is when the form is not
maximized. I do not get any error messages. Here is my code:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_SIZE As Integer = &H5
Const WM_MOVE As Integer = &H3
Const SIZE_MINIMIZED As Integer = 1
Const SIZE_MAXIMIZED As Integer = 2
Const WM_EXITSIZEMOVE As Integer = 562
Const WM_SYSCOMMAND As Integer = 274
Try


If m.Msg = WM_EXITSIZEMOVE Or m.Msg = WM_SYSCOMMAND Then
Debug.WriteLine("msg" & " " & m.Msg & " " &
m.WParam.ToString)

If Me.Location.X + Me.Width >
System.Windows.Forms.Screen.PrimaryScreen.Bounds.W idth Then
Debug.WriteLine("Too far right")
Me.Location = New
System.Drawing.Point(System.Windows.Forms.Screen.P rimaryScreen.Bounds.Width
- Me.Width, 0)
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
ElseIf Me.Location.X < 0 Then
Debug.WriteLine("Too far left")
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
Me.Location = New System.Drawing.Point(0, 0)
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
Else
Debug.WriteLine("Something else")
Me.Location = New
System.Drawing.Point(Me.Location.X, 0)
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
End If

End If
MyBase.WndProc(m)
Catch ex As System.ArgumentException
MsgBox(ex.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub

Reply With Quote
  #2  
Old   
Marc the Demi-Programmer
 
Posts: n/a

Default Re: Change of Form Location Using System.Drawing.Point Ignored WhenForm Maximized - 11-08-2006 , 05:45 PM






After some experimentation I find that if the size of the window when
the program starts is set for the maximum size then the desired behavior
happens only when the window has been sized to the maximum. It appears
that whenever the form is put into the restored state, i.e., not
minimized or maximized, then any code that attempts to change the
location of the form is ignored, even though all other code in the same
sub, even debug code below and above the location change code, is executed.

Marc the Demi-Programmer wrote:
Quote:
I am overriding WncProc to make sure my form's location stays within
specified parameters. Basically, it has to stay at the top of the
screen and not be off to either of the sides. All that works when the
form is in its minimal size. However, when the form is maximized using
the appropriate button the code that is supposed to set the location is
ignored. When the form is switched back to the standard dimensions
through the restore button the location setting works again. My
debugging information shows that the code used to set the location is
processed when the form is maximized, as it is when the form is not
maximized. I do not get any error messages. Here is my code:

Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Const WM_SIZE As Integer = &H5
Const WM_MOVE As Integer = &H3
Const SIZE_MINIMIZED As Integer = 1
Const SIZE_MAXIMIZED As Integer = 2
Const WM_EXITSIZEMOVE As Integer = 562
Const WM_SYSCOMMAND As Integer = 274
Try


If m.Msg = WM_EXITSIZEMOVE Or m.Msg = WM_SYSCOMMAND Then
Debug.WriteLine("msg" & " " & m.Msg & " " &
m.WParam.ToString)

If Me.Location.X + Me.Width
System.Windows.Forms.Screen.PrimaryScreen.Bounds.W idth Then
Debug.WriteLine("Too far right")
Me.Location = New
System.Drawing.Point(System.Windows.Forms.Screen.P rimaryScreen.Bounds.Width
- Me.Width, 0)
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
ElseIf Me.Location.X < 0 Then
Debug.WriteLine("Too far left")
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
Me.Location = New System.Drawing.Point(0, 0)
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
Else
Debug.WriteLine("Something else")
Me.Location = New
System.Drawing.Point(Me.Location.X, 0)
Debug.WriteLine(Me.Location.X & " " & Me.Location.Y)
End If

End If
MyBase.WndProc(m)
Catch ex As System.ArgumentException
MsgBox(ex.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub



Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.