Classwizard in C# like in VC++

  • Thread starter Thread starter Ralph Krausse
  • Start date Start date
R

Ralph Krausse

Hello all,

New to .NET and was wondering if there is a classwizard to create
code for message like VC++ has now, ie. automatically create code for
KeyDown or MouseMove.

Thanks
Ralph
 
I'm not to familiar with VC++'s wizards, but things like KeyDown and
MouseMove aren't handled via messages(usually) in .NET, you would override
the appropriate OnXxx method(OnKeyDown and OnMouseMove respectivly) on your
form\control instead. Is that what you mean?
 
If I wanted to add a mouse move event handler, do I just type in all the
code or is there a wizard that I can tell to add the template code to my
code?
 
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...

thanks
Ralph Krausse
 
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
}
}
 
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

Think out of the box.

Right click on the textbox and open properties
Click on the events view (lightning bolt)
double-click on MouseMove event.
done.

bullshark
 
Back
Top