Exemple #1
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);
        }
Exemple #2
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 );
        }