楼主想要通过按钮(只有在点击后才会出现那张图自己画的图)来实现在Form1上画一张图(图的大小大于窗口的大小,所以设置了滚动条),但是在点击以后就在窗口中出现了话的一部分,但是当楼主想拖动滚动条的时候不仅以前未显示的部分没有出现,而且原来的那部分也不见了;代码如下using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 重绘1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AutoScroll = true;
this.BackColor = Color.Pink;
this.AutoScrollMinSize = new Size(10000, 10000);
}
private void weizhi(PaintEventArgs e)
{
Point startPoint=new Point (0,0);
Size location = new Size(1000, 1000);
Rectangle rectangle = new Rectangle(startPoint,location);
e.Graphics.Clip = new Region(rectangle );
}
private void button1_Click(object sender, EventArgs e)
{
huahua();
}
private void huahua()
{
Graphics g = CreateGraphics();
Point startPoint = new Point(0, 0);
Point endPoint = new Point(800, 800);
SolidBrush brush = new SolidBrush(Color.Green);
Pen pen = new Pen(brush, 18);
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
g.FillEllipse(brush, 0, 0, 120, 120);
g.DrawEllipse(pen, 120, 120, 300, 300);
g.DrawLine(pen, startPoint, endPoint);
g.Dispose();
pen.Dispose();this.BackColor = Color.Pink;
brush.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
Graphics g = CreateGraphics();
g.Clear(Color.White);
g.Dispose();
}
}
}
类重绘
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;namespace 重绘1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.AutoScroll = true;
this.BackColor = Color.Pink;
this.AutoScrollMinSize = new Size(10000, 10000);
}
private void weizhi(PaintEventArgs e)
{
Point startPoint=new Point (0,0);
Size location = new Size(1000, 1000);
Rectangle rectangle = new Rectangle(startPoint,location);
e.Graphics.Clip = new Region(rectangle );
}
private void button1_Click(object sender, EventArgs e)
{
huahua();
}
private void huahua()
{
Graphics g = CreateGraphics();
Point startPoint = new Point(0, 0);
Point endPoint = new Point(800, 800);
SolidBrush brush = new SolidBrush(Color.Green);
Pen pen = new Pen(brush, 18);
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
g.FillEllipse(brush, 0, 0, 120, 120);
g.DrawEllipse(pen, 120, 120, 300, 300);
g.DrawLine(pen, startPoint, endPoint);
g.Dispose();
pen.Dispose();this.BackColor = Color.Pink;
brush.Dispose();
}
private void button2_Click(object sender, EventArgs e)
{
Graphics g = CreateGraphics();
g.Clear(Color.White);
g.Dispose();
}
}
}
类重绘
解决方案 »
- 请问在.NET的Web应用程序开发中,使用WCF和WebService编程的主要区别主要在哪里?
- c# 时间计算问题
- C#连接SQL Server 标准版2005(正版)时,服务器程序可以,但客户机连接时有的机器可以,有的报错
- 关于进度显示方法的问题
- 大家看一下你自已的MSDN FOR VS2005有没有Font类的13个构造函数的说明,MSDN FOR VS2003却很完整喔??
- 恳请高手指点:ASP.NET里使用强名称Excel组件的权限问题
- 关于汉字与键码的问题
- 正则表达式分析网页中图片的URL地址
- 未在本地计算机上注册VFPOLEDB提供程序。
- C# Dictionar根据键值查找值得函数是什么?怎么用?
- 请教窗体传值问题
- 接口有什么用啊,语法格式很明白了,但是感觉没什么作用
public partial class Form1 : Form
{
bool bPaint = false;
public Form1()
{
InitializeComponent(); this.AutoScroll = true;
this.BackColor = Color.Pink;
this.AutoScrollMinSize = new Size(10000, 10000); Paint += new PaintEventHandler(Form1_Paint);
} void Form1_Paint(object sender, PaintEventArgs e)
{
if (bPaint)
{
huahua(e.Graphics);
}
} private void weizhi(PaintEventArgs e)
{
Point startPoint = new Point(0, 0);
Size location = new Size(1000, 1000);
Rectangle rectangle = new Rectangle(startPoint, location);
e.Graphics.Clip = new Region(rectangle);
} private void button1_Click(object sender, EventArgs e)
{
bPaint = true;
this.Invalidate();
} private void huahua(Graphics g)
{ //Graphics g = CreateGraphics(); Point startPoint = new Point(0, 0);
Point endPoint = new Point(800, 800);
SolidBrush brush = new SolidBrush(Color.Green);
Pen pen = new Pen(brush, 18);
g.TranslateTransform(AutoScrollPosition.X, AutoScrollPosition.Y);
g.FillEllipse(brush, 0, 0, 120, 120);
g.DrawEllipse(pen, 120, 120, 300, 300);
g.DrawLine(pen, startPoint, endPoint);
// g.Dispose();
pen.Dispose();
this.BackColor = Color.Pink;
brush.Dispose();
} private void button2_Click(object sender, EventArgs e)
{
bPaint = false;
// Graphics g = CreateGraphics();
// g.Clear(Color.White);
// g.Dispose(); this.BackColor = Color.White;
}
}
void Form1_Paint(object sender, PaintEventArgs e)在重绘事件中,事件参数PaintEventArgs ,这个参数的 Graphics也就是当前窗体的绘图表面
void Form1_Paint(object sender, PaintEventArgs e)在重绘事件中,事件参数PaintEventArgs ,这个参数的 Graphics也就是当前窗体的绘图表面 当然,你也可以这样huahua(CreateGraphics())是一样的
void Form1_Paint(object sender, PaintEventArgs e)这个是什么意思?是事件还是函数?有什么用,对于Paint 我一直不能理解,