Click here to Skip to main content
15,885,366 members
Articles / Programming Languages / C#
Article

Heybo Message Box-Customizable Message Box

Rate me:
Please Sign up or sign in to vote.
2.05/5 (12 votes)
10 Feb 20051 min read 46.9K   430   18   3
A customizable MessageBox with sound.

Sample Harness image

Introduction

I work on projects with non-technical operators. The workstations have a touch screen, with no mouse. Sometimes it is necessary to have a MessageBox display some information. At times, it is hard to be precise clicking Okay with the touch screens because of angle and difference of height of the operators and the small size of the buttons. I was unable to find a simple component to allow a MessageBox with customizable button sizes. I decided to write my own, with a few other features, since I could reuse it for other projects.

Background (optional)

Some others use hooks for existing API message boxes. The hooks generally overwrite the text on the buttons, not the size. This is based on the System.Windows.Forms.Form object. Therefore, you can specify the button size.

Using the code

This code snippet shows how to specify button size, button font, and line size using the HeyboBox.

C#
    // How to call the code with an icon and specified button size.
    HeyboBoxIcon hbi = HeyboBoxIcon.None;
    HeyboBoxButtons hbb = HeyboBoxButtons.OK;
    string text = "Sample Text";
    string caption = "My box caption";
    int buttonHeight = 100;
    int buttonWidth = 150;
    Form ownerForm = this;
    string lineLength = 100;
    Font font = new Font("Arial", 12f);
    DialogResult dr = Heybo.HeyboBox.Show( 
        ownerForm, text,
        caption, hbb, 
        hbi, 
        null,//default button
        buttonHeight,
        buttonWidth, lineLength,
        font);
//

Points of Interest

There may be another way of doing this without using the Windows API that is already established, but I could not find it. I made some enumerations for the button groups and for the images. Images are included as a resource in the library. Sounds have been implemented using P/Invoke, however, the code is a little messy.

The size of the box is dynamically determined by the largest of either buttons size, caption length, or text length. You may specify a new line character using the escape character for a new line. There is also a static property to change the font for both the buttons and the text.

History

Is being made...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Matt is a degree holder in Science and Computer Science. He is interested in .NET based technology. Currently he is employed as a software developer for a regional bank. He has been married since February of 2000 to the same person, and has a wonderful daughter and amazing long toed son. You may learn bits about him by visiting Heybo. He expects his third child August of 2006.

Comments and Discussions

 
Generala sick man Pin
youbest.cn7-Dec-06 17:11
youbest.cn7-Dec-06 17:11 
QuestionSource code ?!? Pin
hoangtg29-Nov-05 14:53
hoangtg29-Nov-05 14:53 
AnswerRe: Source code ?!? Pin
Boyko Markov6-Feb-07 1:45
Boyko Markov6-Feb-07 1:45 

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

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