Esempio n. 1
0
        //-------------------------------------------------------------------------

        /// <summary>
        /// Displays the custom caret on the specified Control. The cursor position
        /// is determined automatically. Only one caret instance can exist at any
        /// given time. Therefore a caret should only be displayed if the
        /// <see cref="Control"/> has focus. This can be automatically achieved by
        /// using <see cref="ApplyBinding"/>. When the caret should not longer be
        /// visible, use <see cref="HideCursor"/>.
        /// </summary>
        /// <param name="control">The caret will be displayed in this control.</param>
        public void DisplayCaret(Control control)
        {
            if (control == null)
            {
                return;
            }
            if (this.originalUserBitmap != null)
            {
                this.image = new Bitmap(this.originalUserBitmap);
                using (BitmapDataHandler pixelData = new BitmapDataHandler(image))
                {
                    pixelData.Enumerate((pixel) =>
                    {
                        pixel.R ^= ParentControl.BackColor.R;
                        pixel.G ^= ParentControl.BackColor.G;
                        pixel.B ^= ParentControl.BackColor.B;
                    });
                }
            }
            else
            {
                int caretHeight = this.height ?? ParentControl.Font.Height;
                this.image = new Bitmap(Width, caretHeight);
                using (Graphics cursorGraphics = Graphics.FromImage(this.image))
                {
                    using (SolidBrush brush = new SolidBrush(XorColorMask(Color, ParentControl.BackColor)))
                    {
                        cursorGraphics.FillRectangle(brush, 0, 0, Width, caretHeight);
                    }
                }
            }
            if (CreateCaret(ParentControl.Handle, this.image.GetHbitmap(), 0, 0))
            {
                ShowCaret(ParentControl.Handle);
            }
        }
Esempio n. 2
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Displays the custom caret on the specified Control. The cursor position
 /// is determined automatically. Only one caret instance can exist at any
 /// given time. Therefore a caret should only be displayed if the
 /// <see cref="Control"/> has focus. This can be automatically achieved by
 /// using <see cref="ApplyBinding"/>. When the caret should not longer be
 /// visible, use <see cref="HideCursor"/>.
 /// </summary>
 /// <param name="control">The caret will be displayed in this control.</param>
 public void DisplayCaret(Control control)
 {
     if (control == null)
       {
     return;
       }
       if (this.originalUserBitmap != null)
       {
     this.image = new Bitmap(this.originalUserBitmap);
     using (BitmapDataHandler pixelData = new BitmapDataHandler(image))
     {
       pixelData.Enumerate((pixel) =>
       {
     pixel.R ^= ParentControl.BackColor.R;
     pixel.G ^= ParentControl.BackColor.G;
     pixel.B ^= ParentControl.BackColor.B;
       });
     }
       }
       else
       {
     int caretHeight = this.height ?? ParentControl.Font.Height;
     this.image = new Bitmap(Width, caretHeight);
     using (Graphics cursorGraphics = Graphics.FromImage(this.image))
     {
       using (SolidBrush brush = new SolidBrush(XorColorMask(Color, ParentControl.BackColor)))
       {
     cursorGraphics.FillRectangle(brush, 0, 0, Width, caretHeight);
       }
     }
       }
       if (CreateCaret(ParentControl.Handle, this.image.GetHbitmap(), 0, 0))
       {
     ShowCaret(ParentControl.Handle);
       }
 }