首页 > Windows开发 > 详细

C#画图超出屏幕的部分无法显示的问题解决

时间:2020-02-10 15:44:22      阅读:123      评论:0      收藏:0      [点我收藏+]

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

C#画图超出屏幕的部分无法显示的问题解决

原文:https://www.cnblogs.com/ming-4/p/12290732.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!