Example #1
0
 private void InitializeControls()
 {
     this.FormClosing += Form1_FormClosing;
     {
         TLP = new MyTableLayoutPanel(5, 1, "PAAAA", "P");
         {
             {
                 LBL    = new MyLabel("");
                 status = "Q, W, O: control\r\nP: restart all";
                 TLP.AddControl(LBL, 0, 0);
             }
             {
                 MyTableLayoutPanel tlp = new MyTableLayoutPanel(1, 2, "A", "AA");
                 {
                     PBX          = new PictureBox();
                     PBX.Dock     = DockStyle.Fill;
                     PBX.SizeMode = PictureBoxSizeMode.AutoSize;
                     PBX.Image    = Properties.Resources.buttonDark;
                     tlp.AddControl(PBX, 0, 0);
                 }
                 {
                     Panel pnl = new Panel();
                     pnl.Dock         = DockStyle.Fill;
                     pnl.AutoSize     = true;
                     pnl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                     PictureBox pbx = new PictureBox();
                     pbx.Dock     = DockStyle.Fill;
                     pbx.SizeMode = PictureBoxSizeMode.Zoom;
                     pbx.Image    = Properties.Resources.computer;
                     MyLabel lbl = new MyLabel("");
                     lbl.Font      = new Font("Consolas", 8, FontStyle.Bold);
                     lbl.Dock      = DockStyle.None;
                     lbl.ForeColor = Color.FromArgb(64, 0, 0, 0);
                     lbl.BackColor = Color.Transparent;
                     lbl.Parent    = pbx;
                     //{
                     //    Bitmap bmp = new Bitmap(1, 1);
                     //    bmp.SetPixel(0, 0, Color.Transparent);
                     //    lbl.BackgroundImage = bmp;
                     //}
                     //pnl.Controls.Add(lbl);
                     pnl.Controls.Add(pbx);
                     tlp.AddControl(pnl, 0, 1);
                     Thread thread = new Thread(() =>
                     {
                         Thread.Sleep(3000);
                         while (true)
                         {
                             Thread.Sleep(20);
                             StringBuilder s = new StringBuilder();
                             for (int i = 0; i < 10; i++)
                             {
                                 for (int j = 0; j < 30; j++)
                                 {
                                     s.Append(random.Next(0, 2) == 0 ? '0' : '1');
                                 }
                                 s.Append("\r\n");
                             }
                             lbl.Invoke(new Action(() => { lbl.Text = s.ToString(); }));
                         }
                     });
                     thread.IsBackground = true;
                     thread.Start();
                 }
                 TLP.AddControl(tlp, 1, 0);
             }
             {
                 TB         = new TrackBar();
                 TB.Dock    = DockStyle.Fill;
                 TB.Minimum = 0;
                 TB.Maximum = 1000;
                 TLP.AddControl(TB, 2, 0);
             }
             {
                 TXB              = new MyTextBox(false);
                 TXB.KeyDown     += Form1_KeyDown;
                 TXB.KeyUp       += Form1_KeyUp;
                 TXB.TextChanged += (object s, EventArgs e1) => { TXB.Text = null; };
                 TLP.AddControl(TXB, 3, 0);
             }
             {
                 IFD = new MyInputField();
                 IFD.AddField("Play speed (FPS)", FPS.ToString()).TextChanged += (object s, EventArgs e1) => {
                     double t;
                     if (!double.TryParse((s as TextBox).Text, out t))
                     {
                         MessageBox.Show("格式不正確");
                     }
                     else
                     {
                         FPS = t;
                     }
                 };
                 TLP.AddControl(IFD, 4, 0);
             }
         }
         this.Controls.Add(TLP);
     }
 }