Graphics g=new Graphics (); 你用g画,在哪个画布上画呢?Graphics g = this.CreateGraphics();明确了g是在this上画(如果this是当前窗体,则在窗体上画;如果this是PictureBox,则在pictureBox上画)还可以是这样的定义 Graphics g = pictureBox1.CreateGraphics();则g在pictureBox1上画
Graphics g = this.CreateGraphics(); 左边是创建对象那么右边又是什么? 左边是声明,右边才是创建对象,this.CreateGraphics()表示创建当前窗体的画布
是不是也就是说Graphics这个类比较特殊,不能用new创建?
Graphics这个类,设计成依赖作用对象,故意防止直接调用构造来创建对象
Graphics本身就没有可访问的构造函数,lz确认你在vs里能定义 Graphics g= new Graphics(); ?不报错吗?
Graphics g = this.CreateGraphics(); 左边是定义一个Graphics类型的变量
如何:创建用于绘制的 Graphics 对象? 1、获取对 Paint 事件的 PaintEventArgs 中 Graphics 对象的引用 private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs pe) { // Declares the Graphics object and sets it to the Graphics object // supplied in the PaintEventArgs. Graphics g = pe.Graphics; // Insert code to paint the form here. }2、CreateGraphics()方法 也可以使用控件或窗体的 CreateGraphics 方法来获取对 Graphics 对象的引用,该对象表示该控件或窗体的绘 图图面。 Graphics g; // Sets g to a graphics object representing the drawing surface of the // control or form g is a member of. g = this.CreateGraphics();3、从 Image 创建 Graphics 对象 Bitmap myBitmap = new Bitmap(@"C:\Documents and Settings\Joe\Pics\myPic.bmp"); Graphics g = Graphics.FromImage(myBitmap);参考msdn,自己可以去看看,上面解释得很详细: http://msdn.microsoft.com/zh-cn/library/5y289054.aspx
为什么我用 Graphics* g = this->CreateGraphics();结果:error C2039: “CreateGraphics”: 不是“Ctest14Dlg”的成员 c:\users\brandy\documents\visual studio 2010\projects\test14\test14\test14dlg.cpp我是建立的基于对话框的MFC应用程序
为什么我用 Graphics* g = this->CreateGraphics();结果:error C2039: “CreateGraphics”: 不是“Ctest14Dlg”的成员 c:\users\brandy\documents\visual studio 2010\projects\test14\test14\test14dlg.cpp我是建立的基于对话框的MFC应用程序
解释得灰常清楚为什么我用 Graphics* g = this->CreateGraphics();结果:error C2039: “CreateGraphics”: 不是“Ctest14Dlg”的成员 c:\users\brandy\documents\visual studio 2010\projects\test14\test14\test14dlg.cpp我是建立的基于对话框的MFC应用程序
你用g画,在哪个画布上画呢?Graphics g = this.CreateGraphics();明确了g是在this上画(如果this是当前窗体,则在窗体上画;如果this是PictureBox,则在pictureBox上画)还可以是这样的定义
Graphics g = pictureBox1.CreateGraphics();则g在pictureBox1上画
左边是声明,右边才是创建对象,this.CreateGraphics()表示创建当前窗体的画布
Graphics这个类,设计成依赖作用对象,故意防止直接调用构造来创建对象
左边是定义一个Graphics类型的变量
1、获取对 Paint 事件的 PaintEventArgs 中 Graphics 对象的引用
private void Form1_Paint(object sender,
System.Windows.Forms.PaintEventArgs pe)
{
// Declares the Graphics object and sets it to the Graphics object
// supplied in the PaintEventArgs.
Graphics g = pe.Graphics;
// Insert code to paint the form here.
}2、CreateGraphics()方法
也可以使用控件或窗体的 CreateGraphics 方法来获取对 Graphics 对象的引用,该对象表示该控件或窗体的绘 图图面。
Graphics g;
// Sets g to a graphics object representing the drawing surface of the
// control or form g is a member of.
g = this.CreateGraphics();3、从 Image 创建 Graphics 对象
Bitmap myBitmap = new Bitmap(@"C:\Documents and
Settings\Joe\Pics\myPic.bmp");
Graphics g = Graphics.FromImage(myBitmap);参考msdn,自己可以去看看,上面解释得很详细:
http://msdn.microsoft.com/zh-cn/library/5y289054.aspx
this.CreateGraphics()这个方法是不是每次调用都会给出不同的Graphics对象,还是说每次都是给的基于this的某个属性呢?