473,396 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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

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
Nov 6 '06 #1
1 9388
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:
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

Nov 8 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: SS KANAGAL | last post by:
Hello, I am drawing a bar graph in an aspx page using System.Drawing namespace . Now I want to provide drill down facility for the graph i.e. on click of a bar in the graph it should get me yet...
1
by: Paul Hoad | last post by:
I'm trying to use MeasureString() to determine the length in pixels of a string However to do I need a System.Drawing.Graphics object to do this I need to create a System.Drawing.Graphics...
1
by: Bilo | last post by:
Need Help with System.Drawing.Point b = new System.Drawing.Point(int x , int y) I want to move a window when mous is down and mous is moving private void label1_MouseMove(object sender,...
0
by: John via .NET 247 | last post by:
Hi, I'm using the System.Drawing.Bitmap namespace to load an image,and the RotateNoneFlipY method to flip that image before saving.However I have noticed that the saved image appears cropped...
0
by: Willem | last post by:
Hi, I'm using System.Drawing.Printing to print some simple information. Private WithEvents mDoc As New PrintDocument The click event on a button has the mDoc.Print()
1
by: jjbutera | last post by:
I have a custom font installed on my machine, but I can't seem to use it with System.Drawing. Dim f As New Font("MyCustomFontName", 20, FontStyle.Regular) This just gives me the default of...
5
by: hzgt9b | last post by:
I'm building a dataset that writes out a Point type value. Here's the code that I've got: 1 Dim dsContent As DataSet = New DataSet("content") 2 Dim dtAsset As DataTable = New...
1
by: dr | last post by:
how to get the System.Drawing.Point of FormStartPosition, e.g. if i want to recenter the form on the screen at some point other then startup.
5
by: Dave Bootsma | last post by:
I have an application where I want to redraw a polygon from points I retrieve from a file. The file is read with streamreader line by line each line contains the points for each polygon. Below is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.