943,822 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 930
  • C# RSS
May 14th, 2009
0

Mouse Event Handling Help?

Expand Post »
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 ?
Similar Threads
Reputation Points: 10
Solved Threads: 1
Light Poster
DevC++4.9.9.2 is offline Offline
39 posts
since Apr 2008
May 14th, 2009
0

Re: Mouse Event Handling Help?

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.
Last edited by ddanbe; May 14th, 2009 at 6:56 am.
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008
May 14th, 2009
0

Re: Mouse Event Handling Help?

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.
C# Syntax (Toggle Plain Text)
  1. public void OnDoubleClick(object sender, MouseEventArgs e)
  2. {
  3. string Value="";
  4. Value = Cfg.Items[Cfg.SelectedIndex].ToString();
  5. }

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

Thanks ddanbe
Last edited by DevC++4.9.9.2; May 14th, 2009 at 4:47 pm.
Reputation Points: 10
Solved Threads: 1
Light Poster
DevC++4.9.9.2 is offline Offline
39 posts
since Apr 2008
May 15th, 2009
0

Re: Mouse Event Handling Help?

My pleasure!
Reputation Points: 2035
Solved Threads: 644
Senior Poster
ddanbe is offline Offline
3,738 posts
since Oct 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Playing SWF without flash-player installed
Next Thread in C# Forum Timeline: Office Word





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC