none
Animation Around Rectangle RRS feed

  • Question

  • Hello,

    I want to highlight rectangle such that a DOT is moving around the rectangle in a rectangular sequence continuously as if it is showing that the rectangle is selected

    Friday, March 4, 2016 6:05 AM

Answers

  • I want to highlight rectangle such that a DOT is moving around the rectangle in a rectangular sequence continuously as if it is showing that the rectangle is selected

    This will animate a rectangle using dashed lines. You can juggle the number and layout of the dashes to vary the effect.

    Public Class Form1
        Dim timer1 As New Timer
        Dim Dashes As New List(Of Single())
        Dim blackPen As New Pen(Color.Black, 5)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            AddHandler timer1.Tick, AddressOf redraw
            timer1.Interval = 200
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim dash1 As Single() = {2, 3}
            Dim dash2 As Single() = {1, 1, 2}
            Dim dash3 As Single() = {3, 2}
            Dashes.Add(dash1)
            Dashes.Add(dash2)
            Dashes.Add(dash3)
            timer1.Start()
        End Sub
    
        Public Sub redraw()
            Static Phase As Integer = 0
            Phase = (Phase + 1) Mod Dashes.Count
            blackPen.DashPattern = Dashes(Phase)
            Me.Invalidate()
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.Clear(Color.Aqua)
            e.Graphics.DrawRectangle(blackPen, New Rectangle(100, 100, 100, 100))
        End Sub
    End Class
    • Marked as answer by Tech Aspirant Friday, March 4, 2016 9:38 AM
    Friday, March 4, 2016 6:57 AM

All replies

  • Could you show us the shell of your program? is this winforms? is the rectangle a PictureBox, or a section of the form background? Does it respond to an event?

    These precisions would frame the question and the related answers...

    Friday, March 4, 2016 6:34 AM
  • I want to highlight rectangle such that a DOT is moving around the rectangle in a rectangular sequence continuously as if it is showing that the rectangle is selected

    This will animate a rectangle using dashed lines. You can juggle the number and layout of the dashes to vary the effect.

    Public Class Form1
        Dim timer1 As New Timer
        Dim Dashes As New List(Of Single())
        Dim blackPen As New Pen(Color.Black, 5)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            AddHandler timer1.Tick, AddressOf redraw
            timer1.Interval = 200
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim dash1 As Single() = {2, 3}
            Dim dash2 As Single() = {1, 1, 2}
            Dim dash3 As Single() = {3, 2}
            Dashes.Add(dash1)
            Dashes.Add(dash2)
            Dashes.Add(dash3)
            timer1.Start()
        End Sub
    
        Public Sub redraw()
            Static Phase As Integer = 0
            Phase = (Phase + 1) Mod Dashes.Count
            blackPen.DashPattern = Dashes(Phase)
            Me.Invalidate()
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.Clear(Color.Aqua)
            e.Graphics.DrawRectangle(blackPen, New Rectangle(100, 100, 100, 100))
        End Sub
    End Class
    • Marked as answer by Tech Aspirant Friday, March 4, 2016 9:38 AM
    Friday, March 4, 2016 6:57 AM
  • Acamar....Just need the same animation in Alphabates

    Alphabates - "ID"

    Friday, March 4, 2016 2:37 PM
  • I want to highlight rectangle such that a DOT is moving around the rectangle in a rectangular sequence continuously as if it is showing that the rectangle is selected

    This will animate a rectangle using dashed lines. You can juggle the number and layout of the dashes to vary the effect.

    Public Class Form1
        Dim timer1 As New Timer
        Dim Dashes As New List(Of Single())
        Dim blackPen As New Pen(Color.Black, 5)
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            AddHandler timer1.Tick, AddressOf redraw
            timer1.Interval = 200
        End Sub
    
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim dash1 As Single() = {2, 3}
            Dim dash2 As Single() = {1, 1, 2}
            Dim dash3 As Single() = {3, 2}
            Dashes.Add(dash1)
            Dashes.Add(dash2)
            Dashes.Add(dash3)
            timer1.Start()
        End Sub
    
        Public Sub redraw()
            Static Phase As Integer = 0
            Phase = (Phase + 1) Mod Dashes.Count
            blackPen.DashPattern = Dashes(Phase)
            Me.Invalidate()
        End Sub
    
        Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
            e.Graphics.Clear(Color.Aqua)
            e.Graphics.DrawRectangle(blackPen, New Rectangle(100, 100, 100, 100))
        End Sub
    End Class

    Acamar....Just need the same animation in Alphabates

    Alphabates - "ID"


    Friday, March 4, 2016 2:37 PM
  • Acamar....Just need the same animation in Alphabates

    Alphabates - "ID"

    I have no idea what that means.  Provide an example.

    Friday, March 4, 2016 9:01 PM