By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,930 Members | 1,269 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,930 IT Pros & Developers. It's quick & easy.

new Point(-e.X, -e.Y); can someone tell me what the e's do / mean?

P: n/a
I understand that Point is an object used for storing co-ordinates,
such as mouse location.

I can't figure out what the e's do in the above example can someone
explain please.

Thanks,

Gary.

Mar 20 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Also please can someone explain the following.

Im looking at a basic custom mouse handler for a form (im using a non
standard form shape so using microsofts suggested code for handling
form movement.) As far as i can see the form movement code consists of
two methods: one's a mousedown event, and one's a mousemove event. This
is the code: -

(some of the comments i've added myself and some were already included,
so some comments - the ones ive added, might not be right, i've made
them to assist me understand what's going on.)

My question is this. The form works fine, when the left button is
clicked on the form, and the form is dragged it moves fine. I can'f
figure out how the form knows the mouse button has been depressed - how
does the program know to stop moving the form? Also as I read the
mousemove event, it will move the form only once, there's not loop or
anything like that, so how does it manage to move the form fluidly?

Any help would be greatly appreciated

/// <summary>
/// When the mouse is clicked on the label (which
/// fills the entire form), the coordinates are
/// captured to use as offsets to move the form
/// as the mouse is moved.
///
/// Addition information on moving nonstandard form:
///
http://msdn.microsoft.com/library/de...lStudioNET.asp
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void trickForm_MouseDown(object sender, MouseEventArgs
e)
{
mouseOffset = new Point(-e.X, -e.Y);
}

/// <summary>
/// Responds to the mouse moving, as long as the
/// left mouse button is also down. For each
/// movement, the form is moved correspondingly.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void trickForm_MouseMove(object sender, MouseEventArgs
e)
{
// only execute the block of code if the left mouse button
was pressed.
if (e.Button == MouseButtons.Left)
{
// create a new point object, set this object equal to
the current mouse x, y co-ordinates.
Point mousePos = Control.MousePosition;

// Offset = a method belonging to the point class.
// Offset( int dx, int dy) - dx = x translation, dy = y
translation

mousePos.Offset(mouseOffset.X, mouseOffset.Y);
// If the Control is a Form, the Location property
value represents
// the upper-left corner of the Form in screen
coordinates.

this.Location = mousePos;
}
}

Mar 20 '06 #2

P: n/a

ga********@myway.com wrote:
I understand that Point is an object used for storing co-ordinates,
such as mouse location.

I can't figure out what the e's do in the above example can someone
explain please.


I can't see any example. If you 'attached' a code file, not everyone
will be able to see it; you should paste code you want people to see
into your post.

Typically, e will be the name given by autogenerated code, and in
documentation, to a parameter (of some type derived from EventArgs) of
an event handler procedure. For example, the documentation for a
MouseDown event handler reads:

public delegate void MouseEventHandler(
object sender,
MouseEventArgs e
);

By looking at the definition of MouseEventHandler and MouseEventArgs,
we see that here, e.X and e.Y would refer to the x and y coordinates of
the mouse.

It should be obvious from the original source of your code snippet what
the e in question is.

--
Larry Lard
Replies to group please

Mar 20 '06 #3

P: n/a
thanks for your reply Larry, the example was the small one line
statement i included in the subject, thanks for clarifying this for me!

Mar 20 '06 #4

P: n/a
On 20 Mar 2006 02:54:27 -0800, ga********@myway.com wrote:
My question is this. The form works fine, when the left button is
clicked on the form, and the form is dragged it moves fine. I can'f
figure out how the form knows the mouse button has been depressed - how
does the program know to stop moving the form? Also as I read the
mousemove event, it will move the form only once, there's not loop or
anything like that, so how does it manage to move the form fluidly?


The MouseDown event is raised when the user clicks the mouse button. When
this happens, the code that you've placed in the event handler for the
MouseDown event is being executed. When the user moves the mouse, the
MouseMove event is raised. When this happens, the code that you've placed
in the event handler for the MouseMove event is being executed. This
MouseMove event is raised over and over again while the user is moving the
mouse hence allowing your form to move smoothly as the user moves the
mouse. When the user stops moving the mouse, the MouseMove event is not
raised anymore. When the user releases the mouse button, the MouseUp event
is raised.
Mar 20 '06 #5

P: n/a

ga********@myway.com wrote:
Also please can someone explain the following.

Im looking at a basic custom mouse handler for a form (im using a non
standard form shape so using microsofts suggested code for handling
form movement.) As far as i can see the form movement code consists of
two methods: one's a mousedown event, and one's a mousemove event. This
is the code: -

(some of the comments i've added myself and some were already included,
so some comments - the ones ive added, might not be right, i've made
them to assist me understand what's going on.)

My question is this. The form works fine, when the left button is
clicked on the form, and the form is dragged it moves fine. I can'f
figure out how the form knows the mouse button has been depressed - how
does the program know to stop moving the form?
The MouseEventArgs e passed to the MouseMove event handler includes a
Button member, which describes the *current* state of the mouse
buttons. The form is only moved if the button is down.

Also as I read the
mousemove event, it will move the form only once, there's not loop or
anything like that, so how does it manage to move the form fluidly?


The Form receives a MouseMove event _every time_ the mouse moves - so
as the user moves the mouse around, the Form will receive dozens of
MouseMove events per second - and in response to each one, the form is
moved.

--
Larry Lard
Replies to group please

Mar 20 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.