예제 #1
0
        /// <summary>
        /// Unlock
        /// </summary>
        /// <param name="textBox">textBox</param>
        /// <param name="stateLocked">stateLocked</param>
        private static void Unlock(this TextBoxBase textBox, ref IntPtr stateLocked)
        {
            // turn on events
            SendMessage(textBox.Handle, EM_SETEVENTMASK, 0, stateLocked);
            // turn on redrawing
            SendMessage(textBox.Handle, WM_SETREDRAW, 1, IntPtr.Zero);

            stateLocked = IntPtr.Zero;
            textBox.Invalidate();
        }
예제 #2
0
        /// <summary>
        /// This is called when the textbox is being redrawn.
        /// When it is, for the textbox to get refreshed, call its default
        /// paint method and then call our method
        /// </summary>
        /// <param name="m">The windows message</param>
        /// <remarks></remarks>
        protected override void WndProc(ref System.Windows.Forms.Message m)
        {
            switch (m.Msg)
            {
            case 15:
                //This is the WM_PAINT message
                //Invalidate the textBoxBase so that it gets refreshed properly
                clientTextBox.Invalidate();

                //call the default win32 Paint method for the TextBoxBase first
                base.WndProc(ref m);

                //now use our code to draw the extra stuff
                this.CustomPaint();

                break;

            default:
                base.WndProc(ref m);
                break;
            }
        }
예제 #3
0
        private static void ReplaceText(HotSpot.HotSpot area, string text)
        {
            TextBoxBase control = area.Control;

            control.SelectionStart  = area.Offset;
            control.SelectionLength = area.Text.Length;
            TextBox textBox = control as TextBox;

            if (textBox != null)
            {
                textBox.Paste(text);                 //allows it to be undone
            }
            else
            {
                control.SelectedText = text;
            }
            control.Invalidate();
        }
예제 #4
0
        internal static void SetTabWidth(TextBoxBase textBox, int tabSpaces, double pixelsPerDialogUnit)
        {
            int numTabs        = 0;
            int tabDialogUnits = 0;

            // Note: This only works well for fixed width fonts.  It works
            // ok for some non-fixed fonts like "Comic Sans MS", but it
            // doesn't work for "less monospaced" fonts like "Garamond" or
            // "Georgia".
            //
            // As far as I can tell, this is because I have to return an
            // integral number of dialog units.  I can calculate the correct
            // number of tab pixels for any font, but when I return the
            // integral DLUs for the tab size, it doesn't multiply back to
            // the correct number of pixels (except on monospaced fonts).
            // If only the stupid TextBox would let us pass in pixels instead
            // of dialog units!

            // If tabSpaces is 0 we'll just set the tab stops to the
            // TextBox default of 32 DLUs.
            if (tabSpaces > 0)
            {
                // Get the pixel width that a space should be.
                double spacePixels;
                using (Graphics graphics = Graphics.FromHwnd(textBox.Handle))
                {
                    const TextFormatFlags Flags = TextFormatFlags.TextBoxControl | TextFormatFlags.NoPadding;
                    spacePixels = TextRenderer.MeasureText(graphics, " ", textBox.Font, new Size(int.MaxValue, int.MaxValue), Flags).Width;
                }

                // Convert the pixels to "dialog units"
                int spaceDialogUnits = (int)Math.Ceiling(spacePixels / pixelsPerDialogUnit);
                tabDialogUnits = tabSpaces * spaceDialogUnits;
                numTabs        = 1;
            }

            // LPARAM has to contain a pointer to the new width,
            // so we have to pass that parameter by reference.
            const int EM_SETTABSTOPS = 0x00CB;

            NativeMethods.SendMessage(textBox, EM_SETTABSTOPS, numTabs, ref tabDialogUnits);
            textBox.Invalidate();
        }
예제 #5
0
            protected override void WndProc(ref Message m)
            {
                const int WM_PAINT     = 0xF;
                const int WM_SETFOCUS  = 0x7;
                const int WM_KILLFOCUS = 0x8;

                const int WM_MOUSEMOVE     = 0x200;
                const int WM_LBUTTONDOWN   = 0x201;
                const int WM_RBUTTONDOWN   = 0x204;
                const int WM_MBUTTONDOWN   = 0x207;
                const int WM_LBUTTONUP     = 0x202;
                const int WM_RBUTTONUP     = 0x205;
                const int WM_MBUTTONUP     = 0x208;
                const int WM_LBUTTONDBLCLK = 0x203;
                const int WM_RBUTTONDBLCLK = 0x206;
                const int WM_MBUTTONDBLCLK = 0x209;

                const int WM_KEYDOWN = 0x0100;
                const int WM_KEYUP   = 0x0101;
                const int WM_CHAR    = 0x0102;

                switch (m.Msg)
                {
                case WM_PAINT:
                    base.WndProc(ref m);
                    OnWmPaint();
                    break;

                case WM_SETFOCUS:
                case WM_KILLFOCUS:
                case WM_LBUTTONDOWN:
                case WM_RBUTTONDOWN:
                case WM_MBUTTONDOWN:
                case WM_LBUTTONUP:
                case WM_RBUTTONUP:
                case WM_MBUTTONUP:
                case WM_LBUTTONDBLCLK:
                case WM_RBUTTONDBLCLK:
                case WM_MBUTTONDBLCLK:
                case WM_KEYDOWN:
                case WM_CHAR:
                case WM_KEYUP:
                    base.WndProc(ref m);
                    _control.Invalidate();
                    // if we don't invalidate, then we end up with artifacts from the wave when it is removed
                    break;

                case WM_MOUSEMOVE:                         // Only need to process if a mouse button is down:
                    base.WndProc(ref m);
                    if (!m.WParam.Equals(IntPtr.Zero))
                    {
                        _control.Invalidate();
                        // if we don't invalidate, then we end up with artifacts from the wave when it is removed
                    }
                    break;

#if MONO
                case 0x286:                             //IME_CHAR
                case 0x10F:                             //IME_COMPOSITION
                    //These two messages cause an extra character to be drawn by mono
                    //At this time (Oct 9 2009) we are not sure wether this is a bug with mono
                    //or with our code and we will need to do further testing (also under windows)
                    //For the time being it fixes an annoying bug (Ws-15007) where 4 characters
                    //were being displayed for each keystroke.
                    //See WS-15008 for a full description of the problem and a roadmap for fixing it
//						//base.WndProc(ref m);
                    break;
#endif
                default:
                    base.WndProc(ref m);
                    break;
                }
            }
예제 #6
0
 public void Dispose()
 {
     SendMessage(_tbb.Handle, 0xb, (IntPtr)1, IntPtr.Zero);
     _tbb.Invalidate();
 }