Esempio n. 1
0
 public Editor(TextBoxBase tbb)
 {
     _TextBoxBase = tbb;
     _TextBoxBase.KeyDown += new KeyEventHandler(KeyDown);
     _TextBoxBase.KeyUp += new KeyEventHandler(KeyUp);
     _TextBoxBase.KeyPress += new KeyPressEventHandler(KeyPress);
 }
Esempio n. 2
0
        public static bool Undo()
        {
            bool res = Execute(OnUndo);

            if (!res)
            {
                Control activeControl = Application.ActiveControl;
                if (activeControl == null)
                {
                    return(false);
                }

                System.Windows.Forms.TextBoxBase active = activeControl as System.Windows.Forms.TextBoxBase;
                res = active != null;
                if (res)
                {
                    active.Undo();
                }
                else
                {
                    MethodInfo method = activeControl.GetType().GetMethod("Undo");
                    if (method != null)
                    {
                        Clipboard.FunctionWithoutReturn getMethod = (Clipboard.FunctionWithoutReturn)Delegate.CreateDelegate
                                                                        (typeof(Clipboard.FunctionWithoutReturn), activeControl, method);

                        getMethod();
                        res = true;
                    }
                }
            }
            return(res);
        }
 public LogWriter(TextBoxBase textBox, string path, bool writeTimestamp, bool append, params TextWriter[] otherOutputs)
     : base(path, writeTimestamp, append, otherOutputs)
 {
     _textBox = textBox;
     _scrollTextBox = true;
     _textBox.MouseWheel += new MouseEventHandler(textBox_MouseWheel);
 }
Esempio n. 4
0
 public static void AppendText(TextBoxBase control, string text)
 {
     if (control.InvokeRequired)
         control.Invoke(new AppendTextDelegate(AppendText), control, text);
     else
         control.AppendText(text);
 }
Esempio n. 5
0
        public bool GetSpellCheck(TextBoxBase extendee)
        {
            if(this.textBoxes.Contains(extendee))
                return (bool)this.textBoxes[extendee];

            return false;
        }
Esempio n. 6
0
		public TextNormalizer (TextBoxBase textboxbase) 
		{
			this.textboxbase = textboxbase;
			
			start_point = 0;
			end_point = Text.Length;
		}
Esempio n. 7
0
        /// <summary>
        /// Does application-wide cut
        /// </summary>
        public static void Cut()
        {
            Control activeControl = Application.ActiveControl;

            if (activeControl == null)
            {
                return;
            }

            System.Windows.Forms.TextBoxBase active = activeControl as System.Windows.Forms.TextBoxBase;
            if (active != null)
            {
                active.Cut();
                return;
            }

            System.Windows.Forms.WebBrowser webbrowser = activeControl as System.Windows.Forms.WebBrowser;
            if (webbrowser != null)
            {
                WebBrowserHelper.ExecCopy(webbrowser);
                ///TODO: don't work in unix
                return;
            }

            MethodInfo method = activeControl.GetType().GetMethod("Cut");

            if (method != null)
            {
                FunctionWithoutReturn getMethod = (FunctionWithoutReturn)Delegate.CreateDelegate
                                                      (typeof(FunctionWithoutReturn), activeControl, method);

                getMethod();
            }
        }
Esempio n. 8
0
        /// <summary>
        ///   Returns the index of the character under the specified 
        ///   point in the control, or the nearest character if there
        ///   is no character under the point.
        /// </summary>
        /// <param name = "textBox">The text box control to check.</param>
        /// <param name = "point">The point to find the character for, 
        ///   specified relative to the client area of the text box.</param>
        /// <returns></returns>
        internal static int CharFromPos(TextBoxBase textBox, Point point)
        {
            unchecked
            {
                // Convert the point into a DWord with horizontal position
                // in the loword and vertical position in the hiword:
                var xy = (point.X & 0xFFFF) + ((point.Y & 0xFFFF) << 16);
                // Get the position from the text box.
                var res =
                    NativeMethods.SendMessageInt(
                        textBox.Handle,
                        NativeMethods.EM_CHARFROMPOS,
                        IntPtr.Zero,
                        new IntPtr(xy)).ToInt32();

                // the Platform SDK appears to be incorrect on this matter.
                // the hiword is the line number and the loword is the index
                // of the character on this line
                var lineNumber = ((res & 0xFFFF) >> 16);
                var charIndex = (res & 0xFFFF);

                // Find the index of the first character on the line within
                // the control:
                var lineStartIndex =
                    NativeMethods.SendMessageInt(
                        textBox.Handle,
                        NativeMethods.EM_LINEINDEX,
                        new IntPtr(lineNumber),
                        IntPtr.Zero).ToInt32();
                // Return the combined index:
                return lineStartIndex + charIndex;
            }
        }
