首页 > 学院 > 开发设计 > 正文

csharp:FlowLayoutPanel

2019-11-17 02:29:08
字体:
来源:转载
供稿:网友

csharp:FlowLayoutPanel

        /// <summary>        /// 集合添加的控件        /// 涂聚文20150339        /// </summary>        public void AddNewTextBox()        {            Point p = new Point();            Label lb1 = new Label();            this.Controls.Add(lb1);            lb1.Text = "关系名称";            lb1.Top = cLeft * 25;            lb1.RightToLeft = RightToLeft.Yes;            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(lb1);            System.Windows.Forms.ComboBox cmb = new ComboBox();            relationshipTypeViewTitile.SetCombox(cmb);            this.Controls.Add(cmb);            cmb.Top = cLeft * 25;            cmb.Size = new System.Drawing.Size(121, 20);            cmb.Left = 2;            flowLayoutPanel1.Controls.Add(cmb);            Label lb2 = new Label();            this.Controls.Add(lb2);            lb2.Text = "关系人姓名";            lb2.Top = cLeft * 25;            lb2.RightToLeft = RightToLeft.Yes;            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(lb2);            System.Windows.Forms.TextBox txtName = new System.Windows.Forms.TextBox();            this.Controls.Add(txtName);            txtName.Name = "txtName";            txtName.Top = cLeft * 25;            txtName.Left = 200;            txtName.Text = "";// "TextBox" + this.cLeft.ToString();            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(txtName);            Label lbtel = new Label();            this.Controls.Add(lbtel);            lbtel.Text = "关系人电话";            lbtel.Top = cLeft * 25;            lbtel.RightToLeft = RightToLeft.Yes;            lbtel.Left = 200;            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(lbtel);            System.Windows.Forms.TextBox txtTel = new System.Windows.Forms.TextBox();            this.Controls.Add(txtTel);            txtTel.Name = "txtTel";            txtTel.Top = cLeft * 25;            txtTel.Left = 200;            txtTel.Text = "";// "TextBox" + this.cLeft.ToString();            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(txtTel);            Label lb4 = new Label();            this.Controls.Add(lb4);            lb4.Text = "关系人生出日期";            lb4.RightToLeft = RightToLeft.Yes;            lb4.Top = cLeft * 25;            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(lb4);            System.Windows.Forms.DateTimePicker dtime = new System.Windows.Forms.DateTimePicker();            dtime.Size = new Size(155, 30);            this.Controls.Add(dtime);            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(dtime);            Label lb5 = new Label();            this.Controls.Add(lb5);            lb5.Text = "关系人描述";            lb5.Top = cLeft * 25;            lb5.RightToLeft = RightToLeft.Yes;            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(lb5);            System.Windows.Forms.TextBox txtRelationDesc = new System.Windows.Forms.TextBox();            this.Controls.Add(txtRelationDesc);            txtRelationDesc.Name = "txtRelationDesc";            txtRelationDesc.Top = cLeft * 25;            txtRelationDesc.Left = 200;            txtRelationDesc.Text = "";// "TextBox" + this.cLeft.ToString();            cLeft = cLeft + 1;            flowLayoutPanel1.Controls.Add(txtRelationDesc);        }        /// <summary>        /// 添加控件事件        /// 涂聚文20150339        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        PRivate void button1_Click(object sender, EventArgs e)        {            AddNewTextBox();        }        /// <summary>        /// 获取添的控件的值        /// 涂聚文20150339        /// </summary>        /// <param name="sender"></param>        /// <param name="e"></param>        private void button2_Click(object sender, EventArgs e)        {             int s = 0;            int k = 0;            int n = 0;            for (int i = 0; i < flowLayoutPanel1.Controls.Count; i++)            {                if (flowLayoutPanel1.Controls[i].GetType() == typeof(ComboBox)) //按类型查找                {                    customerRelationTypeID = ((ComboBox)this.flowLayoutPanel1.Controls[i]).SelectedValue.ToString();                }                if (flowLayoutPanel1.Controls[i].GetType() == typeof(TextBox))                {                    //MessageBox.Show(((TextBox)this.flowLayoutPanel1.Controls[i]).Name);                    if (((TextBox)this.flowLayoutPanel1.Controls[i]).Name.Contains("txtName"))                    {                        customerRelationName = ((TextBox)this.flowLayoutPanel1.Controls[i]).Text.Trim();                    }                    if (((TextBox)this.flowLayoutPanel1.Controls[i]).Name.Contains("txtTel"))                    {                        customerRelationTel = ((TextBox)this.flowLayoutPanel1.Controls[i]).Text.Trim();                    }                    if (((TextBox)this.flowLayoutPanel1.Controls[i]).Name.Contains("txtRelationDesc"))                    {                        customerRelationDesc = ((TextBox)this.flowLayoutPanel1.Controls[i]).Text.Trim();                    }                }                if (flowLayoutPanel1.Controls[i].GetType() == typeof(DateTimePicker)) //按类型查找                {                    customerBirthday = ((DateTimePicker)this.flowLayoutPanel1.Controls[i]).Value;                }                if (IsOdd5(i))                {                    customerRelationContactsId = CustomerRelationContactsId;                    if (Operator == 1)                    {                        customerRelationshipListInfo.CustomerBirthday = customerBirthday;                        customerRelationshipListInfo.CustomerRelationContactsId = customerRelationContactsId;                        customerRelationshipListInfo.CustomerRelationDesc = customerRelationDesc;                        customerRelationshipListInfo.CustomerRelationName = customerRelationName;                        customerRelationshipListInfo.CustomerRelationTel = customerRelationTel;                        customerRelationshipListInfo.CustomerRelationTypeID = customerRelationTypeID;                        k = customerRelationshipListBLL.InsertCustomerRelationshipList(customerRelationshipListInfo);                        //MessageBox.Show(customerRelationTypeID + customerRelationName + customerRelationTel);                        n++;                    }                }            }            if (n > 0)            {                DialogResult dresult = MessageBox.Show("添加了" + n.ToString() + "条联系人", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);                if (dresult == DialogResult.OK)                {                    this.Close();                    this.DialogResult = DialogResult.OK;                }            }            else            {                DialogResult dresult = MessageBox.Show("存在问题,添加了" + n.ToString() + "条联系人", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Error);                if (dresult == DialogResult.No)                {                    this.Close();                    this.DialogResult = DialogResult.OK;                }                if (dresult == DialogResult.Yes)                {                    return;                }            }        }        /// <summary>        /// 判断奇偶数的函數        /// </summary>        /// <param name="n"></param>        /// <returns></returns>        public static bool IsOdd2(int n)        {            return Convert.ToBoolean(n % 2);        }        /// <summary>        ///         /// </summary>        /// <param name="n"></param>        /// <returns></returns>        public static bool IsOdd5(int n)        {            int b = 0;            bool isb = false;            b = n % 9;            if (n > 0)            {                if (b == 0)                {                    isb = true;                }            }            return isb;        }

  


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表