程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> C# >> C#入門知識 >> csharp:FlowLayoutPanel,csharp

csharp:FlowLayoutPanel,csharp

編輯:C#入門知識

csharp:FlowLayoutPanel,csharp


 /// <summary>
        /// 添加控件方法
        /// </summary>
        /// <returns></returns>
        public System.Windows.Forms.TextBox AddNewTextBox()
        {
            Point p = new Point();
            System.Windows.Forms.ComboBox cmb = new ComboBox();
            cmb.DataSource = setCmb();
           
            cmb.ValueMember = "id";
            cmb.DisplayMember = "name";           
            this.Controls.Add(cmb);
            cmb.Top = cLeft * 25;
            cmb.Size = new System.Drawing.Size(121, 20);
            cmb.Left = 2;
            flowLayoutPanel2.Controls.Add(cmb);
            System.Windows.Forms.TextBox txt = new System.Windows.Forms.TextBox();
            this.Controls.Add(txt);
            txt.Top = cLeft * 25;
            txt.Left = 200;
            txt.Text = "TextBox" + this.cLeft.ToString();
            cLeft = cLeft + 1;
            flowLayoutPanel2.Controls.Add(txt);
            return txt;
        }
        /// <summary>
        /// 添加控件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            AddNewTextBox();
        }
        /// <summary>
        /// 獲取控件的值
        /// 塗聚文20150339
        /// Geovin Du
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {

            //((TextBox)this.flowLayoutPanel2.Controls[2]).Text = "geovindu"; //設置值

            //string s = ((TextBox)this.flowLayoutPanel2.Controls[2]).Text.Trim();
            //MessageBox.Show(s);
            string s = string.Empty;

            for (int i = 0; i < flowLayoutPanel2.Controls.Count; i++)
            {
                if (flowLayoutPanel2.Controls[i].GetType() == typeof(TextBox))
                {

                    s = s + ((TextBox)this.flowLayoutPanel2.Controls[i]).Text.Trim() + ";";
                }
            }
             MessageBox.Show(s);
            foreach (Control control in flowLayoutPanel2.Controls)
            {
                if (control.GetType() == typeof(ComboBox)) //按類型查找
                {
                    ComboBox cb = control as ComboBox; //轉換為具體控件類型
                    cb.SelectedText.ToString();
                }

                //if (control.Name == "ComboBox2") //查找某Name的控件
                //{
                //    MessageBox.Show("我是名為pictureBox2的控件");
                //}
            }



           

        }

  

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved