Hallo ihr Zwei...
so, jetzt kommt meine Version
Dank eurer Hilfe habe ich ein dynamisches WallBoard hinbekommen. Ihr braucht dafür
eine PictureBox (Name: picBoard) und einen Timer. Die PictureBox kann beliebig
Breit sein, die Höhe wird automatisch angepasst.
Das Ganze ist noch etwas mit der heißen Nadel gestrickt und kann bestimmt noch an
einigen Stellen optimiert werden.
Imports System.Drawing
Public Class Form1
Private Const LEDSize As Integer = 4 ' LED-Größe
Private Const TInterval As Integer = 20 ' Timer Interval
Private Const StepSize As Integer = 2 ' Schrittweite Scrollbewegung
Private sMatrix() As String
Private bmp As Bitmap
Private g As Graphics
Private LedsPerRow As Integer
Private LedBoardSize As New Point
Private LedBoardRect As Rectangle
Private Pos As Integer = 0
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles MyBase.Load
' LEDBoard initialisieren
With picBoard
LedsPerRow = Int(.Width \ LEDSize)
LedBoardSize.X = LedsPerRow * LEDSize + 1
LedBoardSize.Y = 10 * LEDSize + 2
LedBoardRect.Size = LedBoardSize
.BackColor = Color.Black
.Size = LedBoardSize
End With
' Der Text für das LEDBoard
GetPixel("Gemeinschaftsproduktion von Dave, GPM und Snoopy... ")
' Aufruf muss nach GetPixel erfolgen
InitBoard()
Timer1.Interval = TInterval
Timer1.Enabled = True
End Sub
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As _
System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
g.Dispose()
bmp.Dispose()
End Sub
Private Sub picBoard_Paint(ByVal sender As Object, ByVal e As _
System.Windows.Forms.PaintEventArgs) Handles picBoard.Paint
If Pos + LedBoardSize.X <= bmp.Width Then
e.Graphics.DrawImage(bmp, 0, 0, New Rectangle(Pos, 0, LedBoardSize.X, _
LedBoardSize.Y), GraphicsUnit.Pixel)
Else
Dim n As Integer = (Pos + LedBoardSize.X) - bmp.Width
e.Graphics.DrawImage(bmp, 0, 0, New Rectangle(Pos, 0, LedBoardSize.X, _
LedBoardSize.Y), GraphicsUnit.Pixel)
e.Graphics.DrawImage(bmp, LedBoardSize.X - n, 0, New Rectangle(0, 0, _
LedBoardSize.X, LedBoardSize.Y), GraphicsUnit.Pixel)
End If
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles Timer1.Tick
Pos += StepSize
If Pos > bmp.Width Then
Pos = 0
End If
picBoard.Invalidate()
End Sub
Private Sub InitBoard()
' Bitmap initialisieren
bmp = New Bitmap(sMatrix(0).Length * LEDSize, LedBoardSize.Y)
g = Graphics.FromImage(bmp)
' LEDBoard Image erzeugen
For x As Integer = 0 To sMatrix(0).Length - 1
For y As Integer = 0 To 9
If sMatrix(y).Chars(x) = "0" Then
g.FillEllipse(Brushes.Yellow, x * LEDSize, LEDSize + (y - 1) * _
LEDSize, LEDSize, LEDSize)
Else
g.FillEllipse(Brushes.Gray, x * LEDSize, LEDSize + (y - 1) * _
LEDSize, LEDSize, LEDSize)
End If
Next
Next
End Sub
Private Sub GetPixel(ByVal s As String)
ReDim sMatrix(9)
For Each c As Char In s
Dim bmp As New Bitmap(10, 10)
Dim g As Graphics = Graphics.FromImage(bmp)
g.TranslateTransform(-3, -4)
g.DrawString(c, New Font("Courier New", 10), Brushes.Black, 0, 0)
For x As Integer = 0 To 9
For y As Integer = 0 To 9
If bmp.GetPixel(x, y) = Color.FromArgb(0, 0, 0) Then
sMatrix(y) &= "0"
Else
sMatrix(y) &= " "
End If
Next
Next
g.Dispose()
bmp.Dispose()
Next c
' Nur wenn Text kleiner als LedsPerRow, dann auffüllen
If sMatrix(0).Length < LedsPerRow Then
Dim x1 As Integer = LedsPerRow - sMatrix(0).Length
For x As Integer = 0 To 9
For y As Integer = 0 To x1
sMatrix(x) &= " "
Next
Next
End If
End Sub
End ClassGruß und vielen Dank an Euch...
Gru?
---------------------------------------------------
Snoopy sagt - vb@rchiv find ich gut...
Schon gesehen? OSMMapViewer V2 Control |