2010-06-03 93 views
2

我正在创建动态标签,并让用户通过发送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(); 
    } 
} 

有什么建议吗?

回答

0
  • 你可以通过设置buttlbl_作为一个类的成员,因此您可以检查是否建立之前,形成
  • 它,你可以在this.Controls收集发现它(通过ID)
0

我想你”我错误地处理了这个问题。您显然正尝试为用户提供使用基于语言的界面编辑这些文本框的机会。您可能需要构建完整的解析器来帮助您,或者查看其他范例,或许遵循VS使用的相同方法,以允许您通过GUI类型的界面创建和编辑标签。通过这种方式,您可以对可以完成的操作进行更严格的控制,而无需进行“自然”语言分析的复杂操作。