Create custom messagebox help

(intended to be a normal message box but custom button names)

Page 1 of 1

2 Replies - 14837 Views - Last Post: 20 July 2010 - 01:20 PM Rate Topic: -----

#1 L14M333  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 07-May 10

Create custom messagebox help

Posted 20 July 2010 - 12:30 PM

Hello, i am fairly new to programming and vb.net and i am working on a small project but in the project i need a message box (2 different occasions) where the buttons, instead of Yes No say Pause and GO

now i have done ALOT of searching around and found very little on this case... then only good thing what made a little sense was this video here:

http://www.youtube.c...h?v=n8Txdf7bYEE

The video told me to make a new form (dialogue) and then in my main form add a public sub.

here is the sub i have:

Public Sub injectmessage(ByVal ingmessage As String)
        Dim topmessage As New Message
        Dialog1.Label1.Text = ingmessage
        Dialog1.ShowDialog()

    End Sub



all that does is puts the message on the message box

so i have got it that far and i think it may just be something simple to add but i do not know what :(


if anyone can help me it would be GREAT!


Thanks in advanced


Liam

Is This A Good Question/Topic? 1
  • +

Replies To: Create custom messagebox help

#2 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4496
  • View blog
  • Posts: 7,847
  • Joined: 08-June 10

Re: Create custom messagebox help

Posted 20 July 2010 - 12:44 PM

*
POPULAR

Create a new Form. Put a label and two buttons on the form.
CustomMessageBox.vb
Public Class CustomMessageBox

    Public Sub New(ByVal message As String, ByVal button1Name As String, ByVal button2name As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Label1.Text = message
        Button1.Text = button1Name
        Button2.Text = button2name
        DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DialogResult = Windows.Forms.DialogResult.Yes
        Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DialogResult = Windows.Forms.DialogResult.No
        Close()
    End Sub
End Class


Form1.vb
Dim msg As New CustomMessageBox("My Message", "Go", "Pause")
Dim result = msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
    'user clicked "go"
ElseIf result = Windows.Forms.DialogResult.No Then
    'user clicked "pause"
Else
    'user closed the window without clicking a button
End If


This is a customizable dialog with two buttons. You could create one even more customizable if you wanted.
Was This Post Helpful? 5
  • +
  • -

#3 L14M333  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 14
  • Joined: 07-May 10

Re: Create custom messagebox help

Posted 20 July 2010 - 01:20 PM

View PostinsertAlias, on 20 July 2010 - 11:44 AM, said:

Create a new Form. Put a label and two buttons on the form.
CustomMessageBox.vb
Public Class CustomMessageBox

    Public Sub New(ByVal message As String, ByVal button1Name As String, ByVal button2name As String)

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        Label1.Text = message
        Button1.Text = button1Name
        Button2.Text = button2name
        DialogResult = Windows.Forms.DialogResult.Cancel
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        DialogResult = Windows.Forms.DialogResult.Yes
        Close()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        DialogResult = Windows.Forms.DialogResult.No
        Close()
    End Sub
End Class


Form1.vb
Dim msg As New CustomMessageBox("My Message", "Go", "Pause")
Dim result = msg.ShowDialog()
If result = Windows.Forms.DialogResult.Yes Then
    'user clicked "go"
ElseIf result = Windows.Forms.DialogResult.No Then
    'user clicked "pause"
Else
    'user closed the window without clicking a button
End If


This is a customizable dialog with two buttons. You could create one even more customizable if you wanted.



THANKYOU! works perfect! (i plus repped :))
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1