Exemplo n.º 1
0
        /// <summary>
        /// 生成模板
        /// </summary>
        /// <param name="editdoc">XML模板</param>
        private void InitCustomConfig(XmlDocument editdoc)
        {
            //模板底图
            Image img = EditTemplateInfo.GetEditImg(Editname);

            P_bgimg.Size            = new Size(img.Width, img.Height);
            P_bgimg.BackgroundImage = img;
            //模板中的控件
            P_bgimg.Controls.Clear();//清空模板控件
            //项模板
            foreach (XmlNode item in editdoc.DocumentElement.ChildNodes[4])
            {
                //属性项目|TabIndex索引
                int tabindex = Convert.ToInt32(EditTemplateMethod.GetXmlNodeTextInt(item.SelectSingleNode("TAB_INDEX"), "0"));
                //中文名
                string cname = EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("ITEM_CNAME"));
                //英文名
                string ename = EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("ITEM_ENAME"));
                //控件大小
                Size size = new Size(Convert.ToInt32(EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("ITEM_WIDTH"))), Convert.ToInt32(EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("ITEM_HEIGHT"))));
                //停靠在模板中的位置
                Point location = new Point(Convert.ToInt32(EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("POS_X"))), Convert.ToInt32(EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("POS_Y"))));
                //是否多行文本
                EditControlIsOrMultiline multiline = EditControlIsOrMultiline.FalseMultiline;
                if ((Convert.ToInt32(EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("MULTILINE"))) == 1))
                {
                    multiline = EditControlIsOrMultiline.TrueMultiline;
                }
                //是否自动换行
                EditControlIsOrWrap wrap = EditControlIsOrWrap.FalseWrap;
                if ((Convert.ToInt32(EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("WORD_WRAP"))) == 1))
                {
                    wrap = EditControlIsOrWrap.TrueWrap;
                }
                //默认控件类型为TextBoxText
                EditControlTypeInfo edittype = EditControlTypeInfo.TextBoxText;
                switch (EditTemplateMethod.GetXmlNodeText(item.SelectSingleNode("ITEM_TYPE")))
                {
                case "RichTextBox": edittype = EditControlTypeInfo.RichTextBox;
                    break;

                case "TextBoxText": edittype = EditControlTypeInfo.TextBoxText;
                    break;

                case "TextBoxNumber": edittype = EditControlTypeInfo.TextBoxNumber;
                    break;

                case "DateTimePicker": edittype = EditControlTypeInfo.DateTimePicker;
                    break;

                case "PictureBox": edittype = EditControlTypeInfo.PictureBox;
                    break;

                case "CheckBox": edittype = EditControlTypeInfo.CheckBox;
                    break;

                case "TextBoxLong": edittype = EditControlTypeInfo.TextBoxLong;
                    break;
                }
                CreateCustomControl(tabindex, cname, ename, size, location, multiline, wrap, edittype, BorderStyle.FixedSingle, true, ScrollBars.Both, RichTextBoxScrollBars.Both);
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// 根据相关参数生成控件
 /// </summary>
 /// <param name="tabindex">控件的Tab索引</param>
 /// <param name="cname">控件的中文名称</param>
 /// <param name="ename">控件的英文名称</param>
 /// <param name="size">控件的尺寸</param>
 /// <param name="location">控件的坐标</param>
 /// <param name="ismultiline">是否是多行文本</param>
 /// <param name="iswrap">多行文本时是否自动换行</param>
 /// <param name="controltype">控件的类型</param>
 /// <param name="borderstyle">控件的边框样式</param>
 /// <param name="autosize">是否自动调整控件高度</param>
 /// <param name="scroll">TextBox控件的滚动条类型(注:只对多行文本有效)</param>
 /// <param name="richscrollbar">RichTextBox控件的滚动条类型</param>
 private Control CreateCustomControl(int tabindex, string cname, string ename, Size size, Point location, EditControlIsOrMultiline ismultiline, EditControlIsOrWrap iswrap, EditControlTypeInfo controltype, BorderStyle borderstyle, bool autosizeheight, ScrollBars scroll, RichTextBoxScrollBars richscrollbar)
 {
     try
     {
         Control CustomControl = null;                       //用来套用所有形参属性的控件模板
         if (controltype == EditControlTypeInfo.RichTextBox) //判断是否是RichTextBox控件类型
         {
             CustomControl      = System.Activator.CreateInstance(typeof(RichTextBox), true) as RichTextBox;
             CustomControl.Name = ename;
             ((CustomControl) as RichTextBox).Multiline   = ismultiline == EditControlIsOrMultiline.TrueMultiline ? true : false;
             ((CustomControl) as RichTextBox).BorderStyle = borderstyle;
             ((CustomControl) as RichTextBox).BackColor   = Color.White;
             ((CustomControl) as RichTextBox).WordWrap    = iswrap == EditControlIsOrWrap.TrueWrap ? true : false;
             ((CustomControl) as RichTextBox).DetectUrls  = true;
             ((CustomControl) as RichTextBox).ScrollBars  = richscrollbar;
             ((CustomControl) as RichTextBox).MaxLength   = 200;
             ((CustomControl) as RichTextBox).TabIndex    = tabindex;
             ((CustomControl) as RichTextBox).Tag         = cname;
         }
         else if (controltype == EditControlTypeInfo.TextBoxLong)//判断是否是TextBoxLong类型,对应于长文本类型
         {
             CustomControl      = System.Activator.CreateInstance(typeof(TextBox), true) as TextBox;
             CustomControl.Name = ename;
             ((CustomControl) as TextBox).Multiline   = ismultiline == EditControlIsOrMultiline.TrueMultiline ? true : false;
             ((CustomControl) as TextBox).BackColor   = Color.White;
             ((CustomControl) as TextBox).BorderStyle = borderstyle;
             ((CustomControl) as TextBox).WordWrap    = iswrap == EditControlIsOrWrap.TrueWrap ? true : false;
             ((CustomControl) as TextBox).ScrollBars  = scroll;
             ((CustomControl) as TextBox).MaxLength   = 200;
             ((CustomControl) as TextBox).TabIndex    = tabindex;
             ((CustomControl) as TextBox).Tag         = cname;
         }
         else if (controltype == EditControlTypeInfo.PictureBox)//是否是PictureBox类型
         {
             CustomControl      = System.Activator.CreateInstance(typeof(PictureBox), true) as PictureBox;
             CustomControl.Name = ename;
             ((CustomControl) as PictureBox).BackColor             = Color.White;
             ((CustomControl) as PictureBox).BackgroundImageLayout = ImageLayout.Stretch;
             ((CustomControl) as PictureBox).BorderStyle           = borderstyle;
             ((CustomControl) as PictureBox).SizeMode = PictureBoxSizeMode.Zoom;
             ((CustomControl) as PictureBox).Tag      = cname;
             CustomControl.Click += new EventHandler(CustomControl_Click); //单击图片事件提示选择图片
         }
         else if (controltype == EditControlTypeInfo.CheckBox)             //是否是CheckBox类型
         {
             CustomControl      = System.Activator.CreateInstance(typeof(CheckBox), true) as CheckBox;
             CustomControl.Name = ename;
             CustomControl.Text = cname;
             CustomControl.Tag  = cname;
         }
         else if (controltype == EditControlTypeInfo.TextBoxText)//是否是TextBox类型
         {
             CustomControl      = System.Activator.CreateInstance(typeof(TextBox), true) as TextBox;
             CustomControl.Name = ename;
             CustomControl.Tag  = cname;
             ((CustomControl) as TextBox).BackColor   = Color.White;
             ((CustomControl) as TextBox).Multiline   = ismultiline == EditControlIsOrMultiline.TrueMultiline ? true : false;
             ((CustomControl) as TextBox).WordWrap    = iswrap == EditControlIsOrWrap.TrueWrap ? true : false;
             ((CustomControl) as TextBox).BorderStyle = borderstyle;
             ((CustomControl) as TextBox).MaxLength   = 200;
             CustomControl.KeyPress += new KeyPressEventHandler(CustomControl_KeyPress); //TextBox类型验证输入
         }
         else if (controltype == EditControlTypeInfo.DateTimePicker)                     //是否是DateTimePicker时间类型
         {
             CustomControl      = System.Activator.CreateInstance(typeof(DateTimePicker), true) as DateTimePicker;
             CustomControl.Name = ename;
             CustomControl.Tag  = cname;
             ((CustomControl) as DateTimePicker).Value = DateTime.Now; //当前系统时间为准
         }
         else if (controltype == EditControlTypeInfo.TextBoxNumber)    //是否是TextBox只能输入数字的文本框
         {
             CustomControl      = System.Activator.CreateInstance(typeof(TextBox), true) as TextBox;
             CustomControl.Name = ename;
             CustomControl.Tag  = cname;
             ((CustomControl) as TextBox).BorderStyle = borderstyle;
             ((CustomControl) as TextBox).BackColor   = Color.White;
             ((CustomControl) as TextBox).WordWrap    = iswrap == EditControlIsOrWrap.TrueWrap ? true : false;
             ((CustomControl) as TextBox).MaxLength   = 200;
             ((CustomControl) as TextBox).Multiline   = ismultiline == EditControlIsOrMultiline.TrueMultiline ? true : false;
             CustomControl.KeyPress += new KeyPressEventHandler(CustomControlNumber_KeyPress);
         }
         CustomControl.TabIndex         = tabindex;       //Tab索引
         CustomControl.Size             = size;           //大小
         CustomControl.Location         = location;       //呈现位置
         CustomControl.ContextMenuStrip = CMS_CustomMenu; //设置控件的快捷菜单
         CustomControl.MouseDown       += new MouseEventHandler(CustomControl_MouseDown);
         CustomControl.MouseMove       += new MouseEventHandler(CustomControl_MouseMove);
         CustomControl.MouseUp         += new MouseEventHandler(CustomControl_MouseUp);
         CustomControl.Move            += new EventHandler(CustomControl_Move);
         CustomControl.MouseEnter      += new EventHandler(CustomControl_MouseEnter);
         CustomControl.MouseLeave      += new EventHandler(CustomControl_MouseLeave);
         P_bgimg.Controls.Add(CustomControl);
         return(CustomControl);
     }
     catch (Exception err) { MessageBox.Show(err.ToString()); return(new Control()); }
 }