954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Mouse Event Handling Help?

I am trying to work with listbox in visual stuido 2008. I am new to c# as of 2 days ago however im very experienced with c++ and batch. I was wondering if someone could give me some quick help on how to use mouse clicks.

In particular i have a form with a listbox and its populated with lots of strings. When the user clicks on one of those strings i would like to process data based on that string.

For example:
--------
| str |
| str2 |
---------

Double click str.

MessageBox.Show(str);

Ive been searching for hours and all i seem to know is that
people like to use e as a variable for EventArgs. and that you might have to use
this.MouseDoubleClick += new MouseEventHandler(Something);

im lost lol
any help ?

DevC++4.9.9.2
Light Poster
39 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

In design mode select your listbox. Go to the properties window(usually low right). Select events(click on the lightning bolt icon.
Scroll to MouseDoubleClick and fill in a name you like (e.g. MyMouseDblClick) Press enter and see what happens. Continue from there.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

Thanks, i didnt know it was that simple :)
After making that function i was able to get the mouse click to do something. And then i came to this conclusion:
If Cfg is the name of my listbox.

public void OnDoubleClick(object sender, MouseEventArgs e)
        {
            string Value="";
            Value = Cfg.Items[Cfg.SelectedIndex].ToString();
        }

With that on click you get the name of what was clicked stored in value. Finally lol.

Thanks ddanbe

DevC++4.9.9.2
Light Poster
39 posts since Apr 2008
Reputation Points: 10
Solved Threads: 1
 

My pleasure!

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You