Click here to Skip to main content
15,881,424 members
Articles / Programming Languages / Visual Basic
Tip/Trick

Custom MessageBox with checkbox

Rate me:
Please Sign up or sign in to vote.
5.00/5 (4 votes)
11 Sep 2016CPOL 16.9K   965   2  
This is a simple class that allows you to have message box with checkbox and other small features.

Introduction

I found myself in need of a classical messagebox with checkbox but all the classes I've tried writing in the register Windows preference, however I needed to write the result in the personal .ini setting of the program and so I decided to develop a class of my own that returned the value of the DialogResult and checkbox.

Using the Code

Using the class is very simple. Add the class and resource file to your project and you can use one of the examples attached to the project.

VB.NET
Dim check As Boolean = False
Dim reslt As DialogResult = myMsgBox.Show("writing test 1",
                            "Test", myMsgBox.Buttons.OK, myMsgBox.Icon.Information, 
                            "do not ask me again", check)

There are 32 different combinations of messagebox (with or without checkboxes, custom fonts, buttons with custom text and more).

Constants are present at the start of the sheet to vary text and size of the messagebox.

VB.NET
Const frmminWidth As Integer = 345
Const frmminHeight As Integer = 160

Const frmmaxWidth As Integer = 800
Const frmmaxHeight As Integer = 600

Const txtminWidth As Integer = 250
Const txtminHeight As Integer = 60

Const txtmaxWidth As Integer = 700
Const txtmaxHeight As Integer = 500

'changes the text of the tests according to your language and preference
Const txt_OK As String = "Ok"
Const txt_Cancel As String = "Cancel"
Const txt_Abort As String = "Abort"
Const txt_Retry As String = "Riprova"
Const txt_Ignore As String = "Ignora"
Const txt_Yes As String = "Si"
Const txt_No As String = "No"

The icons in the resource files have been downloaded from here.

History

  • September 11, 2016 - First posting

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Italy Italy
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
-- There are no messages in this forum --