I want to create application that create a textBox after 10 second from starting and create a label after 20 seconds from starting

Recommended Answers

All 3 Replies

one of the things you can drop onto a form ( like you drop a text box) is a timer. You would also need to create an action listener for your timer. i'm not sure on details of adding controls on the fly to a form, but you should easily be able to switch the visible status.

Mike

sounds like i fell into java syntax with 'action listener' but you click the lightning bolt in the control properties thing and add essentially a listener for your timer control. i wrote mine out in code first then linked it through that lightning bolt. google c# timer maybe get all the info you need.

private void frmImage_Load(object sender, EventArgs e)
    {
      new Action(CreateStuff).BeginInvoke(null, null);
    }

    private void CreateStuff()
    {
      DateTime dtStart = System.Diagnostics.Process.GetCurrentProcess().StartTime;
      while (DateTime.Now.Subtract(dtStart).TotalSeconds < 10) //10s
        System.Threading.Thread.Sleep(10);
      
      TextBox tb = null;
      this.Invoke(new MethodInvoker(
        delegate()
        {
          tb = new TextBox();
          tb.Location = new Point(0, 0);
          tb.Text = "abc123";
          tb.Name = "textbox12345";
          this.Controls.Add(tb);
        }));
      while (DateTime.Now.Subtract(dtStart).TotalSeconds < 20) //20s
        System.Threading.Thread.Sleep(10);
      this.Invoke(new MethodInvoker(
        delegate()
        {
          //Put this to the right of the textbox we created
          Label lbl = new Label();
          lbl.Location = new Point(tb.Left+tb.Width+10, 0);
          lbl.Text = "def123";
          this.Controls.Add(lbl);
        }));
    }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.