예제 #1
0
        private void TbValue_LostFocus(object sender, EventArgs e)
        {
            TextBox tb       = sender as TextBox;
            string  property = tb.Tag as string;
            string  value    = tb.Text;
            Pset    pset     = psets[tabControl1.SelectedIndex];

            try
            {
                object v = Convert.ChangeType(value, pset.GetType().GetProperty(property).PropertyType);
                pset.GetType().GetProperty(property).SetValue(pset, v, null);
            }
            catch { }
            tb.Text = pset.GetType().GetProperty(property).GetValue(pset).ToString();
        }
예제 #2
0
        private void AddTabPageByPset(Pset pset)
        {
            TabPage tp = new TabPage(pset.PsetName);

            tabControl1.TabPages.Add(tp);

            int x = 10, y = 10, i = 0;

            foreach (var property in pset.GetType().GetProperties())
            {
                Label lbText = new Label();
                lbText.Location  = new Point(x, y + (i / 2) * 40);
                lbText.Size      = new Size(120, 30);
                lbText.Text      = property.Name;
                lbText.TextAlign = ContentAlignment.TopRight;
                tp.Controls.Add(lbText);

                TextBox tbValue = new TextBox();
                tbValue.Location   = new Point(x + 130, y + (i / 2) * 40);
                tbValue.Size       = new Size(100, 30);
                tbValue.Tag        = property.Name;
                tbValue.Text       = (property.GetValue(pset, null) == null ? "" : property.GetValue(pset, null)).ToString();
                tbValue.ReadOnly   = i == 0 || i == 1;
                tbValue.LostFocus += TbValue_LostFocus;
                tp.Controls.Add(tbValue);

                if (i % 2 == 0)
                {
                    x += 230 + 10;
                }
                else
                {
                    x = 10;
                }

                i++;
            }
            Button tightOk = new Button();

            tightOk.Text     = "拧个OK的";
            tightOk.Location = new Point(10, y + (i / 2) * 40 + 30);
            tightOk.Size     = new Size(80, 30);
            tightOk.Click   += TightOk_Click;
            tp.Controls.Add(tightOk);

            Button tightNOk = new Button();

            tightNOk.Text     = "拧个NOK的";
            tightNOk.Location = new Point(100, y + (i / 2) * 40 + 30);
            tightNOk.Size     = new Size(80, 30);
            tightNOk.Click   += TightNOk_Click;
            tp.Controls.Add(tightNOk);
        }