Please see my comment to the question: you did not specify what UI library you will use so, sorry, no exact references. You will easily find them by yourself. In short, you will need to add a event handler to an invocation list of some event of some control. It can look like that:
Control myControl =
Button myButton =
myControl.MouseDown += (sender, eventArgs) => { DoItWhenMousePressedDown(); };
myControl.MouseUp += (sender, eventArgs) => { DoItWhenMouseReleased(); };
myControl.MouseMove += (sender, eventArgs) => { DoItWhenMouseMoved(eventArgs.X, evenArgs.Y); };
myButton.Click += (sender, eventArgs) => { DoItWhenButtonClicked(); };
This way, your methods (which you can define by yourself, or you can write some other code in "{ }" blocks shown above)
DoItWhenMousePressedDown
,
DoItWhenMouseReleased
,
DoItWhenMouseMoved
or
DoItWhenButtonClicked
will be called when the user operates mouse (or keyboard, in case of
Click
in correspondent way over your control.
Note that the
Click
event is more abstract, not directly related to hardware: it will be triggered by mouse click, be Enter or spacebar key, depending on keyboard focus.
The parameter
eventArgs
will carry additional information: mouse coordinates, which mouse button clicked, etc. You will need to learn if all from the MSDN help pages on relevant events. This part is different for different .NET UI libraries (again, why didn't you tag it? it's very important; and who will waste time for explaining it for all different libraries?), but there a lot of very similar feature.
So far, this is just a cookbook recipe. This is not good enough for you unless you learn very thoroughly how events work. This is very important. You should also understand very well the delegates and anonymous methods.
—SA