Ralph Krausse said:
Let me make this clear, at least more clear.
I have a text box in a form.
I want to add a method that would allow me to figure out if the mouse moves
over it, ie. WM_MOUSEMOVE
I want to add a method that would tell me when the text box loses focus, ie.
WM_KILLFOCUS
And I want to add a method that tells me when the user types in code,
WM_COMMAND and EM_SELCHANGE.
Do I have just cut and paste other methods and change the code to handle
these or is there a wizard in the IDE that I can say add the WM_MOUSEMOVE
code..
Hope that is better...
Well, while you *could* handle the messages nativly, I wouldn't advise it.
Their is no wizard that performs such code insertion. For a standard .NET
form you would us code similar to:
using System;
using System.Windows.Forms;
public class MyForm : Form
{
public void override OnMouseMove(MouseMoveEventArgs e)
{
//do handling for OnMouseMove here
//this should be synonomous with WM_MOUSEMOVE
base.OnMouseMove(e);
}
public void override OnKeyPress(KeyPressEventArgs e)
{
//do handling for OnKeyPress here
//this should be synonomous with
}
}
For code that handles an event on a child control, like your text box you
have to hook up an event handler. In the IDE, on the properties dialog for
the text box, there is a lightning bolt symbol. By pressing that you will be
given a list of events, double clicking on the empty place beside the event
there will generate a handler. This does work for forms as well, but when
you are deriving from a control or a form you should override the
appropriate OnXxx method.
I hope that is clear enough, its hard to explain. Here is a basic example of
a form that hooks up to a handler for a given text box.(you'll have to set
up sizes and such if you want to actually use the code, however).
class Test : Form
{
TextBox textBox = new TextBox();
public Test()
{
this.Controls.Add(textBox);
textBox.MouseMove+=new MouseEventHandler(textBox_MouseMove);
textBox.KeyPress+=new KeyPressEventHandler(textBox_KeyPress);
}
private void textBox_MouseMove(object sender, MouseEventArgs e)
{
//Do what you want with MouseMove
}
private void textBox_KeyPress(object sender, KeyPressEventArgs e)
{
//Do what you want with KeyPress
}
}