Esempio n. 9
0
        public SpellChecker(TextBoxBase textbox, string localeId)
        {
            this.textbox = textbox;
            this.localeId = localeId;

            baseDir = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
        }
Esempio n. 10
0
        public CustomPaintTextBox(TextBoxBase clientTextBox, SpellChecker checker)
        {
            //Set up the CustomPaintTextBox
            this.clientTextBox = clientTextBox;
            this.mySpellChecker = checker;

            //Create a bitmap with the same dimensions as the textbox
            myBitmap = new Bitmap(clientTextBox.Width, clientTextBox.Height);

            //Create the graphics object from this bitmpa...this is where we will draw the lines to start with
            bufferGraphics = Graphics.FromImage(this.myBitmap);
            bufferGraphics.Clip = new Region(clientTextBox.ClientRectangle);

            //Get the graphics object for the textbox.  We use this to draw the bufferGraphics
            textBoxGraphics = Graphics.FromHwnd(clientTextBox.Handle);

            //Assign a handle for this class and set it to the handle for the textbox
            this.AssignHandle(clientTextBox.Handle);

            //We also need to make sure we update the handle if the handle for the textbox changes
            //This occurs if wordWrap is turned off for a RichTextBox
            clientTextBox.HandleCreated += TextBoxBase_HandleCreated;

            //We need to add a handler to change the clip rectangle if the textBox is resized
            clientTextBox.ClientSizeChanged += TextBoxBase_ClientSizeChanged;

            //this.disposedValue = false;
        }
Esempio n. 11
0
		public HotSpot(TextBoxBase control, int offset, int length)
		{
			if(control == null)
			{
				throw  new ArgumentNullException("control");
			}
			if(offset < 0)
			{
				throw  new ArgumentOutOfRangeException("offset", offset, "offset cannot be less than zero");
			}
			if (offset >= control.Text.Length)
			{
				throw new ArgumentOutOfRangeException("offset", offset, "offset must be shorter than text.");
			}
			if(length <= 0)
			{
				throw new ArgumentOutOfRangeException("length", offset, "length must be greater than zero");
			}
			if (offset + length > control.Text.Length)
			{
				throw new ArgumentOutOfRangeException("length", length, "length plus offset must be shorter than text.");
			}
			_control = control;
			_offset = offset;
			_text = _control.Text.Substring(_offset, length);
		}
Esempio n. 12
0
        /// <summary>
        /// Creates a new instance of the <see cref="TextBoxWriter"/> class.
        /// </summary>
        /// <param name="b">The <see cref="TextBoxBase"/> that will be written to.</param>
        /// <exception cref="NullReferenceException">Thrown if the supplied TextBoxBase is null.</exception>
        public TextBoxWriter( TextBoxBase b )
        {
            if ( b == null )
                throw new NullReferenceException();

            textBox = b;
        }
Esempio n. 13
0
        /// <summary>
        /// Does application-wide cut
        /// </summary>
        public static void Paste()
        {
            Control activeControl = Application.ActiveControl;

            if (activeControl == null)
            {
                return;
            }

            System.Windows.Forms.TextBoxBase active = activeControl as System.Windows.Forms.TextBoxBase;
            if (active != null)
            {
                active.Paste();
                return;
            }

            MethodInfo method = activeControl.GetType().GetMethod("Paste");

            if (method != null)
            {
                FunctionWithoutReturn getMethod = (FunctionWithoutReturn)Delegate.CreateDelegate
                                                      (typeof(FunctionWithoutReturn), activeControl, method);

                getMethod();
            }
        }
Esempio n. 14
0
		public TextNormalizer (TextBoxBase textboxbase, int startPoint, int endPoint)
		{
			this.textboxbase = textboxbase;
			
			start_point = startPoint;
			end_point = endPoint;
		}
Esempio n. 15
0
 public void AddControl(TextBoxBase control)
 {
     control.KeyUp += new KeyEventHandler(control_KeyUp);
     control.MouseClick += new MouseEventHandler(control_MouseClick);
     control.GotFocus += new EventHandler(control_GotFocus);
     control.KeyDown += new KeyEventHandler(control_KeyDown);
 }
Esempio n. 16
0
 private static bool ShouldSelectToken(Match match, TextBoxBase label)
 {
     var start = match.Index;
     var end = start + match.Length;
     var caret = label.SelectionStart;
     return caret >= start && caret <= end;
 }
