Texteffekte

    • VB.NET

    Es gibt 10 Antworten in diesem Thema. Der letzte Beitrag () ist von jvbsl.

      Hi,
      Da ich momentan ein kleines Konkurrenzprojekt zu singu's [Release] TextEffectsLib erstelle, wollte ich mal einen kleinen Teil davon Open Source machen.

      Hier findet ihr zahlreich viele Effekte, und es kommen noch mehr dazu.

      VB.NET-Quellcode

      1. Public Sub typewriter(ByVal target As Control, ByVal txt As String, ByVal speed As Integer, ByVal typechar As String)
      2. Dim Array1 As String
      3. Dim ltext As String = ""
      4. Array1 = txt.ToCharArray
      5. For i As Integer = 0 To txt.Length - 1
      6. ltext += Array1(i)
      7. target.Text = ltext + typechar
      8. Application.DoEvents()
      9. Threading.Thread.Sleep(speed)
      10. Next
      11. target.Text = txt
      12. End Sub
      13. Public Sub InFormLeft(ByVal target As Control, ByVal txt As String, ByVal speed As Integer)
      14. Dim Array1 As String
      15. Dim ltext As String = ""
      16. Array1 = txt.ToCharArray
      17. For i As Integer = 0 To txt.Length - 1
      18. ltext = Array1((txt.Length - 1) - i) + ltext
      19. target.Text = ltext
      20. Application.DoEvents()
      21. Threading.Thread.Sleep(speed)
      22. Next
      23. target.Text = txt
      24. End Sub
      25. Public Sub InFormRight(ByVal target As Control, ByVal txt As String, ByVal speed As Integer)
      26. Dim Array1 As String
      27. Dim ltext As String = ""
      28. Dim Pattern As String = ""
      29. Array1 = txt.ToCharArray
      30. Do Until Pattern.Length = txt.Length
      31. Pattern += " "
      32. Loop
      33. For i As Integer = 0 To txt.Length - 1
      34. Pattern = Pattern.Remove(txt.Length - (i + 1), 1)
      35. ltext += Array1(i)
      36. target.Text = Pattern + ltext
      37. Application.DoEvents()
      38. Threading.Thread.Sleep(speed)
      39. Next
      40. target.Text = txt
      41. End Sub
      42. Public Sub OutFromLeft(ByVal target As Control, ByVal txt As String, ByVal speed As Integer)
      43. Dim ltext As String = txt
      44. target.Text = txt
      45. For i As Integer = 0 To txt.Length - 1
      46. ltext = ltext.Remove(0, 1)
      47. target.Text = ltext
      48. Application.DoEvents()
      49. Threading.Thread.Sleep(speed)
      50. Next
      51. End Sub
      52. Public Sub OutFromRight(ByVal target As Control, ByVal txt As String, ByVal speed As Integer)
      53. Dim ltext As String = txt
      54. Dim Pattern As String = ""
      55. target.Text = txt
      56. For i As Integer = 0 To txt.Length - 1
      57. ltext = ltext.Remove(ltext.Length - 1, 1)
      58. Pattern += " "
      59. target.Text = Pattern + ltext
      60. Application.DoEvents()
      61. Threading.Thread.Sleep(speed)
      62. Next
      63. End Sub
      64. Public Sub HideFromLeft(ByVal target As Control, ByVal txt As String, ByVal speed As Integer)
      65. Dim ltext As String = txt
      66. Dim Pattern As String = ""
      67. target.Text = txt
      68. For i As Integer = 0 To txt.Length - 1
      69. ltext = ltext.Remove(0, 1)
      70. Pattern += " "
      71. target.Text = Pattern + ltext
      72. Application.DoEvents()
      73. Threading.Thread.Sleep(speed)
      74. Next
      75. End Sub
      76. Public Sub HideFromRight(ByVal target As Control, ByVal txt As String, ByVal speed As Integer)
      77. Dim ltext As String = txt
      78. target.Text = txt
      79. For i As Integer = 0 To txt.Length - 1
      80. ltext = ltext.Remove(ltext.Length - 1, 1)
      81. target.Text = ltext
      82. Application.DoEvents()
      83. Threading.Thread.Sleep(speed)
      84. Next
      85. End Sub
      86. Public Sub ExpandEffect(ByVal target As Control, ByVal txt As String, ByVal speed As Integer, ByVal expander As String)
      87. Dim Array1 As String
      88. Dim ltext As String = ""
      89. Dim stext As String = txt
      90. Array1 = txt.ToCharArray
      91. For i As Integer = 0 To txt.Length - 1
      92. ltext += Array1(i) + expander
      93. stext = stext.Remove(0, 1)
      94. target.Text = ltext + stext
      95. Application.DoEvents()
      96. Threading.Thread.Sleep(speed)
      97. Next
      98. Threading.Thread.Sleep(800)
      99. Dim first As Boolean = True
      100. Array1 = target.Text.ToCharArray
      101. Dim lS As String = target.Text
      102. For i As Integer = 0 To target.Text.Length - 1
      103. If first = True Then
      104. lS = lS.Remove((Array1.Length - 1) - i, 1)
      105. first = False
      106. Else
      107. first = True
      108. End If
      109. target.Text = lS
      110. Application.DoEvents()
      111. Threading.Thread.Sleep(speed)
      112. Next
      113. End Sub
      Wenn andere sowas verwenden, heißt die Devise: Besser machen :) . Der Aufwand für Threading hält sich in Grenzen, da du eine gemeinsame Methode für alle Effekte verwenden kannst. Eventuell sowas:

      VB.NET-Quellcode

      1. Sub SetTextSafe(c as Control, newText As String) 'kA ob die Methode (Edit: "als Extension") nachträglich vererbt wird - mal testen.
      2. If c.InvokeRequired Then
      3. Dim d As New Action(AddressOf SetTextSafe)
      4. c.Invoke(d, c, newText)
      5. Else
      6. c.Text = newText
      7. End If
      8. End Sub


      Die Abarbeitung der Effekte kannst du dann einfach in den Threadpool stellen.
      Gruß
      hal2000

      Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „hal2000“ ()

      Der einzige unterschied vom Windows-Forms-Timer zum Threading Timer ist nur

      Nope, Threading.Timer verwendet Grundsätzlich einen neuen Thread, der Windows.Forms.Timer nicht(entspricht soweit ich mich erinnere SetTimer? WinAPI)
      Der normale Timer hat ca. eine Genauigkeit von 55 ms, der Threading.Timer hingegen ist genauer...

      Ich trau mich wetten, dass der Timer genau das selbe im Hintergrund macht :D

      Siehe oben, also nein...
      Ich wollte auch mal ne total überflüssige Signatur:
      ---Leer---