VB projects - Customized form buttons
Description: Creating the form with customized buttons in control box
Minimum requirements: vb
Download: source code
Screenshot:

Project: Standard EXE
Controls: Label1 (label), txtCaption (textbox), txtButtons (textbox), cmdButtons (button), cmdMy (button, set Index property to 1), pic (picture box)
Code:
Dim i As Integer
Dim iButtons As Integer
Dim lX As Long
Dim lY As Long
Private Sub cmdButtons_Click()
If Val(txtButtons) < 1 Or Val(txtButtons) > 10 Then
MsgBox "Illegal number of buttons. Select
from the range 1-10"
Else
If iButtons > txtButtons Then
For i = iButtons To
txtButtons + 1 Step -1
Unload cmdMy(i)
Next
iButtons = txtButtons
Else
If iButtons <
txtButtons Then
For i = iButtons + 1 To txtButtons
Load cmdMy(i)
cmdMy(i).Top = 30
If i = 2 Then
Set cmdMy(i).Picture = LoadPicture("Net14.ico", 0)
cmdMy(i).ToolTipText = "Say hello"
End If
If i = 3 Then
Set cmdMy(i).Picture = LoadPicture("Net01.ico", 0)
cmdMy(i).ToolTipText = "Say good-bye"
End If
cmdMy(i).Visible = True
Next
iButtons = txtButtons
Form_Resize
End If
End If
End If
End Sub
Private Sub cmdMy_Click(Index As Integer)
pic.SetFocus
Select Case Index
Case 1
End
Case 2
MsgBox "Hello"
Case 3
MsgBox "Good-bye"
End Select
End Sub
Private Sub Form_Load()
iButtons = 1
Label1 = txtCaption
Set pic = LoadPicture("form.ico", 0)
With cmdMy(1)
.Width = 240
.Height = 240
.Top = 30
End With
Set cmdMy(1).Picture = LoadPicture("Handshak.ico", 0)
cmdMy(1).ToolTipText = "Exit"
txtButtons = 3
cmdButtons_Click
End Sub
Private Sub Form_Resize()
pic.Width = Width - 30
For i = 1 To iButtons
cmdMy(i).Left = Width - (cmdMy(i).Width * i +
20) - 120
Next
End Sub
Private Sub Label1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As
Single)
lX = X
lY = Y
End Sub
Private Sub Label1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As
Single)
If Button = 1 Then
Left = Left - (lX - X)
Top = Top - (lY - Y)
End If
End Sub
Private Sub pic_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
lX = X
lY = Y
End Sub
Private Sub pic_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
If Button = 1 Then
Left = Left - (lX - X)
Top = Top - (lY - Y)
End If
End Sub
Private Sub txtCaption_Change()
Label1 = txtCaption
End Sub
|