Esempio n. 17
0
        /// <summary>
        /// Returns the index of the character under the specified
        /// point in the control, or the nearest character if there
        /// is no character under the point.
        /// </summary>
        /// <param name="txt">The text box control to check.</param>
        /// <param name="pt">The point to find the character for,
        /// specified relative to the client area of the text box.</param>
        /// <returns></returns>
        internal static int CharFromPos(
            System.Windows.Forms.TextBoxBase txt,
            Point pt
            )
        {
            unchecked
            {
                // Convert the point into a DWord with horizontal position
                // in the loword and vertical position in the hiword:
                int xy = (pt.X & 0xFFFF) + ((pt.Y & 0xFFFF) << 16);
                // Get the position from the text box.
                int res = NativeMethods.SendMessageInt(txt.Handle, NativeMethods.EM_CHARFROMPOS, IntPtr.Zero, new IntPtr(xy)).ToInt32();
                // the Platform SDK appears to be incorrect on this matter.
                // the hiword is the line number and the loword is the index
                // of the character on this line
                int lineNumber = ((res & 0xFFFF) >> 16);
                int charIndex  = (res & 0xFFFF);

                // Find the index of the first character on the line within
                // the control:
                int lineStartIndex = NativeMethods.SendMessageInt(txt.Handle, NativeMethods.EM_LINEINDEX,
                                                                  new IntPtr(lineNumber), IntPtr.Zero).ToInt32();
                // Return the combined index:
                return(lineStartIndex + charIndex);
            }
        }
 public static void AppendText(TextBoxBase tb, string text)
 {
     if (tb == null) return;
     tb.SuspendLayout();
     tb.SelectionStart = tb.TextLength;
     tb.SelectedText = text;
     tb.ResumeLayout();
 }
Esempio n. 19
0
 public void SetTxtComp(lib.Visual.Components.sknTextBox txt)
 {
     Type         = txt.TextType == lib.Visual.Components.enmTextType.Int ? TpVinc.Number : TpVinc.Text;
     txt.AutoTab  = false;
     txt.Leave   += new EventHandler(txtCod_Leave);
     txt.KeyDown += new KeyEventHandler(txtCod_KeyDown);
     Text         = txt;
 }
Esempio n. 20
0
        private void CleanInputs(object sender, EventArgs e)
        {
            System.Windows.Forms.TextBoxBase input = (System.Windows.Forms.TextBoxBase)sender;

            if (input.Text.Contains("Пр."))
            {
                input.Text = string.Empty;
            }
        }
Esempio n. 21
0
        public static void Add(TextBoxBase textBox, string message)
        {
            if (textBox.Text == "Log")
              {
            textBox.Text = string.Empty;
              }

              textBox.Text += DateTime.Now + OneSpace + Dash + OneSpace + message + Crlf;
        }
Esempio n. 22
0
 public TextBoxTracer(TextBoxBase t, StringCollection data)
 {
     this.txtLog = t;
     this.logData = data;
     writeAction = s => t.Invoke(new Action(() =>
     {
         t.Text += s;
     }));
 }
Esempio n. 23
0
 /// <summary>
 ///   Restores the selection on the textbox to the saved start and end values. </summary>
 /// <remarks>
 ///   This method checks that the textbox is still <see cref="Disable">available</see>
 ///   and if so restores the selection.  </remarks>
 /// <seealso cref="Disable" />
 public void Restore()
 {
     if (m_textBox == null)
     {
         return;
     }
     m_selection.Set(m_start, m_end);
     m_textBox = null;
 }
Esempio n. 24
0
            /// <summary>
            ///   Initializes a new instance of the Saver class by associating it with a TextBoxBase derived object
            ///   and passing the start and end position of the selection. </summary>
            /// <param name="textBox">
            ///   The TextBoxBase object for which the selection is being saved. </param>
            /// <param name="start">
            ///   The zero-based start position of the selection. </param>
            /// <param name="end">
            ///   The zero-based end position of the selection. It must not be less than the start position. </param>
            /// <remarks>
            ///   This constructor does not save the textbox's start and end position of the selection.
            ///   Instead, it saves the two given parameters. </remarks>
            /// <seealso cref="System.Windows.Forms.TextBoxBase" />
            public Saver(System.Windows.Forms.TextBoxBase textBox, int start, int end)
            {
                m_textBox   = textBox;
                m_selection = new Selection(textBox);
                Debug.Assert(start <= end);

                m_start = start;
                m_end   = end;
            }
 public TextBoxBinding(TextBoxBase textBox, bool readOnly = false, bool nullable = true, bool longText = false)
 {
     this.TextBox = textBox;
     this.TextBox.Multiline = longText;
     this.TextBox.ReadOnly = readOnly;
       if (this.TextBox is TextBox && longText)
     (this.TextBox as TextBox).ScrollBars = ScrollBars.Vertical;
     this.Nullable = nullable;
 }
        /// <summary>
        /// Changes the output display control.
        /// </summary>
        /// <param name="output">The new output.</param>
        public void ChangeDisplay(TextBoxBase output)
        {
            if (output != null)
            {
                _output = output;

                Flush();
            }
        }
