我在我的控件中覆盖了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答案都可以接受:)
答案 0 :(得分:3)
Protected Overrides Sub OnPaint(e As PaintEventArgs)
MyBase.OnPaint(e)
e.Graphics.DrawImageUnscaled(nImg.Visual, 0, 0, Width, Height)
End Sub