c# - Getting buttons to change background color when left mouse button is down and you hover over them -


I have a grid of buttons, to change the color of the color when rotation is clicked through 3 colors

  Private Zero Button 11 9_MouseClick (Object Sender, MouseEventArgs E) {Control ctrl = ((sender)); Switch (ctrl.BackColor.Name) {case "Aquamarine": ctrl.BackColor = Color.Yellow; break; Case "Yellow": ctrl.BackColor = Color.CornflowerBlue; break; Case "Cornflower Blue": ctrl.BackColor = Color.Gainsboro; break; Default: ctrl.BackColor = Color.Aquamarine; break; }   

I need them that when I left the mouse click and rotated them, then I did the same. Thanks for any help.

Use mouseHover events and controls. Musburutan Stable property I will do something like this:

  Private Zero button 11 9_MouseClick (Object Sender, MouseEventArgs E) {ChangeColor (as the sender's control); } Private Zero Button 11 9_MouseHover (Object Sender, EventArgs E) {If (Control.MouseButtons == System.Windows.Forms.MouseButtons.Left) {ChangeColor (Sender as Control); }} Private Zero ChangeColor (control ctrl) {switch (ctrl.BackColor.Name) {case "Aquamarine": ctrl.BackColor = Color.Yellow; break; Case "Yellow": ctrl.BackColor = Color.CornflowerBlue; break; Case "Cornflower Blue": ctrl.BackColor = Color.Gainsboro; break; Default: ctrl.BackColor = Color.Aquamarine; break; }}    

Comments

Popular posts from this blog

python - Writing Greek in matplotlib labels, titles -

c# - LINQ to Entities does not recognize the method 'Int32 IndexOf(System.String, System.StringComparison)' method -

Pygame memory leak with transform.flip -