private void ShakeButton(MyButton btn) { int rand = 10; int frmx = btn.Left; int frmy = btn.Top; Random random = new Random(); for (int i = 0; i < 1000; i += 5) { int x = random.Next(rand); int y = random.Next(rand); if (x % 2 == 0) { btn.Left = btn.Left + x; } else { btn.Left = btn.Left - x; } if (y % 2 == 0) { btn.Top = btn.Top + y; } else { btn.Top = btn.Top - y; } btn.Left = frmx; btn.Top = frmy; } }
private void MyInitializeComponent(int number) { if (btnSlot!=null) { if(btnSlot.Length!=0) for (int i = 0; i < btnSlot.Length; i++) { this.groupBox2.Controls.Remove(btnSlot[i, 0]); btnSlot[i,0].Dispose(); } } this.groupBox2.Refresh(); btnSlot = new MyButton[number, 1]; char c = 'A'; float[] scale = (float[])Tag; Size size = new Size(width, height); for (int i = 0; i < number; i++) { char cname = (char)(c + i); string name = System.Convert.ToString(cname); btnSlot[i, 0] = new MyButton(); this.groupBox2.Controls.Add(btnSlot[i, 0]); btnSlot[i, 0].AllowDrop = true; btnSlot[i, 0].BackColor = System.Drawing.Color.Transparent; btnSlot[i, 0].BackgroundImage = new Bitmap(Application.StartupPath + "\\image\\button\\" + xmlViewData[i]["button"].ToString()); btnSlot[i, 0].FlatAppearance.BorderColor = System.Drawing.Color.White; btnSlot[i, 0].FlatAppearance.MouseDownBackColor = System.Drawing.Color.Transparent; btnSlot[i, 0].FlatAppearance.MouseOverBackColor = System.Drawing.Color.Transparent; btnSlot[i, 0].FlatStyle = System.Windows.Forms.FlatStyle.Flat; btnSlot[i, 0].Location = new System.Drawing.Point(680, 100 + i * (height + 20)); btnSlot[i, 0].Name = name; btnSlot[i, 0].Padding = new System.Windows.Forms.Padding(0, 10, 0, 0); btnSlot[i, 0].Tag = 100 + i * (height + 20); btnSlot[i, 0].Size = size; btnSlot[i, 0].AllowDrop = true; btnSlot[i, 0].BackgroundImageLayout = ImageLayout.Stretch; btnSlot[i, 0].MouseDown += new MouseEventHandler(OnMouseDown); btnSlot[i, 0].MouseUp += new MouseEventHandler(OnMouseUp); if (btnSlot[i, 0].Top + 45 > groupBox2.Top + groupBox2.Height) { btnSlot[i, 0].Visible = false; } } time.Visible = false; score.Visible = false; }