Exemplo n.º 1
0
 /// <summary>
 /// 已重载:获得焦点,显示光标
 /// </summary>
 /// <param name="e"></param>
 protected override void OnGotFocus(EventArgs e)
 {
     if (bolCaretCreated && myCaretBounds.IsEmpty == false && this.Focused)
     {
         myCaret.Create(0, myCaretBounds.Width, myCaretBounds.Height);
         myCaret.SetPos(myCaretBounds.X, myCaretBounds.Y);
         myCaret.Show();
     }
     base.OnGotFocus(e);
 }
Exemplo n.º 2
0
        /// <summary>
        /// 移动光标到新的光标区域
        /// </summary>
        /// <param name="vLeft">在视图中光标区域的左端位置</param>
        /// <param name="vTop">在视图中光标区域的顶端位置</param>
        /// <param name="vWidth">光标区域宽度</param>
        /// <param name="vHeight">光标区域高度</param>
        /// <returns>移动光标是否造成滚动</returns>
        public bool MoveCaretTo(
            int vLeft,
            int vTop,
            int vWidth,
            int vHeight)
        {
            //return false;

            if (this.IsUpdating)
            {
                return(false);
            }
            if (this.ForceShowCaret == false &&
                this.Focused == false)
            {
                if (this.CaretCreated)
                {
                    this.Caret.Hide();
                }
                //this.ScrollToView( vLeft , vTop , vWidth , vHeight );
                return(false);
            }

            int height = GraphicsUnitConvert.Convert(
                vHeight,
                this.GraphicsUnit,
                System.Drawing.GraphicsUnit.Pixel);

            if (vWidth > 0 && vHeight > 0)
            {
                bolCaretCreated = this.Caret.Create(0, vWidth, height);
                if (this.CaretCreated)
                {
                    if (bolMoveCaretWithScroll)
                    {
                        this.ScrollToView(vLeft, vTop, vWidth, vHeight);
                    }
                    System.Drawing.Point p = this.ViewPointToClient(vLeft, vTop);
                    myCaret.SetPos(p.X, p.Y);
                    myCaret.Show();
                    Win32Imm imm = new Win32Imm(this);
                    if (imm.IsImmOpen())
                    {
                        imm.SetImmPos(p);
                    }
                    myCaretBounds = new System.Drawing.Rectangle(
                        p.X,
                        p.Y,
                        vWidth,
                        height);
                    if (this.MoveCaretWithScroll)
                    {
                        return(true);
                    }
                }
            }
            return(false);
        }