473,406 Members | 2,352 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,406 software developers and data experts.

Form.MouseDown with non-rectangular Forms inside MDI container?

I created a non-rectangular Windows Form which opens inside of an MDI
container and I'm managing the MouseMove and MouseDown events with the
following code. The problem is that when I click on the mouse button so that
I can move the Form, the Form "jumps" about an inch to the bottom. This only
happens when the Form opens up inside an Mdi.

private Point mouse_offset;
private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
mouse_offset = new Point(-e.X, -e.Y);
}
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Point mousePos = Control.MousePosition;
mousePos.Offset(mouse_offset.X, mouse_offset.Y);
Location = mousePos;
}
}

Any help is appreciated. Thanks.
VS2005
Aug 7 '07 #1
7 1871
Doc John wrote:
I created a non-rectangular Windows Form which opens inside of an MDI
container and I'm managing the MouseMove and MouseDown events with the
following code. The problem is that when I click on the mouse button so that
I can move the Form, the Form "jumps" about an inch to the bottom. This only
happens when the Form opens up inside an Mdi.
Probably because the mouse coordinates used in the MouseDown method
aren't the same as those used in the MouseMove method.
Aug 7 '07 #2
It does. MouseDown initializes mouse_offset. And MouseMove then works with
mouse_offset.
"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13*************@corp.supernews.com...
Doc John wrote:
>I created a non-rectangular Windows Form which opens inside of an MDI
container and I'm managing the MouseMove and MouseDown events with the
following code. The problem is that when I click on the mouse button so
that I can move the Form, the Form "jumps" about an inch to the bottom.
This only happens when the Form opens up inside an Mdi.

Probably because the mouse coordinates used in the MouseDown method aren't
the same as those used in the MouseMove method.

Aug 7 '07 #3
Doc John wrote:
It does. MouseDown initializes mouse_offset. And MouseMove then works with
mouse_offset.
It does what?

What you wrote above is true. But it ignores the fact that in
MouseDown, you are using the coordinates passed to you in the event,
while in MouseMove you are using coordinates obtained from the
Control.MousePosition property. These are not necessarily the same, and
the behavior you describe pretty much proves that they aren't in your
scenario.

You should at least try changing your code based on my suggestion,
before you dismiss it.

Pete
Aug 7 '07 #4
Sorry about that.

What would you suggest? I've modified the code in as many ways as I could,
but nothing seems to work.

Thanks again.

"Peter Duniho" <Np*********@NnOwSlPiAnMk.comwrote in message
news:13************@corp.supernews.com...
Doc John wrote:
>It does. MouseDown initializes mouse_offset. And MouseMove then works
with mouse_offset.

It does what?

What you wrote above is true. But it ignores the fact that in MouseDown,
you are using the coordinates passed to you in the event, while in
MouseMove you are using coordinates obtained from the
Control.MousePosition property. These are not necessarily the same, and
the behavior you describe pretty much proves that they aren't in your
scenario.

You should at least try changing your code based on my suggestion, before
you dismiss it.

Pete

Aug 7 '07 #5
Doc John wrote:
Sorry about that.

What would you suggest? I've modified the code in as many ways as I could,
but nothing seems to work.
Have you tried anything like this?

private Point mouse_initial;
private Point form_initial;
private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
mouse_initial = e.Location;
form_initial = Location;
}
private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (e.Button == MouseButtons.Left)
{
Location = form_initial + (e.Location - mouse_initial);
}
}
Aug 7 '07 #6
Hi Doc,

I agree with Peter that the reason of your problem is that in the MouseDown
event you are using the coordinates passed in the event args, while in the
MouseMove event, you are using coordinates obtained from the
Control.MousePosition property.

You should use the coordinates passed in the MouseMove event args as well.
The following is a sample.

Point downPoint = Point.Empty;

