右键单击面板不起作用
本文关键字:不起作用 单击 右键 | 更新日期: 2023-09-27 18:24:49
private void panel1_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right)
{
ColorDialog cd = new ColorDialog();
if (cd.ShowDialog() == DialogResult.OK)
{
this.panel3.BackColor = cd.Color;
}
}
}
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
Panel pnl = sender as Panel;
if (pnl != null)
pnl.DoDragDrop(pnl.BackColor, DragDropEffects.Move);
}
private void panel2_DragDrop(object sender, DragEventArgs e)
{
var data = e.Data.GetData(typeof(Color));
if (data != null)
((Panel)sender).BackColor = (Color)data;
}
private void panel2_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Move;
}
我希望如果我按右键 panel1,它应该显示颜色选择的颜色对话框,然后我可以将 panel1 颜色拖放到 panel2 上。但是在此代码之后,Colpetion终于拖放工作但不起作用面板1右键单击帮帮我?
在鼠标中右键单击首先调用mouse down
事件,因此它不会调用mouse click
事件,因此您在鼠标按下事件中尝试了此操作
private void panel1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button !=MouseButtons.Right)
{
Panel pnl = sender as Panel;
if (pnl != null)
pnl.DoDragDrop(pnl.BackColor, DragDropEffects.Move);
}
}