VB.net. How to get a customized msgbox. Working code

Hello friends here's the code: First create two forms: Form1 and Message (give to Message the size you want but adjust the location of the OK button and New Size(350, 0) in Form1). In Form1 insert following code:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Clic 
Message.Label1.Text = "The WordReference English-Italian Dictionary is a living, growing 
    dictionary.  It contains over 50,000 terms and 100,000 translations in both English and Italian"
       
Message.Label1.MaximumSize = New Size(350, 0)
Message.Label1.AutoSize = True
Message.Show()

    

End Sub


In Message form select all and then paste the following code:

Public Class Message
    Dim drag As Boolean
    Dim mousex As Integer
    Dim mousey As Integer



    Private Sub Message_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        CenterButton()

    End Sub
    Private Sub Message_Resize(ByVal sender As Object,
                     ByVal e As System.EventArgs) Handles MyBase.Resize
        CenterButton()
    End Sub
    Private Sub CenterButton()

        Label1.Top = (Me.ClientSize.Height / 2) - (Label1.Height / 2)
        Label1.Left = (Me.ClientSize.Width / 2) - (Label1.Width / 2)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Close()
    End Sub
 Private Sub Message_MouseDown(sender As Object, e As MouseEventArgs) Handles MyBase.MouseDown
        drag = True
        mousex = Windows.Forms.Cursor.Position.X - Me.Left
        mousey = Windows.Forms.Cursor.Position.Y - Me.Top
    End Sub
    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        If drag Then
            Me.Top = Windows.Forms.Cursor.Position.Y - mousey
            Me.Left = Windows.Forms.Cursor.Position.X - mousex
        End If
    End Sub

    Private Sub Message_MouseUp(sender As Object, e As MouseEventArgs) Handles MyBase.MouseUp
        drag = False
    End Sub
End Class


Done! Goodbye

No comments

Post a Comment