codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
Just wanted to add the code for a custom message box in case the link I previously posted might expire.
'// ------------- Prerequisites: 1 Button required on Form1 ------------- \\
Public Class Form1
'// ------------- DYNAMICS ------------- \\
'// message box Form.
Public WithEvents myMessageForm As New Form With _
{.Size = New Size(300, 200), .MinimizeBox = False, .MaximizeBox = False, _
.FormBorderStyle = Windows.Forms.FormBorderStyle.Fixed3D, .ControlBox = False}
'// picturebox to display the Icon.
Public infoImage As New PictureBox With _
{.Location = New Point(20, 30), .Size = New Size(40, 40), .SizeMode = PictureBoxSizeMode.StretchImage}
'// label to display Information.
Public infoLabel As New Label With _
{.Font = New Font("Verdana", 10), .AutoSize = True, .Location = New Point(65, 40)}
'// background label for the Buttons.
Public btnBgLabel As New Label With _
{.BackColor = Color.Gainsboro, .Location = New Point(0, 120), _
.Size = New Size(myMessageForm.width, 80)}
'// buttons
Public WithEvents btn1 As New Button With {.Location = New Point(18, 127), .Size = New Size(120, 35), _
.Text = "Sure Is...", .Font = New Font("Verdana", 10)}
Public btn2 As New Button With {.Location = New Point(150, 127), .Size = New Size(120, 35), _
.Text = "Whatever", .Font = New Font("Verdana", 10)}
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Size = New Size(500, 350) '// resize form.
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
showMyMessagebox() '// Load the Custom Message Box.
End Sub
Sub showMyMessagebox()
Dim infoIcon As Icon = SystemIcons.Information '// give this icon a box. -- referring to the box "of chocolates." :)
myMessageForm.Text = "Cool little Title" '// Title of the message box form.
myMessageForm.Icon = infoIcon '// take the Icon from the box and add it to the message box form.
infoImage.Image = infoIcon.ToBitmap '// display Icon as bitmap in Picturebox.
infoLabel.Text = "The COOLEST Message Box." '// display your Message.
With myMessageForm.Controls '// add the Dynamic Controls to your Message Box Form.
.Add(infoImage) : .Add(infoLabel) : .Add(btnBgLabel) : .Add(btn1) : .Add(btn2)
End With
btnBgLabel.SendToBack() '// send the buttons background Label to the back so the buttons display.
myMessageForm.ShowDialog() '// Load the Custom Message Box.
End Sub
Private Sub myMessageForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles myMessageForm.Load
'// get the location from Left to Right.
Dim locationX As Integer = CInt((Me.Left + (Me.Width - myMessageForm.Width) / 2))
'// get the location from Top to Bottom.
Dim locationY As Integer = CInt((Me.Top + (Me.Height - myMessageForm.Height) / 2))
'// Center the message box Form in center of Form1.
myMessageForm.Location = New Point(locationX, locationY)
End Sub
Private Sub btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btn1.Click
myMessageForm.Close() '// close the Custom Message Box.
End Sub
End Class
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384
"codeorder": the code you pasted shows a mistake in VB 2005.
The word "with" is highlighted as a mistake and says that "End Of Statement [is] Expected"
If it is for line39, then the End With statement is there.
If using vb2005, try adding each line in the With statement on it's own line, not with the ":" char. to combine code lines as one.
If just needing something to do and improve and you programming environment, you can download the 2008 express or the 2010 express versions from Microsoft. 2005 "is so like yesterday":D.
codeorder
Posting Virtuoso
1,913 posts since Aug 2010
Reputation Points: 255
Solved Threads: 384