Esempio n. 27
0
 /// <summary>
 /// Returns the position of the specified character
 /// </summary>
 /// <param name="txt">The text box to find the character in.</param>
 /// <param name="charIndex">The index of the character whose
 /// position needs to be found.</param>
 /// <returns>The position of the character relative to the client
 /// area of the control.</returns>
 internal static Point PosFromChar(System.Windows.Forms.TextBoxBase txt, int charIndex)
 {
     unchecked
     {
         int xy =
             NativeMethods.SendMessageInt(txt.Handle, NativeMethods.EM_POSFROMCHAR, new IntPtr(charIndex), IntPtr.Zero)
             .ToInt32();
         return(new Point(xy));
     }
 }
Esempio n. 28
0
        // We need to force WriteValue() on TextChanged otherwise it will only call WriteValue()
        // on loss of focus.
        // http://stackoverflow.com/questions/1060080/databound-winforms-control-does-not-recognize-change-until-losing-focus
        /// <summary>
        /// Binds the specified text box
        /// </summary>
        /// <param name="txt"></param>
        /// <param name="b"></param>
        /// <returns></returns>
        public static Binding BindText(TextBoxBase txt, Binding b)
        {
            txt.DataBindings.Add(b);
            txt.TextChanged += (sender, e) =>
            {
                b.WriteValue();
            };

            return b;
        }
Esempio n. 29
0
        /// <summary>
        /// Binds the specified text box
        /// </summary>
        /// <param name="txt"></param>
        /// <param name="dataSource"></param>
        /// <param name="dataMember"></param>
        /// <returns></returns>
        public static Binding BindText(TextBoxBase txt, object dataSource, string dataMember)
        {
            var binding = txt.DataBindings.Add("Text", dataSource, dataMember); //NOXLATE
            txt.TextChanged += (sender, e) =>
            {
                binding.WriteValue();
            };

            return binding;
        }
Esempio n. 30
0
 public static bool ParseInputH(TextBoxBase control, out ulong value)
 {
     if (!ulong.TryParse(control.Text, NumberStyles.HexNumber, CultureInfo.InvariantCulture, out value))
     {
         control.Focus();
         control.SelectAll();
         return false;
     }
     return true;
 }
Esempio n. 31
0
 public static bool ParseInputD(TextBoxBase control, out ulong value)
 {
     if (!ulong.TryParse(control.Text, out value))
     {
         control.Focus();
         control.SelectAll();
         return false;
     }
     return true;
 }
		public RetrieveHotSpotsEventArgs(TextBoxBase control)
		{
			if (control == null)
			{
				throw new ArgumentNullException();
			}
			_color = Color.Red;
			_control = control;
			_hotSpots = new List<HotSpot>();
		}
Esempio n. 33
0
        public static int GetBaselineOffsetAtCharIndex(System.Windows.Forms.TextBoxBase tb, int index)
        {
            System.Windows.Forms.RichTextBox rtb = tb as RichTextBox;
            if (rtb == null)
            {
                return(tb.Font.Height);
            }

            int lineNumber = rtb.GetLineFromCharIndex(index);
            int lineIndex  =
                NativeMethods.SendMessageInt(rtb.Handle, NativeMethods.EM_LINEINDEX, new IntPtr(lineNumber), IntPtr.Zero).
                ToInt32();
            int lineLength =
                NativeMethods.SendMessageInt(rtb.Handle, NativeMethods.EM_LINELENGTH, new IntPtr(lineNumber), IntPtr.Zero).
                ToInt32();


            NativeMethods.CHARRANGE charRange;
            charRange.cpMin = lineIndex;
            charRange.cpMax = lineIndex + lineLength;
            //			charRange.cpMin = index;
            //			charRange.cpMax = index + 1;


            NativeMethods.RECT rect;
            rect.Top    = 0;
            rect.Bottom = (int)anInch;
            rect.Left   = 0;
            rect.Right  = 10000000; //(int)(rtb.Width * anInch + 20);


            NativeMethods.RECT rectPage;
            rectPage.Top    = 0;
            rectPage.Bottom = (int)anInch;
            rectPage.Left   = 0;
            rectPage.Right  = 10;//10000000; //(int)(rtb.Width * anInch + 20);

            Graphics canvas    = Graphics.FromHwnd(rtb.Handle);
            IntPtr   canvasHdc = canvas.GetHdc();

            NativeMethods.FORMATRANGE formatRange;
            formatRange.chrg      = charRange;
            formatRange.hdc       = canvasHdc;
            formatRange.hdcTarget = canvasHdc;
            formatRange.rc        = rect;
            formatRange.rcPage    = rectPage;

            NativeMethods.SendMessage(rtb.Handle, NativeMethods.EM_FORMATRANGE, IntPtr.Zero, ref formatRange).ToInt32();

            canvas.ReleaseHdc(canvasHdc);
            canvas.Dispose();

            return((int)((formatRange.rc.Bottom - formatRange.rc.Top) / anInch));
        }
        public TestOutputListener(TextBoxBase output)
        {
            _output = output;

            if (_output == null)
            {
                throw new ArgumentNullException("output", "Provide an output control");
            }

            Flush();
        }
