csharp:FlowLayoutPanel_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > csharp:FlowLayoutPanel

csharp:FlowLayoutPanel

 2015/3/29 18:41:04  ?Geovin Du Dream Park?  程序员俱乐部  我要评论(0)
  • 摘要:///<summary>///添加控件方法///</summary>///<returns></returns>publicSystem.Windows.Forms.TextBoxAddNewTextBox(){Pointp=newPoint();System.Windows.Forms.ComboBoxcmb=newComboBox();cmb.DataSource=setCmb();cmb.ValueMember="id";cmb
  • 标签:ARP
class="brush:csharp;gutter:true;"> /// <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的控件");
                //}
            }



           

        }

  

发表评论
用户名: 匿名