积极答复者
调用函数

问题
-
Imports System.Timers
Public Class Form1
Inherits System.Windows.Forms.Form
Private myTimer As New System.Timers.Timer(1000)
Private drawBlack As Boolean = TruePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Public Sub New()
InitializeComponent()
AddHandler myTimer.Elapsed, AddressOf myTimer_Elapsed
myTimer.Start()
End Sub
Private Sub myTimer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
Dim g As Graphics = Me.CreateGraphics()
If drawBlack Then
g.FillEllipse(Brushes.Black, Me.ClientSize.Width / 2 - 25, Me.ClientSize.Height / 2 - 25, 50, 50)
Me.drawBlack = False
Else
g.FillEllipse(Brushes.Red, Me.ClientSize.Width / 2 - 25, Me.ClientSize.Height / 2 - 25, 50, 50)
Me.drawBlack = True
End If
g.Dispose()
End Sub
End Class如过要调用:
Private Sub myTimer_Elapsed(ByVal sender As Object, ByVal e As ElapsedEventArgs)
Dim g As Graphics = Me.CreateGraphics()
If drawBlack Then
g.FillEllipse(Brushes.Black, Me.ClientSize.Width / 2 - 25, Me.ClientSize.Height / 2 - 25, 50, 50)
Me.drawBlack = False
Else
g.FillEllipse(Brushes.Red, Me.ClientSize.Width / 2 - 25, Me.ClientSize.Height / 2 - 25, 50, 50)
Me.drawBlack = True
End If
g.Dispose()
End Sub
End Class
应该怎么调用,我试过这样不行 call myTimer_Elapsed(),应该怎么调用呢?
visual studio 2008
答案
全部回复
-
你要是自己调用,可以这样
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myTimer_Elapsed(Nothing, Nothing)
End Sub
孟宪会- 已标记为答案 feiyun0112Moderator 2009年3月10日 2:09
- 取消答案标记 liunain021 2009年3月10日 6:32
-
孟宪会 说:
你要是自己调用,可以这样
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
myTimer_Elapsed(Nothing, Nothing)
End Sub
孟宪会
我要在
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
myTimer_Elapsed(Nothing, Nothing)
end up
中这样调用,好像不行。怎么在Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)中调用呢??
visual studio 2008 -
孟宪会 说:
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
myTimer_Elapsed(Nothing, Nothing)
End Sub
是可以的,不过,你的代码是定时器,放在OnPaint里只能是一种状态,不会实现黑红的交替出现
孟宪会
我在Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
myTimer_Elapsed(Nothing, Nothing)
End Sub
中调用过,不行
visual studio 2008