Esempio n. 35
0
 /*******************************/
 /// <summary>
 /// Selects a range of text in the text box.
 /// </summary>
 /// <param name="textContainer">The current text box.</param>
 /// <param name="start">The position of the first character in the current text selection within the text box.</param>
 /// <param name="offset">The number of characters to select.</param>
 public static void SelectText(System.Windows.Forms.TextBoxBase textContainer, int start, int offset)
 {
     if (offset - start < 0)
     {
         ((System.Windows.Forms.TextBoxBase)textContainer).Select(start, 0);
     }
     else
     {
         ((System.Windows.Forms.TextBoxBase)textContainer).Select(start, offset - start);
     }
 }
 /// <remarks>
 /// GetCharIndexFromPosition is missing one caret position, as there is
 /// one extra caret position than there are characters (an extra one at
 /// the end). See http://stackoverflow.com/a/3874132.
 /// </remarks>
 public static int GetCaretIndex(TextBoxBase @this, Point point)
 {
     point = @this.PointToClient(point);
     var index = @this.GetCharIndexFromPosition(point);
     if (index == (@this.TextLength - 1))
     {
         var caretPoint = @this.GetPositionFromCharIndex(index);
         if (caretPoint.X < point.X) index += 1;
     }
     return index;
 }
Esempio n. 37
0
		/// <summary>
		///   Initializes a new instance of the Behavior class by associating it with a TextBoxBase derived object. </summary>
		/// <param name="textBox">
		///   The TextBoxBase object to associate with this behavior.  It must not be null. </param>
		/// <param name="addEventHandlers">
		///   If true, the textBox's event handlers are tied to the corresponding methods on this behavior object. </param>
		/// <exception cref="ArgumentNullException">textBox is null. </exception>
		/// <remarks>
		///   This constructor is <c>protected</c> since this class is only meant to be used as a base for other behaviors. </remarks>
		/// <seealso cref="System.Windows.Forms.TextBoxBase" />	
		/// <seealso cref="AddEventHandlers" />	
		protected Behavior(TextBoxBase textBox, bool addEventHandlers)
		{
			if (textBox == null)
				throw new ArgumentNullException("textBox");
			
			m_textBox = textBox;
			m_selection = new Selection(m_textBox);
			m_selection.TextChanging += new EventHandler(HandleTextChangingBySelection);
			
			if (addEventHandlers)
				AddEventHandlers();				
		}
Esempio n. 38
0
 internal static void FindRegex(TextBoxBase textBox, Regex regex)
 {
     Match match = regex.Match(textBox.Text, textBox.SelectionLength == 0 ? textBox.SelectionStart : textBox.SelectionStart + textBox.SelectionLength);
     if (!match.Success)
     {
         WikiPad.FindForm.ShowFormattedMessageBox("No further occurences of RegularExpression \"{0}\" have been found.", regex.ToString());
         return;
     }
     textBox.SelectionStart = match.Index;
     textBox.SelectionLength = match.Length;
     textBox.ScrollToCaret();
 }
        public static void ScrollToBottom(TextBoxBase tb)
        {
            const int WM_VSCROLL = 277;
            const int SB_BOTTOM = 7;

            IntPtr ptrWparam = new IntPtr(SB_BOTTOM);
            IntPtr ptrLparam = new IntPtr(0);
            SendMessage(tb.Handle, WM_VSCROLL, ptrWparam, ptrLparam);

            //another solution
            //tb.SelectionStart = tb.TextLength;
            //tb.ScrollToCaret();
        }
Esempio n. 40
0
 public static void CreateQuickInsertMenu(TextBoxBase targetControl, Control popupControl, string[,] quickInsertMenuItems)
 {
     ContextMenuStrip contextMenu = new ContextMenuStrip();
     for (int i = 0; i < quickInsertMenuItems.GetLength(0); ++i) {
         if (quickInsertMenuItems[i, 0] == "-") {
             contextMenu.Items.Add(new MenuSeparator());
         } else {
             MenuCommand cmd = new MenuCommand(quickInsertMenuItems[i, 0],
                                               new QuickInsertMenuHandler(targetControl, quickInsertMenuItems[i, 1]).EventHandler);
             contextMenu.Items.Add(cmd);
         }
     }
     new QuickInsertHandler(popupControl, contextMenu);
 }
 public static void AppendText(TextBoxBase tb, string text)
 {
     if (tb == null) return;
     tb.SuspendLayout();
     if (tb.InvokeRequired)
     {
         tb.Invoke(new AppendTextDelegate(AppendText), new object[] { tb, text });
     }
     else
     {
         tb.SelectionStart = tb.TextLength;
         tb.SelectedText = text;
     }
     tb.ResumeLayout();
 }
