如何通过单击其中的“运行时"按钮来关注运行时面板. [英] how can get focus on runtime panel by clicking runtime button inside it.
本文介绍了如何通过单击其中的“运行时"按钮来关注运行时面板.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我上面有2个运行时面板和运行时按钮.当我单击第一个面板并想在其上移动运行时按钮时,它可以工作,但是当我单击第二个运行时面板的按钮而不选择它时,它不起作用.了解如何通过单击运行时面板上的按钮来集中精力于运行时面板.
请帮帮我.
在此先感谢.
Hi All,
I have 2 runtime panel and runtime buttons on it.When i click on first panel and want to move runtime button on it,its working but when i click on the button of 2nd runtime panel without selecting it,its not working.So i want to know how can get focus on runtime panel by clicking runtime button on it.
Please help me.
Thanks in Advance.
推荐答案
int num1 = Form.ActiveForm.Location.X + pnlDrawingArea.Location.X + 30;
int num2 = Form.ActiveForm.Location.Y + pnlDrawingArea.Location.Y + 40;
//Create Rectangle Box
if (drawRect == "Yes")
{
if (i > -1)
{
p1 = new Panel();
p1.Name = "Rect" + i.ToString();
p1.AllowDrop = true;
p1.Location = new Point(MousePosition.X - num1, MousePosition.Y - num2);
p1.BackColor = Color.Red;
p1.Click += new EventHandler(p1_Click);
p1.MouseDown += new MouseEventHandler(p1_MouseDown);
p1.MouseMove += new MouseEventHandler(p1_MouseMove);
p1.MouseUp += new MouseEventHandler(p1_MouseUp);
p1.DragEnter += new DragEventHandler(p1_DragEnter);
p1.DragDrop += new DragEventHandler(p1_DragDrop);
p1.GotFocus += new EventHandler(p1_GotFocus);
p1.LostFocus += new EventHandler(p1_LostFocus);
this.pnlDrawingArea.Controls.Add(p1);
if (p1.CanFocus)
{
p1.Focus();
}
i++;
}
drawRect = "No";
}
void p1_DragDrop(object sender, DragEventArgs e)
{
p1 = (Panel)sender;
if (flag == "Yes")
{
int num1 = Form.ActiveForm.Location.X + pnlDrawingArea.Location.X + p1.Location.X;
int num2 = Form.ActiveForm.Location.Y + pnlDrawingArea.Location.Y + p1.Location.Y + 40;
pnlTblNo = new Button();
pnlTblNo.Name = "RectTbl" + i.ToString();
pnlTblNo.AllowDrop = true;
pnlTblNo.Text = e.Data.GetData(DataFormats.Text).ToString();
pnlTblNo.Height = 28;
pnlTblNo.Width = 30;
pnlTblNo.BackColor = Color.SeaShell;
//pnlTblNo.Click += new EventHandler(pnlTblNo_Click);
pnlTblNo.MouseDown += new MouseEventHandler(pnlTblNo_MouseDown);
pnlTblNo.MouseUp += new MouseEventHandler(pnlTblNo_MouseUp);
pnlTblNo.MouseMove += new MouseEventHandler(pnlTblNo_MouseMove);
pnlTblNo.LostFocus += new EventHandler(pnlTblNo_LostFocus);
pnlTblNo.Anchor = (AnchorStyles.Left | AnchorStyles.Top);
pnlTblNo.Location = new Point(MousePosition.X - num1, MousePosition.Y - num2);
this.p1.Controls.Add(pnlTblNo);
flag = "No";
}
if (p1.CanFocus)
{
p1.Focus();
}
}
void pnlTblNo_MouseMove(object sender, MouseEventArgs e)
{
if (Dragging)
{
num1 = Form.ActiveForm.Location.X + pnlDrawingArea.Location.X + p1.Location.X+10;
num2 = Form.ActiveForm.Location.Y + pnlDrawingArea.Location.Y + p1.Location.Y+30;
num3 = Form.ActiveForm.Location.X + pnlDrawingArea.Location.X + p1.Location.X + 10 + p1.Width;
num4 = Form.ActiveForm.Location.Y + pnlDrawingArea.Location.Y + p1.Location.Y + 30+p1.Height;
if(MousePosition.X>num3||MousePosition.Y>num4)
{
MessageBox.Show("Please Select panel");
}
else
{
pnlTblNo.Location = new Point(MousePosition.X - num1, MousePosition.Y - num2);
}
}
}
这篇关于如何通过单击其中的“运行时"按钮来关注运行时面板.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文