创建图形对象

有三种方法可以创建图形对象

  1. 来自油漆事件

每次重绘控件(调整大小,刷新…)时都会调用此事件,如果你希望控件始终在控件上绘制,请使用此方法

   'this will work on any object's paint event, not just the form
   Private Sub Form1_Paint(sender as Object, e as PaintEventArgs) Handles Me.Paint
     Dim gra as Graphics
     gra = e.Graphics
   End Sub
  1. 创建图形

当你想要在控件上创建一次性图形时,或者你不希望控件重新绘制自身时,通常会使用此选项

   Dim btn as New Button
   Dim g As Graphics = btn.CreateGraphics
  1. 现有的图形

如果要绘制和更改现有图形,请使用此方法

   'The existing image can be from a filename, stream or Drawing.Graphic
   Dim image = New Bitmap("C:\TempBit.bmp")
   Dim gr As Graphics = Graphics.FromImage(image)