Esempio n. 42
0
 public string GetSelection(int selectionNum, out int startOffset, out int endOffset)
 {
     startOffset = endOffset = CaretOffset;
     if (selectionNum != 0)
     {
         return(null);
     }
     SWF.TextBoxBase textBoxBase = TextBoxBase;
     if (TextBoxBase.Document.SelectionVisible)
     {
         startOffset = textBoxBase.SelectionStart;
         endOffset   = startOffset + textBoxBase.SelectionLength;
         return(textBoxBase.Text.Substring(startOffset, endOffset - startOffset));
     }
     return(null);
 }
Esempio n. 43
0
        public static bool Delete()
        {
            bool res = Execute(OnDelete);

            if (!res)
            {
                Control activeControl = Application.ActiveControl;
                if (activeControl == null)
                {
                    return(false);
                }

                System.Windows.Forms.TextBoxBase active = activeControl as System.Windows.Forms.TextBoxBase;
                res = active != null;
                if (res)
                {
                    if (active.SelectionLength != 0)
                    {
                        active.SelectedText = "";
                    }
                    else if (active.Text[active.SelectionStart] != '\r')
                    {
                        active.SelectionLength = 1;
                        active.SelectedText    = "";
                    }
                    else
                    {
                        active.SelectionLength = 2;
                        active.SelectedText    = "";
                    }
                }
                else
                {
                    MethodInfo method = activeControl.GetType().GetMethod("Delete");
                    if (method != null)
                    {
                        Clipboard.FunctionWithoutReturn getMethod = (Clipboard.FunctionWithoutReturn)Delegate.CreateDelegate
                                                                        (typeof(Clipboard.FunctionWithoutReturn), activeControl, method);

                        getMethod();
                        res = true;
                    }
                }
            }
            return(res);
        }
Esempio n. 44
0
        public static bool SelectAll()
        {
            bool res = Execute(OnSelectAll);

            if (!res)
            {
                Control activeControl = Application.ActiveControl;
                if (activeControl == null)
                {
                    return(false);
                }

                System.Windows.Forms.TextBoxBase active = activeControl as System.Windows.Forms.TextBoxBase;
                res = active != null;
                if (res)
                {
                    active.SelectAll();
                }

                if (!res)
                {
                    System.Windows.Forms.WebBrowser webbrowser = activeControl as System.Windows.Forms.WebBrowser;
                    if (webbrowser != null)
                    {
                        WebBrowserHelper.ExecSelectAll(webbrowser);
                        ///TODO: don't work in unix
                        res = true;
                    }
                }

                if (!res)
                {
                    MethodInfo method = activeControl.GetType().GetMethod("SelectAll");
                    if (method != null)
                    {
                        Clipboard.FunctionWithoutReturn getMethod = (Clipboard.FunctionWithoutReturn)Delegate.CreateDelegate
                                                                        (typeof(Clipboard.FunctionWithoutReturn), activeControl, method);

                        getMethod();
                        res = true;
                    }
                }
            }
            return(res);
        }
Esempio n. 45
0
 public static void SetRichTextBoxDropString(System.Windows.Forms.TextBoxBase yourCtr, Action action = null)
 {
     if (yourCtr == null)
     {
         return;
     }
     if (yourCtr is RichTextBox)
     {
         ((RichTextBox)yourCtr).AllowDrop = true;
     }
     else if (yourCtr is TextBox)
     {
         ((TextBox)yourCtr).AllowDrop = true;
     }
     else
     {
         yourCtr.AllowDrop = true;
     }
     yourCtr.DragDrop += (sender, e) =>
     {
         System.Windows.Forms.TextBoxBase tempTextBoxBase = sender as System.Windows.Forms.TextBoxBase;
         string tempText = (string)e.Data.GetData(typeof(string));
         if (tempText == null || tempTextBoxBase == null)
         {
             return;
         }
         int selectionStart = tempTextBoxBase.SelectionStart;
         tempTextBoxBase.Text = tempTextBoxBase.Text.Insert(selectionStart, tempText);
         tempTextBoxBase.Select(selectionStart, tempText.Length);
         action?.Invoke();
     };
     yourCtr.DragEnter += (sender, e) =>
     {
         if (e.Data.GetData(typeof(string)) == null)
         {
             e.Effect = System.Windows.Forms.DragDropEffects.None;
         }
         else
         {
             e.Effect = System.Windows.Forms.DragDropEffects.Move;
         }
     };
 }
