473,763 Members | 1,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ToStri ng)

If Me.Location.X + Me.Width >
System.Windows. Forms.Screen.Pr imaryScreen.Bou nds.Width Then
Debug.WriteLine ("Too far right")
Me.Location = New
System.Drawing. Point(System.Wi ndows.Forms.Scr een.PrimaryScre en.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.Locati on.X, 0)
Debug.WriteLine (Me.Location.X & " " & Me.Location.Y)
End If

End If
MyBase.WndProc( m)
Catch ex As System.Argument Exception
MsgBox(ex.ToStr ing)
Catch ex As Exception
MsgBox(ex.ToStr ing)
End Try
End Sub
Nov 6 '06 #1
1 9455
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.ToStri ng)

If Me.Location.X + Me.Width >
System.Windows. Forms.Screen.Pr imaryScreen.Bou nds.Width Then
Debug.WriteLine ("Too far right")
Me.Location = New
System.Drawing. Point(System.Wi ndows.Forms.Scr een.PrimaryScre en.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.Locati on.X, 0)
Debug.WriteLine (Me.Location.X & " " & Me.Location.Y)
End If

End If
MyBase.WndProc( m)
Catch ex As System.Argument Exception
MsgBox(ex.ToStr ing)
Catch ex As Exception
MsgBox(ex.ToStr ing)
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
1663
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 another graph with different data populated in that graph. I want to know how to provide href for each bar in the graph in the code behind.
1
9577
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 object for which there is only two constructors System.Drawing.Graphics.FromHdc
1
469
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, MouseEventArgs e) { if (e.Button == MouseButtons.Left && video.Fullscreen != true) {
0
1856
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 andhas a large blue area on a particular side, which gets largerevery time the image is flipped again. I'm assuming that this may be due to a lack of time assigned tothe procedure before saving the image, but I'm not sure how Ican recitify this. I...
0
2462
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
2881
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 Arial. Is there something I should know? Is there only a specific set of fonts that can be used with the Font class?
5
4368
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 DataTable("asset") 3 Dim dcPk(0) As DataColumn 4 dcPk(0) = _ 5 dtAsset.Columns.Add("fullName", Type.GetType("System.String")) 6 dtAsset.Columns.Add("videoLocation", Type.GetType("System.Drawing.Point"))
1
1205
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
3585
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 a typical line from my file. 500,748 500,678 552,678 552,696 584,696 584,714 612,714 612,748 Each set of x,y coordinates is separated by a space. How can I read this into my points collection. If I currently try I get
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9383
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10140
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9819
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8821
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6642
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5268
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3519
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.