2
時比較的WinForms控制倉位我有一個包含名爲button1
一個按鈕,並呼籲panel1
具有色綠一個面板的小程序。到目前爲止,該計劃允許你拖button1
周圍的形式。我想擴大這個項目,所以當button1
的面板面板的顏色變爲紅色下降。拖動
形式:
至今代碼:
System.Drawing.Point OldPosition;
public Form1()
{
InitializeComponent();
}
private void button1_MouseDown(object sender, MouseEventArgs e)
{
//Only prepare if the button click down is the left button
if (e.Button == MouseButtons.Left)
{
//Store the current mouse location
OldPosition = e.Location;
//Change the mouse cursor if you want
button1.Cursor = Cursors.Hand;
}
}
private void button1_MouseMove(object sender, MouseEventArgs e)
{
//Only move if the left button still down
if (e.Button == MouseButtons.Left)
{
button1.Location = new Point(button1.Location.X + (e.X - OldPosition.X), button1.Location.Y + (e.Y - OldPosition.Y));
}
}
private void Form1_Load(object sender, EventArgs e)
{
panel1.BackColor = Color.Green;
}
private void panel1_MouseEnter(object sender, EventArgs e)
{
if (button1.Location == panel1.Location)
panel1.BackColor = Color.Red; //im not sure how to do this part
}
感謝隊友。我已經把面板寄回去了 – Tacit