Esempio n. 1
0
 /// <summary>
 /// 隐藏光标,,并设置相关位置
 /// </summary>
 private void OnHideCaret()
 {
     if (!this.defaultIsHideCaret)
     {
         CWinAPICaret.HideCaret(this.Handle);
         this.defaultIsHideCaret = true;
     }
     this.defaultMousePos.iPos      = -1;
     this.defaultMousePos.iArea     = -1;
     this.defaultMousePos.bLeftPos  = false;
     this.defaultMousePos.bRightPos = false;
 }
Esempio n. 2
0
 /// <summary>
 /// 创建光标
 /// </summary>
 private void OnCreateCaret()
 {
     //---获取焦点
     this.Focus();
     //float size = 0.0f;
     //如果没有创建Caret,则创建
     if (!this.defaultIsCreateCaret)
     {
         this.defaultIsCreateCaret = true;
         CWinAPICaret.CreateCaret(this.Handle, IntPtr.Zero, (int)(this.defaultFont.Size), this.defaultFont.Height + this.defaultColStaffWidth);
     }
     if (this.Visible == false)
     {
         this.defaultIsCreateCaret = false;
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 查找输入符
        /// </summary>
        public void OnFindCaret()
        {
            //---获取焦点
            this.Focus();
            this.defaultIsCreateCaret = false;
            //---判断选中行是否合法
            if (this.defaultRowSelectedNum == -1)
            {
                return;
            }
            //---数据选择的列号
            int currentColumn = this.CalcXScaleColIndex();

            //---判断当前列号是否合法
            if (currentColumn == -1)
            {
                return;
            }
            //---计算宽度
            int fontWidth = this.FontWidth();
            //---计算字体的高度
            int fontHeight = this.FontHeigth();
            //---当前起始位置
            Point pointA = this.CalcDataScalePoint();

            if (this.defaultMousePos.bLeftPos)
            {
                pointA.X = pointA.X + currentColumn * (fontWidth + this.defaultRowStaffWidth) + (fontWidth) / 2;
            }
            if (this.defaultMousePos.bRightPos)
            {
                pointA.X = pointA.X + currentColumn * (fontWidth + this.defaultRowStaffWidth) + fontWidth;
            }
            pointA.Y += (this.defaultRowSelectedNum) * (fontHeight + this.defaultColStaffWidth);
            //---显示输入符
            this.OnCreateCaret();
            //---设置输入符的位置
            //CWinAPICaret.SetCaretPos(pointA.X, pointA.Y+1);
            CWinAPICaret.SetCaretPos((pointA.X - this.defaultCaretXOffset), (pointA.Y + this.defaultCaretYOffset));
            //---显示输入符
            CWinAPICaret.ShowCaret(this.Handle);
        }
Esempio n. 4
0
        /// <summary>
        /// 输入符向左移动
        /// </summary>
        private void OnCaretMove_Left()
        {
            if (this.defaultMousePos.iPos != -1 && this.defaultMousePos.iArea != -1)
            {
                this.Focus();

                //---表明在Data区
                if (this.defaultMousePos.iArea == 1)
                {
                    //---获取字体的宽度及长度
                    int fontWidth  = this.FontWidth();
                    int fontHeight = this.FontHeigth();

                    //---查找在第几列
                    int colPosition = this.CalcXScaleColIndex();

                    //---获取所在行的启动信息
                    Point pointA = this.CalcYScaleRowPoint();

                    //---表示在每行的起始位置
                    Point pointB = new Point();
                    if (colPosition == 0)
                    {
                        //---表明在第一个字节的右部
                        if (this.defaultMousePos.bRightPos)
                        {
                            pointB.X = pointA.X + this.defaultRowStaffWidth;
                            pointB.Y = pointA.Y - 2;
                            this.defaultMousePos.bRightPos = false;
                            this.defaultMousePos.bLeftPos  = true;
                            CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                            this.Invalidate();
                            return;
                        }

                        //---表明在第一个字节的左部
                        if (this.defaultMousePos.bLeftPos)
                        {
                            if (this.defaultRowSelectedNum > 0)
                            {
                                this.defaultRowSelectedNum -= 1;
                                pointB.X = pointA.X + defaultRowShowNum * (fontWidth + this.defaultRowStaffWidth) - (fontWidth) / 2;
                                pointB.Y = pointA.Y - fontHeight - this.defaultColStaffWidth - 2;
                                this.defaultMousePos.iPos     -= 1;
                                this.defaultMousePos.bRightPos = true;
                                this.defaultMousePos.bLeftPos  = false;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                this.Invalidate();
                                return;
                            }
                            else if (this.defaultRowSelectedNum == 0 && this.defaultRowNowNum > 0)
                            {
                                this.defaultRowSelectedNum = 0;
                                this.defaultRowNowNum     -= 1;

                                this.defaultVScrollBar.Value = this.defaultRowNowNum;
                                this.Invalidate();
                                pointB.X                       = pointA.X + defaultRowShowNum * (fontWidth + this.defaultRowStaffWidth) - (fontWidth) / 2;
                                pointB.Y                       = pointA.Y;
                                defaultMousePos.iPos          -= 1;
                                this.defaultMousePos.bRightPos = true;
                                this.defaultMousePos.bLeftPos  = false;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                this.Invalidate();
                                return;
                            }
                        }
                    }

                    //---表示不在每行的起始位置
                    else
                    {
                        //---表明在字节的右部
                        if (this.defaultMousePos.bRightPos)
                        {
                            pointB.X = pointA.X + colPosition * (fontWidth + this.defaultRowStaffWidth) + this.defaultRowStaffWidth;
                            pointB.Y = pointA.Y - 2;
                            this.defaultMousePos.bRightPos = false;
                            this.defaultMousePos.bLeftPos  = true;
                            CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                            this.Invalidate();
                            return;
                        }

                        //---表明在字节的左部
                        if (this.defaultMousePos.bLeftPos)
                        {
                            pointB.X = pointA.X + (colPosition - 1) * (fontWidth + this.defaultRowStaffWidth) + this.defaultRowStaffWidth + fontWidth - (fontWidth) / 2;
                            pointB.Y = pointA.Y - 2;
                            this.defaultMousePos.iPos     -= 1;
                            this.defaultMousePos.bRightPos = true;
                            this.defaultMousePos.bLeftPos  = false;
                            CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                            this.Invalidate();
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// 输入符向右移动
        /// </summary>
        private void OnCaretMove_Right()
        {
            if ((this.defaultMousePos.iPos != -1) && (this.defaultMousePos.iArea != -1))
            {
                //---设置输入点
                this.Focus();

                //---光标在数据区域
                if (this.defaultMousePos.iArea == 1)
                {
                    //---计算字体的宽度
                    int fonWidth = this.FontWidth();

                    //---计算字体的高度
                    int fontHeight = this.FontHeigth();

                    //---获取当前的列信息
                    int colPosition = this.CalcXScaleColIndex();

                    //---获取数据所在行的起始信息---仅仅是起始信息
                    Point pointA = this.CalcYScaleRowPoint();

                    //---用于计算光标的二维坐标
                    Point pointB = new Point();

                    //---表明在最后一个字节
                    if (colPosition == (this.defaultRowShowNum - 1))
                    {
                        //---表明在字节的右部
                        if (this.defaultMousePos.bRightPos)
                        {
                            //---计算控件最大可显示的行数
                            int iMaxDataRow = this.defaultMaxRow;                           //this.CalcYScaleMaxRow();
                            //---计算实际的行数
                            int iDataRow = this.defaultTotalRow;                            // this.CalcYScaleTotalRow();
                            //---判断选择数据所在的行号-----从1开始
                            if (this.defaultRowSelectedNum < (iMaxDataRow - 1))
                            {
                                this.defaultRowSelectedNum++;
                                //---为了避免光标在最后一个位置,依然能够移动位置
                                if (this.defaultRowSelectedNum != iDataRow)
                                {
                                    pointB.X = pointA.X + this.defaultRowStaffWidth;
                                    pointB.Y = pointA.Y + fontHeight + this.defaultColStaffWidth - 2;
                                    this.defaultMousePos.iPos += 1;

                                    //---设置光标的位置;同时置位光标的位置标志
                                    this.defaultMousePos.bRightPos = false;
                                    this.defaultMousePos.bLeftPos  = true;
                                    CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                }
                                else
                                {
                                    //---保持光标位置不变,选择的列号页不变
                                    this.defaultRowSelectedNum -= 1;

                                    //---最后一行数据的最后一个数据---位置信息保留
                                    this.defaultMousePos.bRightPos = true;
                                    this.defaultMousePos.bLeftPos  = false;
                                }

                                //---重新绘制窗体
                                this.Invalidate();
                                return;
                            }
                            else if ((this.defaultRowSelectedNum == (iMaxDataRow - 1) && (iDataRow - this.defaultRowNowNum - iMaxDataRow) > 0))
                            {
                                this.defaultRowNowNum       += 1;
                                this.defaultVScrollBar.Value = this.defaultRowNowNum;
                                this.Invalidate();

                                pointB.X = pointA.X + this.defaultRowStaffWidth;
                                pointB.Y = pointA.Y - 2;
                                this.defaultMousePos.iPos     += 1;
                                this.defaultMousePos.bRightPos = false;
                                this.defaultMousePos.bLeftPos  = true;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                return;
                            }

                            //---如果本窗体的最后一行且是最后一个数据,则如下处理
                            else if ((this.defaultRowSelectedNum == (iMaxDataRow - 1) && (iDataRow - this.defaultRowNowNum - iMaxDataRow) == 0))
                            {
                                //SetCaretPos( pt.X, pt.Y );
                                this.Invalidate();
                                return;
                            }
                        }

                        //---表明在字节的左部
                        if (this.defaultMousePos.bLeftPos)
                        {
                            //---用于显示光标位置
                            pointB.X = pointA.X + colPosition * (fonWidth + this.defaultRowStaffWidth) + this.defaultRowStaffWidth + (fonWidth) / 2;
                            pointB.Y = pointA.Y - 2;
                            this.defaultMousePos.bRightPos = true;
                            this.defaultMousePos.bLeftPos  = false;
                            CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                            this.Invalidate();
                            return;
                        }
                    }
                    else
                    {
                        //---表明在字节的右部
                        if (this.defaultMousePos.bRightPos)
                        {
                            //---判定是否在最后一个字节
                            if ((this.defaultMousePos.iPos + 1) >= (this.mNowData.Length))
                            {
                                return;
                            }

                            pointB.X = pointA.X + (colPosition + 1) * (fonWidth + this.defaultRowStaffWidth) + this.defaultRowStaffWidth;
                            pointB.Y = pointA.Y - 2;
                            this.defaultMousePos.iPos     += 1;
                            this.defaultMousePos.bRightPos = false;
                            this.defaultMousePos.bLeftPos  = true;
                            CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                            this.Invalidate();
                            return;
                        }

                        //---表明在字节的左部
                        if (this.defaultMousePos.bLeftPos)
                        {
                            pointB.X = pointA.X + colPosition * (fonWidth + this.defaultRowStaffWidth) + this.defaultRowStaffWidth + (fonWidth) / 2;
                            pointB.Y = pointA.Y - 2;
                            this.defaultMousePos.bRightPos = true;
                            this.defaultMousePos.bLeftPos  = false;
                            CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                            this.Invalidate();
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        /// <summary>
        /// 鼠标按下的处理-----用于获取光标的位置------显示光标的信息
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseDown(MouseEventArgs e)
        {
            if ((this.defaultNowData == null) || (this.defaultNowData.Length == 0))
            {
                return;
            }
            else
            {
                if (e.Button == MouseButtons.Left)
                {
                    //---获取焦点
                    this.Focus();

                    //---记录鼠标的坐标
                    Point mousePoint = new Point(e.X, e.Y);
                    //---获取地址栏的起始位置
                    Point pointA = this.CalcYScalePoint();
                    //---计算字体的宽度
                    int fontWidth = this.FontWidth();
                    //---计算字体的高度
                    int fontHeight = this.FontHeigth();
                    //---计算当前控件能够显示的最大行数
                    int iMaxRowCount = this.defaultMaxRow;                    //this.CalcYScaleMaxRow();
                    //---计算数据需要显示的行数
                    int iTotalRowCount = this.defaultTotalRow;                // this.CalcYScaleTotalRow();
                    //---判断鼠标左键是否是右侧的空白位置
                    if ((mousePoint.X < this.defaultDataStartHeight) || (mousePoint.X > (this.defaultDataStartWidth - 10)))
                    {
                        return;
                    }

                    //---判定是否在当前行中
                    Rectangle nowRectangle = new Rectangle();

                    Region nowRegion;

                    //---高度
                    int iHeight = pointA.Y;

                    #region  标位于地址区域	-----获取当前选中的行号

                    for (int ix = this.defaultRowNowNum; ix < this.defaultRowNowNum + iMaxRowCount; ix++)
                    {
                        if (iTotalRowCount <= ix)
                        {
                            //---表明没有选中行
                            this.defaultRowSelectedNum = -1;
                            break;
                        }
                        else
                        {
                            //---计算矩形区域的尺寸
                            nowRectangle.X      = pointA.X;
                            nowRectangle.Y      = iHeight;
                            nowRectangle.Width  = this.Width - this.defaultExternalLineWidth;
                            nowRectangle.Height = fontHeight + this.defaultColStaffWidth;

                            //---指示由矩形和由路径构成的图形形状的内部
                            nowRegion = new Region(nowRectangle);

                            //---判断是否找到光标的位置
                            if (nowRegion.IsVisible(mousePoint))
                            {
                                //---表明选中了某一行
                                this.defaultRowSelectedNum = ix - this.defaultRowNowNum;

                                //---重新绘制控件
                                this.Invalidate();
                                break;
                            }
                            iHeight += fontHeight + this.defaultColStaffWidth;
                        }
                    }

                    //---判断是否是本行被选中
                    if (this.defaultRowSelectedNum == -1)
                    {
                        //---没有选中行
                        return;
                    }
                    #endregion

                    #region  标位于数据区域-----用于创建光标

                    Point poinaB;

                    int dataOffset = 0;

                    if (this.defaultYScaleShow)
                    {
                        dataOffset = this.defaultExternalLineWidth / 2 + this.defaultYScaleWidth;
                    }
                    else
                    {
                        dataOffset = this.defaultExternalLineWidth / 2;
                    }
                    poinaB = new Point(dataOffset, pointA.Y);

                    //---计算位置
                    nowRectangle.X     = poinaB.X;
                    nowRectangle.Y     = poinaB.Y + this.defaultRowSelectedNum * (fontHeight + this.defaultColStaffWidth);
                    nowRectangle.Width = this.defaultRowShowNum * (this.defaultRowStaffWidth + fontWidth);

                    nowRectangle.Height = fontHeight + this.defaultColStaffWidth;

                    //---断鼠标左键是否是左侧的空白位置
                    if (mousePoint.X < this.defaultDataEndWidth)
                    {
                        //---创建光标
                        this.OnCreateCaret();
                        //---设置光标
                        CWinAPICaret.SetCaretPos((this.defaultDataEndWidth + 8), (nowRectangle.Y + this.defaultCaretYOffset / 2));
                        //---显示光标
                        CWinAPICaret.ShowCaret(this.Handle);
                        this.defaultIsHideCaret        = false;
                        this.defaultMousePos.iPos      = (this.defaultRowNowNum + this.defaultRowSelectedNum) * this.defaultRowShowNum + 0;
                        this.defaultMousePos.iArea     = 1;
                        this.defaultMousePos.bLeftPos  = true;
                        this.defaultMousePos.bRightPos = false;
                        return;
                    }

                    nowRegion = new Region(nowRectangle);

                    //鼠标在指定的区域内
                    if (nowRegion.IsVisible(mousePoint))
                    {
                        //---创建光标
                        this.OnCreateCaret();
                        int iDataOffset = nowRectangle.X + this.defaultRowStaffWidth;
                        int iDataHeight = nowRectangle.Y;

                        //---遍历查找光标的位置
                        for (int iy = 0; iy < this.defaultRowShowNum; iy++)
                        {
                            nowRectangle.X      = iDataOffset;
                            nowRectangle.Y      = iDataHeight;
                            nowRectangle.Width  = fontWidth / 2;
                            nowRectangle.Height = fontHeight + this.defaultColStaffWidth;
                            nowRegion           = new Region(nowRectangle);

                            //---数据的左边
                            if (nowRegion.IsVisible(mousePoint))
                            {
                                //---设置光标
                                CWinAPICaret.SetCaretPos((nowRectangle.X - this.defaultCaretXOffset), (nowRectangle.Y + this.defaultCaretYOffset / 2));
                                //---显示光标
                                CWinAPICaret.ShowCaret(this.Handle);
                                this.defaultIsHideCaret        = false;
                                this.defaultMousePos.iPos      = (this.defaultRowNowNum + this.defaultRowSelectedNum) * this.defaultRowShowNum + iy;
                                this.defaultMousePos.iArea     = 1;
                                this.defaultMousePos.bLeftPos  = true;
                                this.defaultMousePos.bRightPos = false;
                                break;
                            }
                            nowRectangle.X    += (fontWidth + 1) / 2;
                            nowRectangle.Width = (fontWidth + 3) / 2 + this.defaultRowStaffWidth;
                            nowRegion          = new Region(nowRectangle);

                            //---数据的右边
                            if (nowRegion.IsVisible(mousePoint))
                            {
                                //---设置光标
                                CWinAPICaret.SetCaretPos((nowRectangle.X - this.defaultCaretXOffset), (nowRectangle.Y + this.defaultCaretYOffset / 2));
                                //---显示光标
                                CWinAPICaret.ShowCaret(this.Handle);
                                this.defaultIsHideCaret        = false;
                                this.defaultMousePos.iPos      = (this.defaultRowNowNum + this.defaultRowSelectedNum) * this.defaultRowShowNum + iy;
                                this.defaultMousePos.iArea     = 1;
                                this.defaultMousePos.bLeftPos  = false;
                                this.defaultMousePos.bRightPos = true;

                                break;
                            }
                            iDataOffset += fontWidth + this.defaultRowStaffWidth;
                        }

                        //---如果点击区域超过最大值,则不显示
                        if (this.defaultMousePos.iPos != -1 && this.defaultMousePos.iPos >= this.defaultNowData.Length)
                        {
                            this.OnHideCaret();
                        }

                        //---添加---注销
                        nowRegion.Dispose();
                    }
                    else
                    {
                        this.OnHideCaret();
                    }
                    #endregion
                }
            }

            //处理基类鼠标按下的事件
            //base.OnMouseDown( e );
        }
Esempio n. 7
0
        /// <summary>
        /// 输入符向下移动
        /// </summary>
        private void OnCaretMove_Down()
        {
            if (defaultMousePos.iPos != -1 && defaultMousePos.iArea != -1)
            {
                //---获取焦点
                //this.Focus();

                //----表明在Data区
                if (defaultMousePos.iArea == 1)
                {
                    //---获取字体的宽度及长度
                    int iFontWidth  = this.FontWidth();
                    int iFontHeight = this.FontHeigth();

                    //---查找在第几列
                    int iColumn = this.CalcXScaleColIndex();
                    //---获取所在行的启动信息
                    Point pointA = this.CalcYScaleRowPoint();
                    //---计算最大显示行数
                    int iMaxDataRow = this.defaultMaxRow;                    //this.CalcYScaleMaxRow();
                    //---计算实际数据可显示的行数
                    int iTotalDataRow = this.defaultTotalRow;                // this.CalcYScaleTotalRow();
                    //---进行判定
                    Point pointB = new Point();
                    if ((this.defaultMousePos.iPos + defaultRowShowNum) < (this.mNowData.Length))
                    {
                        if (defaultRowSelectedNum < iMaxDataRow - 1)
                        {
                            defaultRowSelectedNum += 1;

                            //---表明在第一个字节的右部
                            if (defaultMousePos.bRightPos)
                            {
                                pointB.X = pointA.X + iColumn * (iFontWidth + defaultRowStaffWidth) + defaultRowStaffWidth + (iFontWidth) / 2;
                                pointB.Y = pointA.Y + iFontHeight + defaultColStaffWidth - 2;

                                defaultMousePos.iPos     += defaultRowShowNum;
                                defaultMousePos.bRightPos = true;
                                defaultMousePos.bLeftPos  = false;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                this.Invalidate();
                                return;
                            }

                            //---表明在第一个字节的左部
                            if (defaultMousePos.bLeftPos)
                            {
                                pointB.X = pointA.X + iColumn * (iFontWidth + defaultRowStaffWidth) + defaultRowStaffWidth;
                                pointB.Y = pointA.Y + iFontHeight + defaultColStaffWidth - 2;

                                defaultMousePos.iPos     += defaultRowShowNum;
                                defaultMousePos.bRightPos = false;
                                defaultMousePos.bLeftPos  = true;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                this.Invalidate();
                                return;
                            }
                        }
                        else
                        {
                            defaultRowNowNum += 1;

                            //---表明在第一个字节的右部
                            if (defaultMousePos.bRightPos)
                            {
                                pointB.X = pointA.X + iColumn * (iFontWidth + defaultRowStaffWidth) + defaultRowStaffWidth + (iFontWidth) / 2;
                                pointB.Y = pointA.Y;

                                defaultMousePos.iPos     += defaultRowShowNum;
                                defaultMousePos.bRightPos = true;
                                defaultMousePos.bLeftPos  = false;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                this.defaultVScrollBar.Value = defaultRowNowNum;
                                this.Invalidate();
                                return;
                            }

                            //---表明在第一个字节的左部
                            if (defaultMousePos.bLeftPos)
                            {
                                pointB.X = pointA.X + iColumn * (iFontWidth + defaultRowStaffWidth) + defaultRowStaffWidth;
                                pointB.Y = pointA.Y;

                                defaultMousePos.iPos     += defaultRowShowNum;
                                defaultMousePos.bRightPos = false;
                                defaultMousePos.bLeftPos  = true;
                                CWinAPICaret.SetCaretPos((pointB.X - this.defaultCaretXOffset), (pointB.Y + this.defaultCaretYOffset));
                                this.defaultVScrollBar.Value = defaultRowNowNum;
                                this.Invalidate();
                                return;
                            }
                        }
                    }
                }
            }
        }