WinForms Dynamic Label

Posted by tolga on Stack Overflow See other posts from Stack Overflow or by tolga
Published on 2010-06-03T14:27:21Z Indexed on 2010/06/03 14:34 UTC
Read the original article Hit count: 169

Filed under:
|
|

I am creating dynamic labels and letting users change attributes of the labes like backcolor and so by sending unicode. However I don't know how to check if the label exists therefore I can't manipulate the dynamicly created label. below is my code:

if ((InputBox.Text.StartsWith("p")) && (InputBox.Text.EndsWith("}")))// only process if the message starts with p and ends with }
{
    string Message = InputBox.Text;
    InputBox.Text = "";// Clear the box when done. 

    // Butt1 message line
    if (Message.StartsWith("plabelt1"))
    {
        if (Message.StartsWith("plabelt1_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();
    }
}

Any suggestions?

© Stack Overflow or respective owner

Related posts about c#

Related posts about dynamic