我准备在Pane 用GDI l水平方向放20个红色矩形 垂直方向放20个红色矩形 。
在这种情况下 希望能得到滚动条,查看20个矩形。实际没有滚动条。
看网上说可以 我怎么实现不了
************************************初始化代码
void initData()
{
g = this.CreateGraphics();//将图形画在窗体上
g = pictureBox1.CreateGraphics();//将图形画在panel1控件上
pen = new Pen(color, 3);//创建一个画笔对象,该画笔的颜色为红色,笔触大小为3个像素
brush = new SolidBrush(Color.FromArgb(255, 0, 0));//设置画刷的颜色为红色
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
panel1.AutoScrollMinSize = new Size(10, 10);
}
private void Form1_Load(object sender, EventArgs e)
{
initData();
}
*****************************************生成矩形代码
private void button3_Click(object sender, EventArgs e)
{
int X_Point,Y_Point;
int Rectangle_long;
int Rectangle_Width;
int i;
X_Point = 50;
Y_Point = 50;
Rectangle_long = 50;
Rectangle_Width = 10;
for (i = 0; i < 20; i++)
{
Y_Point = 50*(i+1);
X_Point = 50;
g.DrawRectangle(pen, X_Point, Y_Point, Rectangle_long, Rectangle_Width);
g.FillRectangle(brush, X_Point, Y_Point, Rectangle_long, Rectangle_Width);
}
for (i = 0; i < 20; i++)
{
X_Point = 100 * (i + 1)+ Rectangle_long+30;
Y_Point = 50;
g.DrawRectangle(pen, X_Point, Y_Point, Rectangle_long, Rectangle_Width);
g.FillRectangle(brush, X_Point, Y_Point, Rectangle_long, Rectangle_Width);
}
}