C#畫圖超出屏幕的部分無法顯示的解決方法


C#畫圖超出屏幕的部分無法顯示,通過AutoScrollMinSize屬性及相關方法解決問題。

可以實現

 

 到

 

 的轉變。

代碼如下:

using System.Drawing;
using System.Windows.Forms;

namespace drawing_test
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.AutoScrollMinSize = new Size(250, 350);//解決問題需添加
        }

        private Point rectangleTopLeft = new Point(0, 0);
        private Size rectangleSize = new Size(200, 200);
        private Point ellipseTopLeft = new Point(50, 200);
        private Size ellipseSize = new Size(200, 150);
        private Pen bluePen = new Pen(Color.Blue, 3);
        private Pen redPen = new Pen(Color.Red, 2);

        private void OnPaint(object sender, PaintEventArgs e)
        {
            Graphics dc = e.Graphics;
            Size scrollOffset = new Size(this.AutoScrollPosition);//解決問題需添加

            Rectangle rectangleArea = new Rectangle(rectangleTopLeft + scrollOffset, rectangleSize);//解決問題需修改
            Rectangle ellipseArea = new Rectangle(ellipseTopLeft + scrollOffset, ellipseSize);//解決問題需修改

            dc.DrawRectangle(bluePen, rectangleArea);
            dc.DrawEllipse(redPen, ellipseArea);
        }
    }
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM