在.NET中,可以通过以下方法获取Graphics对象。
1. 从Paint事件的参数中获取。
窗体和许多控件都有一个Paint事件,有一个PaintEventArgs类型的参数e。
获取Graphics对象private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        }
窗体的Paint事件是最常用于放置绘图代码的地方,每当窗体被其他窗体挡住,再次显示的时候,窗体的所有内容必须被重绘,否则会得到一个空白的窗体。

2. 用CreateGraphics方法创建。
如果需要在Paint方法以外绘图,可以通过控件或窗体的CreateGraphics方法来获取Graphics对象。
获取Graphics对象private void button1_Click(object sender, System.EventArgs e)
        }

3. 对Image对象调用Graphics.FromImage获取。
获取Graphics对象private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
        }

相关文章:

  • 2021-08-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-09-28
  • 2022-02-02
  • 2022-12-23
  • 2021-12-08
  • 2021-10-09
  • 2021-10-14
相关资源
相似解决方案