4 Replies - 610 Views - Last Post: 30 June 2009 - 11:40 PM Rate Topic: -----

#1 L1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 21-June 09

Assigning multiple activators to one control

Post icon  Posted 30 June 2009 - 10:06 PM

I want to assign multiple activators to one control button, say, I want a label to add one every time I click one it with the left mouse button and minus one every time I click one it with the right mouse button.

Any help would be appreciated
Is This A Good Question/Topic? 0
  • +

Replies To: Assigning multiple activators to one control

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1638
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Assigning multiple activators to one control

Posted 30 June 2009 - 10:09 PM

Dream.In.Code has a policy by which we prefer to see a good faith effort on your part before providing source code for homework assignments. Please post the code you have written in an effort to resolve the problem, and our members would be happy to provide some guidance. Be sure to include a description of any errors you are encountering as well.

Post your code like this: :code:

Thanks.
Was This Post Helpful? 0
  • +
  • -

#3 L1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 21-June 09

Re: Assigning multiple activators to one control

Posted 30 June 2009 - 11:06 PM

 private void lblpcolor1_Click(object sender, EventArgs e)
		{


			if (intClick1 == 10)
			{
				intClick1 = 1;
			}
			else
			{
				intClick1++;
			}


			switch (intClick1)
			{


				case 1:
					lblpcolor1.BackColor = Color.Red;
					break;
				case 2:
					lblpcolor1.BackColor = Color.Orange;
					break;
				case 3:
					lblpcolor1.BackColor = Color.Yellow;
					break;
				case 4:
					lblpcolor1.BackColor = Color.Green;
					break;
				case 5:
					lblpcolor1.BackColor = Color.Cyan;
					break;
				case 6:
					lblpcolor1.BackColor = Color.Blue;
					break;
				case 7:
					lblpcolor1.BackColor = Color.Purple;
					break;
				case 8:
					lblpcolor1.BackColor = Color.Black;
					break;
				case 9:
					lblpcolor1.BackColor = Color.White;
					break;
				case 10:
					lblpcolor1.BackColor = Color.Gray;
					break;

			}



As in this case, this is set by default that the label I have assigned will change color every time I click on it with my left mouse button, it can loop between the 10 colors but can't go backwards if I happen to click an extra time, what I want to do is to assign the right click button of the mouse to it so that it'll go backwards when I click on the label with my right mouse button
Was This Post Helpful? 0
  • +
  • -

#4 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 429
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Assigning multiple activators to one control

Posted 30 June 2009 - 11:25 PM

This is how I would do it:

		int color = 1;

		private void lblpcolor1_Click(object sender, EventArgs e)
		{
			// Convert event to MouseEventArgs so we can find out which mousebutton was clicked
			MouseEventArgs me = (MouseEventArgs)e;

			if (me.Button == MouseButtons.Left)
				color++;
			else if (me.Button == MouseButtons.Right)
				color--;
			

			if (color > 10)
				color = 1;
			else if (color < 1)
				color = 10;

			ChangeLabelColor(lblpcolor1);
		}

		private void ChangeLabelColor(Label lbl)
		{
			switch (color)
			{
				case 1:
					lbl.BackColor = Color.Red;
					break;
				case 2:
					lbl.BackColor = Color.Orange;
					break;
				case 3:
					lbl.BackColor = Color.Yellow;
					break;
				case 4:
					lbl.BackColor = Color.Green;
					break;
				case 5:
					lbl.BackColor = Color.Cyan;
					break;
				case 6:
					lbl.BackColor = Color.Blue;
					break;
				case 7:
					lbl.BackColor = Color.Purple;
					break;
				case 8:
					lbl.BackColor = Color.Black;
					break;
				case 9:
					lbl.BackColor = Color.White;
					break;
				case 10:
					lbl.BackColor = Color.Gray;
					break;

			}
		}



I hope this helps you. Also don't hesitate to ask if there is anything confusing in my solution.
Was This Post Helpful? 0
  • +
  • -

#5 L1989  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 26
  • Joined: 21-June 09

Re: Assigning multiple activators to one control

Posted 30 June 2009 - 11:40 PM

View Postjanne_panne, on 30 Jun, 2009 - 10:25 PM, said:

This is how I would do it:

		int color = 1;

		private void lblpcolor1_Click(object sender, EventArgs e)
		{
			// Convert event to MouseEventArgs so we can find out which mousebutton was clicked
			MouseEventArgs me = (MouseEventArgs)e;

			if (me.Button == MouseButtons.Left)
				color++;
			else if (me.Button == MouseButtons.Right)
				color--;
			

			if (color > 10)
				color = 1;
			else if (color < 1)
				color = 10;

			ChangeLabelColor(lblpcolor1);
		}

		private void ChangeLabelColor(Label lbl)
		{
			switch (color)
			{
				case 1:
					lbl.BackColor = Color.Red;
					break;
				case 2:
					lbl.BackColor = Color.Orange;
					break;
				case 3:
					lbl.BackColor = Color.Yellow;
					break;
				case 4:
					lbl.BackColor = Color.Green;
					break;
				case 5:
					lbl.BackColor = Color.Cyan;
					break;
				case 6:
					lbl.BackColor = Color.Blue;
					break;
				case 7:
					lbl.BackColor = Color.Purple;
					break;
				case 8:
					lbl.BackColor = Color.Black;
					break;
				case 9:
					lbl.BackColor = Color.White;
					break;
				case 10:
					lbl.BackColor = Color.Gray;
					break;

			}
		}



I hope this helps you. Also don't hesitate to ask if there is anything confusing in my solution.




I've changed a bit to apply to my code, thanks a lot for the help.

Also I would like to ask if I use this "private void ChangeLabelColor(Label lbl)" can I apply it to other labels with the same function?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1