Esempio n. 46
0
        internal static int GetTextWidthAtCharIndex(System.Windows.Forms.TextBoxBase tb, int index, int length)
        {
            System.Windows.Forms.RichTextBox rtb = tb as RichTextBox;

            //TODO!
            if (rtb == null)
            {
                return(tb.Font.Height);
            }

            NativeMethods.CHARRANGE charRange;
            charRange.cpMin = index;
            charRange.cpMax = index + length;

            NativeMethods.RECT rect;
            rect.Top    = 0;
            rect.Bottom = (int)anInch;
            rect.Left   = 0;
            rect.Right  = (int)(rtb.ClientSize.Width * anInch);

            NativeMethods.RECT rectPage;
            rectPage.Top    = 0;
            rectPage.Bottom = (int)anInch;
            rectPage.Left   = 0;
            rectPage.Right  = (int)(rtb.ClientSize.Width * anInch);

            Graphics canvas    = Graphics.FromHwnd(rtb.Handle);
            IntPtr   canvasHdc = canvas.GetHdc();

            NativeMethods.FORMATRANGE formatRange;
            formatRange.chrg      = charRange;
            formatRange.hdc       = canvasHdc;
            formatRange.hdcTarget = canvasHdc;
            formatRange.rc        = rect;
            formatRange.rcPage    = rectPage;

            NativeMethods.SendMessage(rtb.Handle, NativeMethods.EM_FORMATRANGE, IntPtr.Zero, ref formatRange);

            canvas.ReleaseHdc(canvasHdc);
            canvas.Dispose();

            return((int)((formatRange.rc.Right - formatRange.rc.Left) / anInch));
        }
Esempio n. 47
0
        /// <summary>附加文本到文本控件末尾。主要解决非UI线程以及滚动控件等问题</summary>
        /// <param name="txt">控件</param>
        /// <param name="msg">消息</param>
        /// <param name="maxLines">最大行数。超过该行数讲清空控件</param>
        /// <returns></returns>
        public static TextBoxBase Append(this TextBoxBase txt, String msg, Int32 maxLines = 1000)
        {
            if (txt.IsDisposed)
            {
                return(txt);
            }

            var func = new Action <String>(m =>
            {
                try
                {
                    if (txt.Lines.Length >= maxLines)
                    {
                        txt.Clear();
                    }

                    // 记录原选择
                    var selstart = txt.SelectionStart;
                    var sellen   = txt.SelectionLength;

                    // 输出日志
                    if (m != null)
                    {
                        //txt.AppendText(m);
                        // 需要考虑处理特殊符号
                        //ProcessBell(ref m);
                        //ProcessBackspace(txt, ref m);
                        //ProcessReturn(txt, ref m);

                        m = m.Trim('\0');
                        // 针对非Windows系统到来的数据,处理一下换行
                        if (txt is RichTextBox && Environment.NewLine == "\r\n")
                        {
                            // 合并多个回车
                            while (m.Contains("\r\r"))
                            {
                                m = m.Replace("\r\r", "\r");
                            }
                            //while (m.Contains("\n\r")) m = m.Replace("\n\r", "\r\n");
                            //m = m.Replace("\r\n", "<TagOfLine>");
                            m = m.Replace("\r\n", "\n");
                            //m = m.Replace("\r", "\r\n");
                            m = m.Replace("\n\r", "\n");
                            // 单独的\r换成\n
                            //if (_line.IsMatch(m))
                            //    m = _line.Replace(m, "\n");
                            m = m.Replace("\r", "\n");
                            //m = m.Replace("\r", null);
                            //m = m.Replace("<TagOfLine>", "\r\n");
                        }
                        if (String.IsNullOrEmpty(m))
                        {
                            return;
                        }
                        txt.AppendText(m);
                    }

                    // 如果有选择,则不要滚动
                    if (sellen > 0)
                    {
                        // 恢复选择
                        if (selstart < txt.TextLength)
                        {
                            sellen = Math.Min(sellen, txt.TextLength - selstart - 1);
                            txt.Select(selstart, sellen);
                            txt.ScrollToCaret();
                        }

                        return;
                    }

                    txt.Scroll();
                }
                catch { }
            });

            //txt.Invoke(func, msg);
            var ar = txt.BeginInvoke(func, msg);

            //ar.AsyncWaitHandle.WaitOne(100);
            //if (!ar.AsyncWaitHandle.WaitOne(10))
            //    txt.EndInvoke(ar);

            return(txt);
        }
