none
严重求助 ,闪烁的点,为什么总是搞不定? RRS feed

  • 问题

  • Imports System.Drawing
    Imports System.drawing.drawing2d

    Public Class Form1
        Inherits System.Windows.Forms.Form
        Private WithEvents tmr As New System.Timers.Timer(10)
        Private rnd As New Random

    Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
            Me.Invalidate()
    End Sub

    Dim x, y, z, w As Single

        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                x = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub
        Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                y = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub
        Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                w = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub
        Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                z = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed
            Me.CreateGraphics.FillEllipse(New SolidBrush(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))), New Rectangle(x - 3, y - 3, 6, 6))
        End Sub

        Public Sub point()
            Dim rect1 As Rectangle = Rectangle.FromLTRB( x - 3, y - 3,  x + 3, y+ 3)
            Dim rect2 As Rectangle = Rectangle.FromLTRB( w - 2, z- 2,  w + 2, z + 2)
            Dim pen1 As Pen
            pen1 = New Pen(Color.Black)
            Dim brush1 As Brush
            brush1 = New SolidBrush(Color.FromArgb(225, Color.Black))
            Me.CreateGraphics.DrawEllipse(pen1, rect1)
            Me.CreateGraphics.FillEllipse(brush1, rect1)
            Me.CreateGraphics.DrawEllipse(pen1, rect2)
            Me.CreateGraphics.FillEllipse(brush1, rect2)
        End Sub

        Private Sub myfunc()
            If If 140 < x and x< 180  and y<100 Then
             tmr_Elapsed(Nothing, Nothing)
            Else
            Call point()
            End If
        End Sub
    End Class


    根据版主建议 http://social.microsoft.com/Forums/zh-CN/vbasiczhchs/thread/99e921fb-2a3c-4b25-bad9-4e31a4ad8239
     我的程序已经作了一些修改,我想用if 语句的来实现画闪烁的点和不闪烁的点,代码都是正确的,为什么达不到我的要求呢?


     


    visual studio 2008
    2009年3月10日 8:44

答案

  •   Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed
            If 140 < x And x < 180 And y < 100 Then
                Me.CreateGraphics.FillEllipse(New SolidBrush(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))), New Rectangle(x - 3, y - 3, 6, 6))
            Else
                Call point()
            End If
        End Sub

    Private Sub myfunc()

            tmr_Elapsed(Nothing, Nothing)
     
        End Sub


    http://feiyun0112.cnblogs.com/
    • 已标记为答案 liunain021 2009年3月14日 7:43
    2009年3月12日 1:25
    版主

全部回复

  •  Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            tmr.Enabled = True
        End Sub
    http://feiyun0112.cnblogs.com/
    2009年3月10日 8:59
    版主

  • Imports System.Drawing
    Imports System.drawing.drawing2d

    Public Class Form1
        Inherits System.Windows.Forms.Form
        Private WithEvents tmr As New System.Timers.Timer(10)
        Private rnd As New Random

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            tmr.Start()
     End Sub


    Private Sub Form1_SizeChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.SizeChanged
            Me.Invalidate()
    End Sub

    Dim x, y, z, w As Single

        Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                x = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub
        Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                y = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub
        Private Sub TextBox4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox4.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                w = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub
        Private Sub TextBox3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox3.TextChanged
            Dim t As Single
            Try
                t = DirectCast(sender, System.Windows.Forms.TextBox).Text
                z = t
            Catch
            End Try
            myfunc()
            Me.Invalidate()
        End Sub

    Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)

    End Sub

    Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed
            Me.CreateGraphics.FillEllipse(New SolidBrush(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))), New Rectangle(x - 3, y - 3, 6, 6))
        End Sub

        Public Sub point()
            Dim rect1 As Rectangle = Rectangle.FromLTRB( x - 3, y - 3,  x + 3, y+ 3)
            Dim rect2 As Rectangle = Rectangle.FromLTRB( w - 2, z- 2,  w + 2, z + 2)
            Dim pen1 As Pen
            pen1 = New Pen(Color.Black)
            Dim brush1 As Brush
            brush1 = New SolidBrush(Color.FromArgb(225, Color.Black))
            Me.CreateGraphics.DrawEllipse(pen1, rect1)
            Me.CreateGraphics.FillEllipse(brush1, rect1)
            Me.CreateGraphics.DrawEllipse(pen1, rect2)
            Me.CreateGraphics.FillEllipse(brush1, rect2)
        End Sub

        Private Sub myfunc()
            If If 140 < x and x< 180  and y<100 Then
             tmr_Elapsed(Nothing, Nothing)
            Else
            Call point()
            End If
        End Sub
    End Class

    不好意思,代码修正好。重新回到话题。


    visual studio 2008
    2009年3月10日 10:08
  • ??


    visual studio 2008
    2009年3月11日 2:54
  • 我试了没问题

    除了这里多写了个if
     If If 140 < x and x< 180  and y<100 Then

    http://feiyun0112.cnblogs.com/
    2009年3月11日 8:25
    版主
  • feiyun0112 说:

    我试了没问题

    除了这里多写了个if
     If If 140 < x and x< 180  and y<100 Then


    http://feiyun0112.cnblogs.com/



    问题时当x和y 不在 140 < x and x< 180  and y<100这个范围时,窗体上画的还是闪烁的点。窗体上画的还是闪烁的点。
    visual studio 2008
    2009年3月11日 10:51
  •   Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed
            If 140 < x And x < 180 And y < 100 Then
                Me.CreateGraphics.FillEllipse(New SolidBrush(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))), New Rectangle(x - 3, y - 3, 6, 6))
            Else
                Call point()
            End If
        End Sub

    Private Sub myfunc()

            tmr_Elapsed(Nothing, Nothing)
     
        End Sub


    http://feiyun0112.cnblogs.com/
    • 已标记为答案 liunain021 2009年3月14日 7:43
    2009年3月12日 1:25
    版主
  • feiyun0112 说:

      Private Sub tmr_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed
            If 140 < x And x < 180 And y < 100 Then
                Me.CreateGraphics.FillEllipse(New SolidBrush(Color.FromArgb(rnd.Next(0, 255), rnd.Next(0, 255), rnd.Next(0, 255))), New Rectangle(x - 3, y - 3, 6, 6))
            Else
                Call point()
            End If
        End Sub

    Private Sub myfunc()

            tmr_Elapsed(Nothing, Nothing)
     
        End Sub


    http://feiyun0112.cnblogs.com/



    成功了,不好意思,恢复完了。
    visual studio 2008
    • 已标记为答案 liunain021 2009年3月14日 7:43
    • 取消答案标记 liunain021 2009年3月14日 7:43
    2009年3月14日 7:43