Locked How avoid flickering using powerpacks

  • יום שלישי 21 יוני 2011 10:59
     
      קוד כלול

    Hi , I have a problem using power packs. I set in a panel about 70 rectangle shape and when I try to update their "label" , there is a little flickering. Can you help me to avoid this behaviour ? Here my sample code

    Imports System.Drawing
    
    Public Class Form1
    
     Dim arrTavoli(-1) As MyRectangleWithText
     Dim i As Integer = 0
     Dim shapeContainer1 As New Microsoft.VisualBasic.PowerPacks.ShapeContainer
    
     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      For i As Integer = 0 To 96
       AvvaloraTavolo(i, i Mod 12, Math.Floor(i / 12))
      Next
      PanelControl1.Controls.Add(shapeContainer1)
     End Sub
    
     Sub AvvaloraTavolo(ByVal i As Integer, ByVal intRiga As Integer, ByVal intcolonna As Integer)
      ReDim Preserve arrTavoli(i)
      arrTavoli(i) = New MyRectangleWithText
      arrTavoli(i).Location = New Point(intRiga * 50, intcolonna * 50)
      arrTavoli(i).Size = New Drawing.Size(50, 50)
      arrTavoli(i).Visible = True
      arrTavoli(i).Text = "Tav " & i & Environment.NewLine & " T.0"
      arrTavoli(i).FillColor = Color.AliceBlue
      arrTavoli(i).FillStyle = PowerPacks.FillStyle.Solid
      shapeContainer1.Shapes.Add(arrTavoli(i))
     End Sub
    
    
    
     Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
      i += 1
      i = i Mod 96
      For j As Integer = 0 To 95
       arrTavoli(j).Text = "Tav " & j & Environment.NewLine & " T." & i * j
       arrTavoli(i).FillColor = Color.FromArgb(-i * j)
    
      Next
     End Sub
    
     Private Sub SimpleButton2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SimpleButton2.Click
      Dim _frm2 As New Form2
      _frm2.ShowDialog()
     End Sub
    End Class
    

    Carlo

כל התגובות

  • שבת 25 יוני 2011 01:16
    מנחה דיון
     
     

    How do you implement the MyRectangleWithText class. This could be the cause I guess, I played your code without the text, works OK to me (You can try to remove the text and see if there is a difference).

    And how bad is the flickering? On the full form or in the rectangle.

     


    John Chen
  • יום שלישי 28 יוני 2011 10:32
     
      קוד כלול

    Sorry for my delay

    I forgot to write myRectanglewithtext class. Here you are

    Imports System.Drawing
    
    Public Class MyRectangleWithText
      Inherits PowerPacks.RectangleShape
    
      Private FText As String = String.Empty
    
      Private FFont As Font = Nothing
    
      Private FTextLocation As Point = New Point(0, 0)
    
      Private FTextColour As Color = Color.Black
    
      Private CanDrawText As Boolean = False
    
      Public Property Text() As String
    
        Get
    
          Return FText
    
        End Get
    
        Set(ByVal value As String)
    
          FText = value
    
          RedrawText()
    
        End Set
    
      End Property
    
    
      Public Property Font() As Font
    
        Get
    
          Return FFont
    
        End Get
    
        Set(ByVal value As Font)
    
          FFont = value
    
          RedrawText()
    
        End Set
    
      End Property
    
    
      Public Property TextLocation() As Point
    
        Get
    
          Return FTextLocation
    
        End Get
    
        Set(ByVal value As Point)
    
          FTextLocation = value
    
          RedrawText()
    
        End Set
    
      End Property
    
    
      Public Property TextColor() As Color
    
        Get
    
          Return FTextColour
    
        End Get
    
        Set(ByVal value As Color)
    
          FTextColour = value
    
          RedrawText()
    
        End Set
    
      End Property
    
    
      Private Sub RedrawText()
    
        CanDrawText = FText <> String.Empty AndAlso FFont IsNot Nothing
    
        If CanDrawText Then Invalidate()
    
      End Sub
    
    
      Private Sub MyRectangleWithText_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint
    
        If Not CanDrawText Then Exit Sub
    
        Dim g As Graphics = e.Graphics
    
        g.DrawString(FText, FFont, New SolidBrush(FTextColour), Location.X + FTextLocation.X, Location.Y + FTextLocation.Y)
    
        Me.FillColor = Me.FillColor
      End Sub
    
    
      Public Sub New()
        Me.Font = New Font("Tahoma", 10)
      End Sub
    
    End Class
    
    
    

    The flickering is in the set of rectangle . It seems like a white flash

    Thanks


    Carlo
  • שבת 09 יולי 2011 20:29
    מנחה דיון
     
     

    It seems you can simply use a Label (instead of you own Retangle with Text control) to achieve what you are doing:

    Like this code, where in the form assuming you have a Panel1 control as the container control.

    Public Class Form1

        Dim arrTavoli(-1) As Label
        Dim i As Integer = 0

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

            For i As Integer = 0 To 96
                AvvaloraTavolo(i, i Mod 12, Math.Floor(i / 12))
            Next
            Timer1.Start()
        End Sub

        Sub AvvaloraTavolo(ByVal i As Integer, ByVal intRiga As Integer, ByVal intcolonna As Integer)
            ReDim Preserve arrTavoli(i)
            arrTavoli(i) = New Label
            arrTavoli(i).Location = New Point(intRiga * 50, intcolonna * 50)
            arrTavoli(i).Size = New Drawing.Size(50, 50)
            arrTavoli(i).Visible = True
            arrTavoli(i).Text = "Tav " & i & Environment.NewLine & " T.0"
            arrTavoli(i).BackColor = Color.AliceBlue
            Panel1.Controls.Add(arrTavoli(i))
        End Sub

        Private Sub Timer1_Tick_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
            i += 1
            i = i Mod 96
            For j As Integer = 0 To 95

                arrTavoli(j).Text = "Tav " & j & Environment.NewLine & " T." & i * j
                arrTavoli(i).BackColor = Color.FromArgb(-i * j)
            Next
        End Sub
    End Class

      


    John Chen
  • יום שני 11 יולי 2011 08:09
     
     

    Yes , It works, but I choose power packs because they are clickable, I can choose between oval and rectangle shape...

    In this way how can I display an ellipse?


    Carlo