R
RobW
I am a newbie to the wonders of C# programmming and I would be
grateful if someone could help me! I would like to create a class that
will change the properties of a label or text control (such as back
color) during a mouse over event. I would like the class to be generic
so that it may be used in other projects. I looked at an example from
VS help and........ it doesn't work. The class does not seem to be
able to reference the control.
public class myMouseEventClass
{
protected Label label1;
// Function signatures must match the signature of the
// MouseEventHandler class.
public void myMouseDown(object sender, MouseEventArgs ex)
{
if (ex.Button == MouseButtons.Left)
{
// Insert code to execute when a mouse down event is
// received, and the left button is clicked.
}
}
// A method that shows you where you are in the control
// that is receiving the event.
public void myWhereAreWe(object sender, MouseEventArgs ex)
{
label1.Text = "Mouse is at X: " + ex.X + " Y: " + ex.Y ;
}
}
[Visual Basic, C#] You must create an instance of this class. You must
also
set the event handlers; you can do this in your constructor.
[C#]
myMouseEventClass myEvents = new myMouseEventClass() ;
public Form1()
{
InitializeComponent();
textBox1.MouseDown += new
MouseEventHandler(myEvents.myMouseDown);
textBox1.MouseMove += new
MouseEventHandler(myEvents.myWhereAreWe);
}
When one of the specified events is raised in the control, the
attached
method is called and the application can execute code in response to
the
event.
Can anyone help with this as this is confusing the hell out of me?
Thanks in advance
grateful if someone could help me! I would like to create a class that
will change the properties of a label or text control (such as back
color) during a mouse over event. I would like the class to be generic
so that it may be used in other projects. I looked at an example from
VS help and........ it doesn't work. The class does not seem to be
able to reference the control.
public class myMouseEventClass
{
protected Label label1;
// Function signatures must match the signature of the
// MouseEventHandler class.
public void myMouseDown(object sender, MouseEventArgs ex)
{
if (ex.Button == MouseButtons.Left)
{
// Insert code to execute when a mouse down event is
// received, and the left button is clicked.
}
}
// A method that shows you where you are in the control
// that is receiving the event.
public void myWhereAreWe(object sender, MouseEventArgs ex)
{
label1.Text = "Mouse is at X: " + ex.X + " Y: " + ex.Y ;
}
}
[Visual Basic, C#] You must create an instance of this class. You must
also
set the event handlers; you can do this in your constructor.
[C#]
myMouseEventClass myEvents = new myMouseEventClass() ;
public Form1()
{
InitializeComponent();
textBox1.MouseDown += new
MouseEventHandler(myEvents.myMouseDown);
textBox1.MouseMove += new
MouseEventHandler(myEvents.myWhereAreWe);
}
When one of the specified events is raised in the control, the
attached
method is called and the application can execute code in response to
the
event.
Can anyone help with this as this is confusing the hell out of me?
Thanks in advance