TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
ali
NA
14
0
problem in executing this code
Apr 30 2010 4:53 PM
Handling events in C# is little bit tricky than in C++ or VB. In C#, you write a delegate and then write an event handler. These event handlers are overridable public events defined in the Control or other WinForms classes.
1. Write a Delegate
I want to handle Mouse Down events and do something when left or right mouse buttons are pressed. Write this line of code in your InitializeComponent function.
this.MouseDown += new System.WinForms.MouseEventHandler(this.Form_MouseDown);
2. Write the Event
Now you write the event handle. The output parameter of your event returns System.WinForms.MouseEventArgs object which gives you the details about mouse down such as what button is pressed or how many times. Here are MouseEventArgs members.
MouseEventArgs members
Button Indicates which mouse button was pressed. It could be Left, Right, Middle, or None.
Clicks Indicates the number of times the mouse button was pressed and released.
Delta Indicates a signed count of the number of detents the mouse wheel has rotated.
X The x-coordinate of mouse click.
Y The y-coordinate of mouse click.
Event Handler
private void Form_MouseDown(object sender, System.WinForms.MouseEventArgs e)
{
switch (e.Button)
{
case MouseButtons.Left:
MessageBox.Show(this,"Left Button Click");
break;
case MouseButtons.Right:
MessageBox.Show(this,"Right Button Click" );
break;
case MouseButtons.Middle:
break;
default:
break;
}
}
THIS OCCURED
The type or namespace name 'WinForms' does not exist in the namespace 'System' (are you missing an assembly reference?)
WHT SHOULD I DO iT URGENT PLZ HELP
Reply
Answers (
6
)
Chek Format from textbox
How correct the page alignment?