void MainForm_MouseDown(object sender, MouseEventArgs e) {
if( e.Button != MouseButtons.Left ) return;
downPoint = new Point(e.X, e.Y);
}

void MainForm_MouseMove(object sender, MouseEventArgs e) {
if( downPoint == Point.Empty ) return;
Point location =
new Point(
this.Left + e.X - downPoint.X,
this.Top + e.Y - downPoint.Y);
this.Location = location;
}

void MainForm_MouseUp(object sender, MouseEventArgs e) {
if( e.Button != MouseButtons.Left ) return;
downPoint = Point.Empty;
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Aug 8 '07 #7
Yes. That worked.

Thanks.

"Linda Liu [MSFT]" <v-****@online.microsoft.comwrote in message
news:Q%****************@TK2MSFTNGHUB02.phx.gbl...
Hi Doc,

I agree with Peter that the reason of your problem is that in the
MouseDown
event you are using the coordinates passed in the event args, while in the
MouseMove event, you are using coordinates obtained from the
Control.MousePosition property.

You should use the coordinates passed in the MouseMove event args as well.
The following is a sample.

Point downPoint = Point.Empty;

void MainForm_MouseDown(object sender, MouseEventArgs e) {
if( e.Button != MouseButtons.Left ) return;
downPoint = new Point(e.X, e.Y);
}

void MainForm_MouseMove(object sender, MouseEventArgs e) {
if( downPoint == Point.Empty ) return;
Point location =
new Point(
this.Left + e.X - downPoint.X,
this.Top + e.Y - downPoint.Y);
this.Location = location;
}

void MainForm_MouseUp(object sender, MouseEventArgs e) {
if( e.Button != MouseButtons.Left ) return;
downPoint = Point.Empty;
}

Hope this helps.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================

This posting is provided "AS IS" with no warranties, and confers no
rights.

Aug 9 '07 #8

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

Similar topics

3
by: Deborah V. Gardner | last post by:
I have a list box and would like to point to an item and have a textbox popup referencing a column in the list box. On the list box's MouseDown event I have the following Dim strFullText ...
2
by: JJ | last post by:
Hi All, I need to create a MouseDown event for a picture box . Am I doing the following right? pictureBox.MouseDown += new System.WinForms.MouseEventHandler(pictureBox_MouseDown) Then
1
by: Jürgen Müllder | last post by:
Hi! I have a TreeView in my Application. I have the MouseDown Attached to the TreeView. When i click at a Node it makes that what it should. But when i Expand a Node by clicking at the Plus Sign...
4
by: rsmith | last post by:
How can I capture the MouseDown event on a Label ? I entered thr following code and got a " cannot handle Event 'MouseDown' because they do not have the same signature." Private Sub...
2
by: active | last post by:
In VB6 I believe MouseDown had a Shift argument that told if Shift, Ctrl or Alt was pressed. How in VB.NET MouseDown do I determine if one of these keys is pressed? I could increment a global...
4
by: active | last post by:
I can use Control.ModifierKeys to determine if a modifying key is pressed when executing MouseDown event, but how can I determine if an "M" was pressed?? Possible? Can't find a clue in...
4
by: Tomasz Bak | last post by:
Hello, I have a simple problem: mark a list of defects on an image. I think the best way to do it is to select a single deffect, then take two coordinates of coursor form an image on a web...
2
by: Stewart | last post by:
2 questions 1. How do i set the whole form's opacity prop? Right now i have to set an event handler for each element on the form. Is there are better way to do this? 2. how do i make a form...
0
by: hmm | last post by:
Hi all I have two problems: Problem #1: I'm using a .NET Form with the property 'FormBorderStyle' set to 'None'. The idea is to completely cover the area of that Form with a UserControl. In...
1
by: JDeats | last post by:
It appears the WinForm MouseDown and MouseUp event handlers are not working properly. In the "bare bones" sample application below, Form1_MouseUp gets called even through the mouse button remains...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: 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
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,...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.