这个C#程序用VB.NET怎么写?
小菜鸟我初学VB.NET,在一本书上看到这个C#程序,想用VB.NET实现. 可是怎么弄也不行,看了MSDN也找不到方法:
using System;
using System.Drawing;
using System.Windows.Forms;
class Test
{
public static void Main()
{
Form form = new Form();
form.Text = "Paint Event";
form.Paint += new PaintEventHandler(MyPaintHandler);
Application.Run(form);
}
static void MyPaintHandler(object obj, PaintEventArgs pea)
{
Graphics g = pea.Graphics;
g.Clear(Color.Chocolate);
}
}
这是我写的VB.NET程序,可是有异常,大家帮忙看看怎么改:
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Class PaintEvent
Public Shared Sub Main()
Dim form As New Form
form.Text = "Paint Event"
Dim paint As New PaintEventHandler(AddressOf Handler)
AddHandler form.Paint, paint
Application.Run(form)
End Sub
Shared Sub Handler(ByVal obj As Object, ByVal pea As PaintEventArgs)
Dim g As Graphics
g.Clear(Color.Chocolate)
End Sub
End Class