【发布时间】:2012-07-03 21:46:36
【问题描述】:
我正在寻找一些 GDI 教程,但到目前为止我发现的所有内容都适用于 OnPaint 方法,该方法将 Paintarguments 传递给 Graphics。我还没有找到如何从头开始,我的意思是如何使用 Graphics 类本身? 这是我已经完成但对我不起作用的全部代码:
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 WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Pen pen= new Pen(Color.Red, 3);
Graphics g;
g = this.CreateGraphics();
g.DrawEllipse(pen, 150, 150, 100, 100);
}
}
}
它只是没有做任何事情。我尝试了新的形式,没有。
提前谢谢你!
【问题讨论】:
-
调用 CreateGraphics 时,必须手动处置已创建的对象,即在完成后调用 g.Dispose ()。