首页 > 代码库 > 控件移动

控件移动

功能:点击按钮,按钮的位置进行移动。

添加2个按钮:change,changeBack。

 1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 10 namespace changeLocation11 {12     public partial class changeLocation : Form13     {14         public int X1 = 200;15         public int Y1 = 10;16         public int X2 = 200;17         public int Y2 = 110;18         public changeLocation()19         {20             InitializeComponent();21         }22         //换位按钮单击事件23         private void change_Click(object sender, EventArgs e)24         {25             change.Left = X1; change.Top = Y1;26             changeBack.Left = X1+100; changeBack.Top = Y1;27         }28         //反换位按钮单击事件29         private void changeBack_Click(object sender, EventArgs e)30         {31             change.Left = X1; change.Top = Y1;32             changeBack.Left = X2; changeBack.Top = Y2;33         }34         //窗体装载事件35         private void changeLocation_Load(object sender, EventArgs e)36         {37             change.Left = X1; change.Top = Y1;38             changeBack.Left = X2; changeBack.Top = Y2;39         }40     }41 }

这是个很简单的程序,想了解代码控制控件移动的新手们可以拿来练练手。

控件移动