我正在创建动态标签,并让用户通过发送unicode来更改像backcolor等实验室的属性。但是,我不知道如何检查标签是否存在,因此我无法操作动态创建的标签。以下是我的代码:WinForms动态标签
if ((InputBox.Text.StartsWith("π")) && (InputBox.Text.EndsWith("}")))// only process if the message starts with π and ends with }
{
string Message = InputBox.Text;
InputBox.Text = "";// Clear the box when done.
// Butt1 message line
if (Message.StartsWith("πlabelt1"))
{
if (Message.StartsWith("πlabelt1_BackColor"))
{
Message = Message.Substring(19);
//labelt1.BackColor = System.Drawing.Color.FromName(Message.Replace("}", ""));
}
}
private void ImageBox_DragDrop(object sender, DragEventArgs e)
{
//Graphics g = ImageBox.CreateGraphics();
//g.DrawImage((Image)e.Data.GetData(DataFormats.Bitmap),
//new Point(e.X - this.Left, e.Y - this.Top - 150));
Point p2 = PointToClient(Cursor.Position);
Label buttlbl_ = new Label();
labelCount++;
buttlbl_.Name = "labelt" + labelCount.ToString();
buttlbl_.Location = new Point(p2.X, p2.Y);
buttlbl_.Size = new System.Drawing.Size(37, 37);
buttlbl_.BackColor = System.Drawing.Color.DarkGray;
this.Controls.Add(buttlbl_);
buttlbl_.BringToFront();
ImageBox.Invalidate();
}
}
有什么建议吗?