Hallo Zusammen,
hier mal ein Zwischenschritt
Class MainToolbar
Dim _x As Integer = 3
Dim _y As Integer = 3
Dim picButtonPanel As New System.Windows.Forms.Panel
Dim _Control As Control
Public Event Click(ByVal name As String)
Public Sub New(ByVal myControl As Control)
_Control = myControl
End Sub
Public Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs)
Dim control As Object = DirectCast(sender, _
System.Windows.Forms.PictureBox)
RaiseEvent Click(control.name)
End Sub
Public Sub PictureBox_MouseUp(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
resetPicButtonBoarder(_Control.Controls)
End Sub
Public Sub PictureBox_MouseDown(ByVal sender As Object, ByVal e As _
System.Windows.Forms.MouseEventArgs)
Dim control As Object = DirectCast(sender, _
System.Windows.Forms.PictureBox)
control.BorderStyle = BorderStyle.Fixed3D
End Sub
Public Sub PictureBox_MouseEnter(ByVal sender As Object, ByVal e As _
System.EventArgs)
Dim control As Object = DirectCast(sender, _
System.Windows.Forms.PictureBox)
control.Size = New System.Drawing.Size(32, 32)
control.Location = New System.Drawing.Point(control.Tag.X - 3, _
control.Tag.Y - 3)
End Sub
Public Sub PictureBox_MouseLeave(ByVal sender As Object, ByVal e As _
System.EventArgs)
Dim control As Object = DirectCast(sender, _
System.Windows.Forms.PictureBox)
control.Size = New System.Drawing.Size(24, 24)
control.Location = New System.Drawing.Point(control.tag.X, _
control.tag.Y)
End Sub
Public Sub add(ByVal image As System.Drawing.Image, ByVal name As String, _
ByVal tooltip As String)
Dim picButton As New System.Windows.Forms.PictureBox
picButton.Image = image
picButton.Name = name
Form1.ToolTip1.SetToolTip(picButton, tooltip)
picButton.SizeMode = PictureBoxSizeMode.StretchImage
picButton.Location = New System.Drawing.Point(_x, _y)
picButton.Tag = picButton.Location
picButton.Size = New System.Drawing.Size(24, 24)
picButton.Parent = _Control
AddHandler picButton.Click, AddressOf PictureBox_Click
AddHandler picButton.MouseUp, AddressOf PictureBox_MouseUp
AddHandler picButton.MouseDown, AddressOf PictureBox_MouseDown
AddHandler picButton.MouseEnter, AddressOf PictureBox_MouseEnter
AddHandler picButton.MouseLeave, AddressOf PictureBox_MouseLeave
_x += 26
End Sub
Public Sub space(ByVal width As Integer)
_x += width
End Sub
Public Sub separator()
Dim picButton As New System.Windows.Forms.PictureBox
picButton.Image = My.Resources.separator
picButton.Location = New System.Drawing.Point(_x, _y)
picButton.Size = New System.Drawing.Size(5, 24)
picButton.Parent = _Control
_x += 9
End Sub
Public Sub resetPicButtonBoarder(ByVal Controls As _
Control.ControlCollection)
For Each control As Control In Controls
If (TypeOf control Is PictureBox) Then
CType(control, PictureBox).BorderStyle = BorderStyle.None
End If
If (control.Controls.Count > 0) Then
resetPicButtonBoarder(control.Controls)
End If
Next
End Sub
End Class Und so wirds genutzt
Dim picButtonPanel As New System.Windows.Forms.Panel
Dim WithEvents myToolbar As New MainToolbar(picButtonPanel)
Private Sub PictureBox_Click(ByVal name As String) Handles myToolbar.Click
Me.Label1.Text = name
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
Handles Me.Load
createToolBar()
End Sub
Private Sub createToolBar()
picButtonPanel.Location = New System.Drawing.Point(0, 24)
picButtonPanel.Size = New System.Drawing.Size(Me.Width, 32)
picButtonPanel.Parent = Me
myToolbar.add(My.Resources.wi0126_32, "Button1", "Button 1")
myToolbar.add(My.Resources.wi0126_32, "Button2", "Button 2")
myToolbar.separator()
myToolbar.add(My.Resources.wi0126_32, "Button3", "Button 3")
myToolbar.add(My.Resources.wi0126_32, "Button4", "Button 4")
End Sub Gruß
Carsten |