Click here to Skip to main content
11,634,796 members (68,834 online)
Click here to Skip to main content

Titles - Easy Control Over MessageBox, InputBox, and Form Titles

, 17 Nov 2009 CPOL 10.2K 4
Rate this:
Please Sign up or sign in to vote.
Simple enum and method to set MessageBox, InputBox, and Form titles.

Introduction

The code snippet included below allows quick and easy control over Form titles for message boxes and input boxes and basically any other Windows Form title. When working as a team, trying to remember what other members are using for an error message or for missing information or any other normal message box or input box gets crazy. Even when working on a project alone, trying to remember the wording you used for "Missing Data" takes time to search in an effort to have the program look uniform.

Background

While creating a project that has about 1,000 various popup message boxes and input boxes, I was looking for a method to control what would be used for tTitles on Forms like message box and input box. When left up to the individual, we tended to get basically anything. For a general program error, we were getting "Program Error", "Error", "Prgm Er", "Action Not Complete", "Action Not Done", etc. etc. etc!

So, I wanted to write a method that would allow simple retrieval of values that the team agreed to and could stick with. Instead of creating a table or an XML doc to hold these values, it was easier just to place the values in an enum and create a method of getting the enum name, not value, and return that string to the calling code.

We used an "_" to separate the words, because the can be no spaces in an enum, and then simply used a Replace to insert a " ", so the title would read like normal text. The values of the enum does not matter, so no need to associate any values with the enum, or even what order they are put in the enum.

Using the Code

To use the following code, create a module and name it what you will. We named our module MsgTitles. We only have the MsgTitles enum and the GetTitle method in the module for ease of use.

Save the module in your project. Add code for a message box, for example, and when prompted by intellisense for a title, type "GetTitle(". You will be prompted by intellisense for any of your MsgTitles enums. You can then just start typing any of the enums to fill in your code. Close off the GetTitle with a ")" and finish off your message box.

When the message box is called in code, the GetTitle method will get the name of the enum, turn it into a string, and replace the "_" characters with " ".

' 
' Vb.NET code  - Cope All into Module
' Here is a list of generally used Titles for InputBox and MsgBox
' Add any Title you want to make available to your programmers
' Ex of Title: Please Input Your Name = Please_Input_Your_Name
Public Enum MsgTitles
    Action_Not_Permitted
    Action_Complete
    Verify
    Message
    Additonal_Info_Needed
    Program_Error
    Need_a_Name
    Need_an_Amount
    Need_a_Date
    Need_a_Contact
    Data_Saved
    Data_Deleted
    Data_Added
    Warning
    Empty_Folder
    Dont_let_soem_one_Tipe_sumthin_lik_thes
End Enum
'Function to Get Enum Name String and remove "_" and replace with " " 

Public Function GetTitle(ByVal Title As MsgTitles) As String
    Return Replace([Enum].GetName(GetType(MsgTitles), Title), "_", " ").ToString
End Function

'-----------------------------------------------------
        
'To use in a form just place a normal msgbox like the following in your code

MsgBox("Would you like to control the TITLES that your programs use??" + &_
       " Help your team use the SAME WORDS!!", MsgBoxStyle.Critical + _
       MsgBoxStyle.OkOnly, GetTitle(MsgTitles.Dont_let_soem_one_Tipe_sumthin_lik_thes))
 or 
Dim newDesc As String = InputBox("Enter an description.", _
                        GetTitle(MsgTitles.Additonal_Info_Needed), "")

Points of Interest

This function could be used for nearly any re-occurring string needed for any form. Was thinking about adding a routine to check that when a form opened up that it had a title and not a blank caption, and if it was blank, to pull a generic form title from the enum.

Please feel free to comment, or add other ideas of how to use!

History

Just created - No updates.

License

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

Share

About the Author

Drew Stegon
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

 
GeneralMy vote of 2 Pin
Sunito23-Nov-09 22:06
memberSunito23-Nov-09 22:06 
GeneralMy vote of 2 Pin
Preston McCormick23-Nov-09 10:16
memberPreston McCormick23-Nov-09 10:16 
GeneralMy vote of 2 Pin
zulu23-Nov-09 9:51
memberzulu23-Nov-09 9:51 
GeneralInteresting way to do it! Pin
Dinesh Mani17-Nov-09 19:19
memberDinesh Mani17-Nov-09 19:19 
GeneralRe: Interesting way to do it! Pin
Drew Stegon18-Nov-09 17:05
memberDrew Stegon18-Nov-09 17:05 
GeneralRe: Interesting way to do it! Pin
Dinesh Mani18-Nov-09 17:45
memberDinesh Mani18-Nov-09 17:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150728.1 | Last Updated 17 Nov 2009
Article Copyright 2009 by Drew Stegon
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid