在.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-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-05-11
  • 2021-10-19
  • 2021-04-20
  • 2021-09-23
猜你喜欢
  • 2021-09-21
  • 2021-07-10
  • 2021-10-10
  • 2022-12-23
  • 2021-10-11
  • 2022-12-23
  • 2021-08-27
相关资源
相似解决方案