Esempio n. 48
0
File: Theme.cs Progetto: yonder/mono
 public abstract bool TextBoxBaseShouldPaintBackground(TextBoxBase textBoxBase);
 public DataGridViewTextBoxEditingControlAccessibleObject(DataGridViewTextBoxEditingControl ownerControl) : base(ownerControl)
 {
     _owningDataGridViewTextBoxEditingControl = ownerControl;
     _textProvider = new TextBoxBaseUiaTextProvider(ownerControl);
     UseTextProviders(_textProvider, _textProvider);
 }
Esempio n. 50
0
File: Theme.cs Progetto: yonder/mono
 public abstract void TextBoxBaseFillBackground(TextBoxBase textBoxBase, Graphics g, Rectangle clippingArea);
Esempio n. 51
0
File: Theme.cs Progetto: yonder/mono
 public abstract bool TextBoxBaseHandleWmNcPaint(TextBoxBase textBoxBase, ref Message m);
Esempio n. 52
0
 internal static int GetFirstVisibleLine(System.Windows.Forms.TextBoxBase txt)
 {
     return(NativeMethods.SendMessageInt(txt.Handle, NativeMethods.EM_GETFIRSTVISIBLELINE, IntPtr.Zero, IntPtr.Zero).ToInt32());
 }
Esempio n. 53
0
        /// <summary>附加文本到文本控件末尾。主要解决非UI线程以及滚动控件等问题</summary>
        /// <param name="txt">控件</param>
        /// <param name="msg">消息</param>
        /// <param name="maxLines">最大行数。超过该行数讲清空控件</param>
        /// <returns></returns>
        public static TextBoxBase Append(this TextBoxBase txt, String msg, Int32 maxLines = 1000)
        {
            if (txt.IsDisposed)
            {
                return(txt);
            }

            var func = new Action <String>(m =>
            {
                try
                {
                    if (txt.Lines.Length >= maxLines)
                    {
                        txt.Clear();
                    }

                    // 记录原选择
                    var selstart = txt.SelectionStart;
                    var sellen   = txt.SelectionLength;

                    // 输出日志
                    if (m != null)
                    {
                        //txt.AppendText(m);
                        // 需要考虑处理特殊符号
                        //ProcessBell(ref m);
                        //ProcessBackspace(txt, ref m);
                        //ProcessReturn(txt, ref m);

                        m = m.Trim('\0');
                        if (String.IsNullOrEmpty(m))
                        {
                            return;
                        }
                        txt.AppendText(m);
                    }

                    // 如果有选择,则不要滚动
                    if (sellen > 0)
                    {
                        // 恢复选择
                        if (selstart < txt.TextLength)
                        {
                            sellen = Math.Min(sellen, txt.TextLength - selstart - 1);
                            txt.Select(selstart, sellen);
                            txt.ScrollToCaret();
                        }

                        return;
                    }

                    txt.Scroll();
                }
                catch { }
            });

            //txt.Invoke(func, msg);
            var ar = txt.BeginInvoke(func, msg);

            //ar.AsyncWaitHandle.WaitOne(100);
            //if (!ar.AsyncWaitHandle.WaitOne(10))
            //    txt.EndInvoke(ar);

            return(txt);
        }
Esempio n. 54
0
 public static void ScrollLineUp(this System.Windows.Forms.TextBoxBase tb)
 {
     SendMessage(tb.Handle, WM_VSCROLL, new IntPtr(SB_LINEUP), new IntPtr(0));
 }
Esempio n. 55
0
 public static void ScrollToBottom(this System.Windows.Forms.TextBoxBase tb)
 {
     SendMessage(tb.Handle, WM_VSCROLL, new IntPtr(SB_BOTTOM), new IntPtr(0));
 }
 public TextBoxBaseUiaTextProvider(TextBoxBase owner)
 {
     _owningTextBoxBase = owner.OrThrowIfNull();
 }
 public TextBoxBase_NSTextView(TextBoxBase owner)
 {
     this.owner = owner;
 }
Esempio n. 58
0
 public ToolStripTextBoxControlAccessibleObject(TextBox toolStripHostedControl, ToolStripControlHost?toolStripControlHost) : base(toolStripHostedControl, toolStripControlHost)
 {
     _owningTextBoxBase = toolStripHostedControl;
     _textProvider      = new TextBoxBaseUiaTextProvider(toolStripHostedControl);
     UseTextProviders(_textProvider, _textProvider);
 }
Esempio n. 59
0
 public TextBoxBase_NSSecureTextField(TextBoxBase owner) : base(owner)
 {
 }
Esempio n. 60
0
 public TextCursor(TextBoxBase owner)
 {
     this.owner = owner;
 }