Exemple #1
0
        /// <summary>
        /// 切换可视区域的位置
        /// </summary>
        /// <param name="p">当前点位置</param>
        private void ChangeVisibleRegionLocation(Point p)
        {
            if (currentCanvas != null && (graphSetting.CanvasScale == 1.0f))
            {
                int horizontalValue = (int)((p.X - validRegion.X) / horizontalScale - regionLocation.X - regionSize.Width / 2);
                int verticalValue   = (int)((p.Y - validRegion.Y) / verticalScale - regionLocation.Y - regionSize.Height / 2);
                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;
                    }
                }

                selected              = true;
                lastMovePoint         = p;
                currentCanvas.Visible = true;
                this.Invalidate();
                currentCanvas.Invalidate();
            }
        }
Exemple #2
0
        /// <summary>
        /// 切换可视区域的位置
        /// </summary>
        /// <param name="p">当前点位置</param>
        private void ChangeVisibleRegionLocation(Point p)
        {
            if (currentCanvas != null)
            {
                int horizontalValue       = p.X - regionLocation.X - (int)(regionSize.Width / 2);
                int verticalValue         = p.Y - regionLocation.Y - (int)(regionSize.Height / 2);
                int horizontalScrollValue = (int)(horizontalValue * entireRegionSize.Width / this.Size.Width);
                int verticalScrollValue   = (int)(verticalValue * entireRegionSize.Height / this.Size.Height);

                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;
                }
                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;
                }
                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;
                    }
                }

                selected              = true;
                regionLocation       += new Size(horizontalValue, verticalValue);
                lastMovePoint         = p;
                currentCanvas.Visible = true;
                this.Invalidate();
                currentCanvas.Invalidate();
            }
        }