我正在重写我的控件中的 OnPaint 方法,该方法是直接从我自己的ICan3D.Graphics
类生成的图像中绘制的。当我保存图像时(如您所见,该行已被注释掉)图像是正确的。但是,当表单加载时,它不会将图像作为背景显示。
Imports System
Namespace ICan3D
Public Class RenderSurface
Inherits Control
Dim nImg As Graphics
Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
Dim img As Bitmap = nImg.Visual
'img.Save("C:\image.png")
Dim nGraphDis As System.Drawing.Graphics = System.Drawing.Graphics.FromImage(img)
Dim nPaintEventArgs As New PaintEventArgs(nGraphDis, New Rectangle(0, 0, Width, Height))
MyBase.OnPaint(nPaintEventArgs)
End Sub
Private Sub RenderSurface_Resize(sender As Object, e As System.EventArgs) Handles Me.Resize
nImg = New Graphics(Width, Height)
End Sub
End Class
End Namespace
我正在使用 VB.net,所以所有 .net 答案都是可以接受的 :)