using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FormsDrawTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//设置TabPage添加滚动条的最小值为(1000, 800)
this.tabControl1.TabPages[0].AutoScrollMinSize = new Size(1000, 800);
}
private void tabPage1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
//平移坐标系
g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);
//绘制矩形和椭圆
g.FillRectangle(Brushes.LightPink, 0, 0, 200, 150);
}
}
}
找到问题了,g.TranslateTransform(this.AutoScrollPosition.X, this.AutoScrollPosition.Y);这一行写错了,用this调用的是Form的AutoScrollPosition,而不是tabpage的,修改为 g.TranslateTransform(tabControl1.TabPages[0].AutoScrollPosition.X, tabControl1.TabPages[0].AutoScrollPosition.Y);就对了
https://blog.csdn.net/suncherrydream/article/details/12105079