Exemplo n.º 1
0
        /// <summary>
        /// 移动可视区域
        /// </summary>
        /// <param name="p"></param>
        public void MoveRegion(Point p)
        {
            activated = false;

            if (currentCanvas != null && (graphSetting.CanvasScale == 1.0f))
            {
                if (tracking) // 可视绘图区域
                {
                    int horizontalValue = (int)((p.X - lastMovePoint.X) / horizontalScale);
                    int verticalValue   = (int)((p.Y - lastMovePoint.Y) / verticalScale);
                    currentCanvas.Visible = false; // 避免闪烁

                    if (regionLocation.X + horizontalValue >= 0 &&
                        regionLocation.X + regionSize.Width + horizontalValue <= currentCanvas.AutoScrollMinSize.Width &&
                        currentCanvas.HorizontalScroll.Value + horizontalValue >= currentCanvas.HorizontalScroll.Minimum &&
                        currentCanvas.HorizontalScroll.Value + horizontalValue <= currentCanvas.HorizontalScroll.Maximum)
                    {
                        currentCanvas.HorizontalScroll.Value += horizontalValue;
                    }
                    else
                    {
                        if (horizontalValue > 0) // 向右移动可视区域
                        {
                            currentCanvas.HorizontalScroll.Value = currentCanvas.HorizontalScroll.Maximum;
                        }
                        else // 向左移动可视区域
                        {
                            currentCanvas.HorizontalScroll.Value = currentCanvas.HorizontalScroll.Minimum;
                        }
                    }

                    if (regionLocation.Y + verticalValue >= 0 &&
                        regionLocation.Y + regionSize.Height + verticalValue <= currentCanvas.AutoScrollMinSize.Height &&
                        currentCanvas.VerticalScroll.Value + verticalValue >= currentCanvas.VerticalScroll.Minimum &&
                        currentCanvas.VerticalScroll.Value + verticalValue <= currentCanvas.VerticalScroll.Maximum)
                    {
                        currentCanvas.VerticalScroll.Value += verticalValue;
                    }
                    else
                    {
                        if (verticalValue > 0) // 向下移动可视区域
                        {
                            currentCanvas.VerticalScroll.Value = currentCanvas.VerticalScroll.Maximum;
                        }
                        else // 向上移动可视区域
                        {
                            currentCanvas.VerticalScroll.Value = currentCanvas.VerticalScroll.Minimum;
                        }
                    }

                    lastMovePoint         = p;
                    currentCanvas.Visible = true;
                    this.Refresh();
                    currentCanvas.Refresh();
                }
                else
                {
                    if (IsInRegion(p)) // 激活可视区域
                    {
                        activated       = true;
                        tooltipLocation = p;
                    }

                    Invalidate();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// 移动可视区域
        /// </summary>
        /// <param name="p"></param>
        public void MoveRegion(Point p)
        {
            activated = false;

            if (currentCanvas != null)
            {
                if (tracking) // 可视绘图区域
                {
                    int  horizontalValue       = p.X - lastMovePoint.X;
                    int  verticalValue         = p.Y - lastMovePoint.Y;
                    int  horizontalScrollValue = (int)(horizontalValue * entireRegionSize.Width / this.Size.Width);
                    int  verticalScrollValue   = (int)(verticalValue * entireRegionSize.Height / this.Size.Height);
                    bool changeLocation        = false; // 是否改变可视区域位置

                    currentCanvas.Visible = false;      // 避免闪烁

                    if (regionLocation.X + horizontalValue >= 0 &&
                        regionLocation.X + regionSize.Width + horizontalValue <= this.Size.Width &&
                        currentCanvas.HorizontalScroll.Value + horizontalScrollValue >= currentCanvas.HorizontalScroll.Minimum &&
                        currentCanvas.HorizontalScroll.Value + horizontalScrollValue <= currentCanvas.HorizontalScroll.Maximum)
                    {
                        currentCanvas.HorizontalScroll.Value += horizontalScrollValue;
                        changeLocation = true;
                    }
                    else
                    {
                        if (horizontalValue > 0) // 向右移动可视区域
                        {
                            horizontalValue       = this.Size.Width - regionSize.Width - regionLocation.X;
                            horizontalScrollValue = (int)(horizontalValue * entireRegionSize.Width / this.Size.Width);
                            currentCanvas.HorizontalScroll.Value = currentCanvas.HorizontalScroll.Maximum;
                        }
                        else // 向左移动可视区域
                        {
                            horizontalValue       = -regionLocation.X;
                            horizontalScrollValue = (int)(horizontalValue * entireRegionSize.Width / this.Size.Width);
                            currentCanvas.HorizontalScroll.Value = currentCanvas.HorizontalScroll.Minimum;
                        }
                    }

                    if (regionLocation.Y + verticalValue >= 0 &&
                        regionLocation.Y + regionSize.Height + verticalValue <= this.Size.Height &&
                        currentCanvas.VerticalScroll.Value + verticalScrollValue >= currentCanvas.VerticalScroll.Minimum &&
                        currentCanvas.VerticalScroll.Value + verticalScrollValue <= currentCanvas.VerticalScroll.Maximum)
                    {
                        currentCanvas.VerticalScroll.Value += verticalScrollValue;
                        changeLocation = true;
                    }
                    else
                    {
                        if (verticalValue > 0) // 向下移动可视区域
                        {
                            verticalValue       = this.Size.Height - regionSize.Height - regionLocation.Y;
                            verticalScrollValue = (int)(verticalValue * entireRegionSize.Height / this.Size.Height);
                            currentCanvas.VerticalScroll.Value = currentCanvas.VerticalScroll.Maximum;
                        }
                        else // 向上移动可视区域
                        {
                            verticalValue       = -regionLocation.Y;
                            verticalScrollValue = (int)(verticalValue * entireRegionSize.Height / this.Size.Height);
                            currentCanvas.VerticalScroll.Value = currentCanvas.VerticalScroll.Minimum;
                        }
                    }

                    if (changeLocation)
                    {
                        regionLocation += new Size(horizontalValue, verticalValue);
                    }

                    lastMovePoint         = p;
                    currentCanvas.Visible = true;
                    this.Refresh();
                    currentCanvas.Refresh();
                }
                else
                {
                    if (IsInRegion(p)) // 激活可视区域
                    {
                        activated       = true;
                        tooltipLocation = p;
                    }

                    Invalidate(ClientRectangle);
                }
            }
        }