0

Below is event handler to be executed when a key is pressed ('enter'). No matter where I mention the statement 'p.tag_label.Visibilty=true" in the code,it never shows the tag_label control. Please guide. I mentioned in the code where exactly the tag_label loses its visibilty.

 void tag_box_KeyPress(object sender, KeyPressEventArgs e)
    {
        int i = (sender as TextBox).TabIndex;
        if (e.KeyChar == (char)13)
        {
            foreach (var h in heading_wise)
            {
                foreach (var p in h.project_panels)
                {
                    if (p.tag_box.TabIndex==i)
                    {
                        p.tag_text = p.tag_box.Text;


                        p.tag_box.Visible = false;
                      //  p.tag_label.Visible = true;
                        if (!string.IsNullOrWhiteSpace(p.tag_box.Text))
                        {
                            p.tag_label.Text = p.tag_box.Text;
                            p.tag_label.Visible = true;

                            foreach (Label l in flowLayoutPanel1.Controls)
                            {

                                if (l.Text==p.tag_label.Text)
                                {

                                    continue;
                                }
                                else
                                {


                                    flowLayoutPanel1.Controls.Add(p.tag_label);
                               // Somewhere here the tag_label loses its visibilty automatically.     
                                }

                            }

                        }

                    }

                }
            }


        }

    }
  • When you modify properties of a control like Text or Visibility, it needs to be invoked on the UI thread. – Ron Beyer May 19 '15 at 13:29
  • I don't understand what it means to invoke on the UI thread,Could you please elaborate ? What specific changes I need to made. –  May 19 '15 at 13:44
  • http://stackoverflow.com/questions/661561/how-to-update-the-gui-from-another-thread-in-c see the second answer for the simplest implementation. – Ron Beyer May 19 '15 at 13:47

0 Answers0