这个C#程序用VB.NET怎么写?

jellen 2004-11-04 01:28:08
小菜鸟我初学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
...全文
90 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
jellen 2004-11-04
  • 打赏
  • 举报
回复
谢谢楼上的,我太粗心了,竟然忘记初始化g了:)
OK, 结帖!
3tzjq 2004-11-04
  • 打赏
  • 举报
回复
Imports System
Imports System.Drawing
Imports System.Windows.Forms

_

Class Test

Public Shared Sub Main()
Dim form As New Form()
form.Text = "Paint Event"
AddHandler form.Paint, AddressOf MyPaintHandler

Application.Run(form)
End Sub 'Main


Shared Sub MyPaintHandler(obj As Object, pea As PaintEventArgs)
Dim g As Graphics = pea.Graphics

g.Clear(Color.Chocolate)
End Sub 'MyPaintHandler
End Class 'Test
einsteincao 2004-11-04
  • 打赏
  • 举报
回复
Imports System
Imports System.Drawing
Imports System.Windows.Forms

_

Class Test

Public Shared Sub Main()
Dim form As New Form()
form.Text = "Paint Event"
AddHandler form.Paint, AddressOf MyPaintHandler

Application.Run(form)
End Sub 'Main


Shared Sub MyPaintHandler(obj As Object, pea As PaintEventArgs)
Dim g As Graphics = pea.Graphics

g.Clear(Color.Chocolate)
End Sub 'MyPaintHandler
End Class 'Test
einsteincao 2004-11-04
  • 打赏
  • 举报
回复
http://authors.aspalliance.com/aldotnet/examples/translate.aspx

16,555

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