123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- namespace IntelligentControlForsx.Test
- {
- public partial class MainTest : Form
- {
- private bool isAllLoad = false;
- public MainTest()
- {
- InitializeComponent();
- for (int i = 0; i < 5; i++)
- {
- Button bt = new Button();
- bt.Name = "bt";
- bt.Text = "btn" + i;
- bt.Dock = DockStyle.Left;
- plStructure.Controls.Add(bt);
- }
- }
- private void MainTest_Load(object sender, EventArgs e)
- {
- }
- private void MainTest_Shown(object sender, EventArgs e)
- {
- }
- private void ThreadTest()
- {
- ControlAddDelegate del = new ControlAddDelegate(ControlAdd);
- this.plLoad.Invoke(del);
- }
- private void ControlAdd()
- {
- Thread.Sleep(5000);
- for (int i = 0; i < 5; i++)
- {
- Button bt = new Button();
- bt.Name = "bt" + i;
- bt.Text = "btn" + i;
- bt.Dock = DockStyle.Left;
- plLoad.Controls.Add(bt);
- }
- for (int i = 5; i < 10; i++)
- {
- Button bt = new Button();
- bt.Name = "bt" + i;
- bt.Text = "btn" + i;
- bt.Dock = DockStyle.Left;
- plOther.Controls.Add(bt);
- }
- plLoad.Hide();
- plOther.Hide();
- isAllLoad = true;
- Console.WriteLine("线程加载完毕====================================");
- }
- public delegate void ControlAddDelegate();
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (isAllLoad == false)
- {
- Console.WriteLine("定时器执行(未加载完毕)");
- Thread t = new Thread(ThreadTest);
- t.Start();
- Console.WriteLine("form加载完毕====================================");
- }
- else
- {
- Console.WriteLine("定时器执行(已经加载完毕)");
- timer1.Enabled = false;
- }
- }
- private void btnShow1_Click(object sender, EventArgs e)
- {
- plStructure.Show();
- plLoad.Hide();
- plOther.Hide();
- }
- private void btnShow2_Click(object sender, EventArgs e)
- {
- plStructure.Hide();
- plLoad.Show();
- plOther.Hide();
- }
- private void btnShow3_Click(object sender, EventArgs e)
- {
- plStructure.Hide();
- plLoad.Hide();
- plOther.Show();
- }
- private void btnGetAllControl_Click(object sender, EventArgs e)
- {
- foreach (Control ctrl in this.plStructure.Controls)
- {
- Console.WriteLine(ctrl.Name);
- }
- }
- }
- }
|