Example #1
0
 /// <summary>
 /// Sets the scroll bars.
 /// </summary>
 /// <param name="richTextBox">The rich text box.</param>
 /// <param name="value">The value.</param>
 public static void SetScrollBars(this RichTextBox richTextBox, RichTextBoxScrollBars value)
 {
     if (richTextBox.InvokeRequired)
     {
         richTextBox.BeginInvoke(new MethodInvoker(() => richTextBox.SetScrollBars(value)));
     }
     else
     {
         richTextBox.ScrollBars = value;
         richTextBox.Refresh();
     }
 }
            public virtual void ApplyScrollbars(RichTextBoxScrollBars scrollbars)
            {
                if (scrollView == null)
                {
                    return;
                }

                switch (scrollbars)
                {
                case RichTextBoxScrollBars.None:
                    scrollView.HasVerticalScroller   = false;
                    scrollView.HasHorizontalScroller = false;
                    scrollView.AutohidesScrollers    = true;
                    break;

                case RichTextBoxScrollBars.Vertical:
                    scrollView.HasVerticalScroller   = true;
                    scrollView.HasHorizontalScroller = false;
                    scrollView.AutohidesScrollers    = true;
                    break;

                case RichTextBoxScrollBars.Horizontal:
                    scrollView.HasVerticalScroller   = false;
                    scrollView.HasHorizontalScroller = true;
                    scrollView.AutohidesScrollers    = true;
                    break;

                case RichTextBoxScrollBars.Both:
                    scrollView.HasVerticalScroller   = true;
                    scrollView.HasHorizontalScroller = true;
                    scrollView.AutohidesScrollers    = true;
                    break;

                case RichTextBoxScrollBars.ForcedVertical:
                    scrollView.HasVerticalScroller   = true;
                    scrollView.HasHorizontalScroller = false;
                    scrollView.AutohidesScrollers    = false;
                    break;

                case RichTextBoxScrollBars.ForcedHorizontal:
                    scrollView.HasVerticalScroller   = false;
                    scrollView.HasHorizontalScroller = true;
                    scrollView.AutohidesScrollers    = false;
                    break;

                case RichTextBoxScrollBars.ForcedBoth:
                    scrollView.HasVerticalScroller   = true;
                    scrollView.HasHorizontalScroller = true;
                    scrollView.AutohidesScrollers    = false;
                    break;
                }
            }
Example #3
0
        /// <summary>
        /// Called when the Enabled state has changed.
        /// </summary>
        /// <param name="e">The event arguments.</param>
        protected override void OnEnabledChanged(EventArgs e)
        {
            // .NET 1.1 had a bug with RichTextBox's scroll bars.
            // After disabling and reenabling the control, the vertical scroll
            // bar would end up permenantly disabled.  But toggling the
            // ScrollBars property on reenable seems to fix it.
            if (this.Enabled && this.ScrollBars != RichTextBoxScrollBars.None)
            {
                RichTextBoxScrollBars original = this.ScrollBars;
                this.ScrollBars = RichTextBoxScrollBars.None;
                this.ScrollBars = original;
            }

            base.OnEnabledChanged(e);
        }
Example #4
0
		// Constructor will go when complete, only for testing - pdb
		internal TextBoxBase ()
		{
			alignment = HorizontalAlignment.Left;
			accepts_return = false;
			accepts_tab = false;
			auto_size = true;
			InternalBorderStyle = BorderStyle.Fixed3D;
			actual_border_style = BorderStyle.Fixed3D;
			character_casing = CharacterCasing.Normal;
			hide_selection = true;
			max_length = short.MaxValue;
			password_char = '\0';
			read_only = false;
			word_wrap = true;
			richtext = false;
			show_selection = false;
			enable_links = false;
			list_links = new ArrayList ();
			current_link = null;
			show_caret_w_selection = (this is TextBox);
			document = new Document(this);
			document.WidthChanged += new EventHandler(document_WidthChanged);
			document.HeightChanged += new EventHandler(document_HeightChanged);
			//document.CaretMoved += new EventHandler(CaretMoved);
			document.Wrap = false;
			click_last = DateTime.Now;
			click_mode = CaretSelection.Position;

			MouseDown += new MouseEventHandler(TextBoxBase_MouseDown);
			MouseUp += new MouseEventHandler(TextBoxBase_MouseUp);
			MouseMove += new MouseEventHandler(TextBoxBase_MouseMove);
			SizeChanged += new EventHandler(TextBoxBase_SizeChanged);
			FontChanged += new EventHandler(TextBoxBase_FontOrColorChanged);
			ForeColorChanged += new EventHandler(TextBoxBase_FontOrColorChanged);
			MouseWheel += new MouseEventHandler(TextBoxBase_MouseWheel);
			RightToLeftChanged += new EventHandler (TextBoxBase_RightToLeftChanged);
			
			scrollbars = RichTextBoxScrollBars.None;

			hscroll = new ImplicitHScrollBar();
			hscroll.ValueChanged += new EventHandler(hscroll_ValueChanged);
			hscroll.SetStyle (ControlStyles.Selectable, false);
			hscroll.Enabled = false;
			hscroll.Visible = false;
			hscroll.Maximum = Int32.MaxValue;

			vscroll = new ImplicitVScrollBar();
			vscroll.ValueChanged += new EventHandler(vscroll_ValueChanged);
			vscroll.SetStyle (ControlStyles.Selectable, false);
			vscroll.Enabled = false;
			vscroll.Visible = false;
			vscroll.Maximum = Int32.MaxValue;

			SuspendLayout ();
			this.Controls.AddImplicit (hscroll);
			this.Controls.AddImplicit (vscroll);
			ResumeLayout ();
			
			SetStyle(ControlStyles.UserPaint | ControlStyles.StandardClick, false);
#if NET_2_0
			SetStyle(ControlStyles.UseTextForAccessibility, false);
			
			base.SetAutoSizeMode (AutoSizeMode.GrowAndShrink);
#endif

			canvas_width = ClientSize.Width;
			canvas_height = ClientSize.Height;
			document.ViewPortWidth = canvas_width;
			document.ViewPortHeight = canvas_height;

			Cursor = Cursors.IBeam;
		}
	public RichTextBox() : base()
	{
		autoWordSelection = false;
		bulletIndent = 0;
		detectUrls = true;
		rightMargin = 0;
		scrollBars = RichTextBoxScrollBars.Both;
		zoomFactor = 1;
		base.MaxLength = 2147483647;
		base.Multiline = true;
	}
Example #6
0
 static string XmlFromControlScrollBarsProperty(RichTextBoxScrollBars ScBars)
 {
     return XmlFromTagValue(ModUiTags.RichTextScrollBars, ScBars);
 }
Example #7
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()); }
 }
 public virtual void ApplyScrollbars(RichTextBoxScrollBars scrollbars)
 {
     // No scrollbars in this implementation
 }