How to move a button from an array of buttons by mouse? C# -
I'm really new to c # coding I got an array of buttons and I left clicking the mouse I want to move the button. any advice?
Private Zero CreateTable (Button [Tabla]) {int horizotal = 45; Int vertical = 45; For (int i = 0; i & lt; tab; album; i ++) {tab [i] = new button (); Tabla [i]. Back Collar = Color Ezur; Tabla [ii] Size = new size (45, 45); Tabla [i]. Place = new point (horizontal, vertical); If ((i == 14) || (i == 29) || (I == 44) || (I == 59) || (I == 74) || (I == 89) || (I == 104) || (I == 119) || I == 134 || I == 14 9 || I == 164 || I == 17 9 || I ==194 || I == 20 9) {vertical = 45; Horizon = horizon + 45; } And vertical = vertical + 45; This.Controls.Add (Tabla [i]); }} This is the code that creates my buttons.
First of all, if you add your button to mouseeventhandler, then you declare mouseeventshandler in this way. Private Zero CreateTable (Button [Tabla]) {int horizotal = 45; Int vertical = 45; For (int i = 0; i & lt; tab; album; i ++) {tab [i] = new button (); Tabla [i]. Back Collar = Color Ezur; Tabla [ii] Size = new size (45, 45); Tabla [i]. Place = new point (horizontal, vertical); If ((i == 14) || (i == 29) || (I == 44) || (I == 59) || (I == 74) || (I == 89) || (I == 104) || (I == 119) || I == 134 || I == 14 9 || I == 164 || I == 17 9 || I ==194 || I == 20 9) {vertical = 45; Horizon = horizon + 45; } And vertical = vertical + 45; Tabla [i] MouseDown + = new mouseover handler (button_down); // Handler tab below [i]. MouseShow + = new mouseover handler (button_mov); Add // Add Handler. Control. Add (Tab [i]); }} Private Wide Button _Down (Object Sender, Mouse Event ARGS E) {if (E. Button == Mousebutton Left) {start.X = E. Location.x; Start Y = E place. why; }} Private Zero Button _move (Object Sender, Mouse Event Argus E) {if (e.button == MouseButtons.Left) {((Button) Sender). Left + = E place. X - Start. X; (Button) sender). Top + = E. place. Y - Getting Started Y; }} The sender is a handler's collar and we know that this is a button. So we can use it this way. ± It seems that this code is perfect for you, but your problem is using the button for the letter. You can use PictureBox for the letter and they can come more properly than the buttons. Finally I think you should declare your button array.
Comments
Post a Comment