Solved

Custom Width Message Box per Label Length?

Posted on 2006-07-07
5
383 Views
Last Modified: 2011-10-03
I have two problems:

1. My text does not show on my message box, I found the Thread(sleep) is a problem.....

2. I would like to base the winform (custom message box) on the varrying label length...

Leave it to microsoft to NOT allow for a more flexable MessageBox.Show.
As if thier thousands of programmers have never needed to auto-close one.

Anyway, here's what I have so far:

[Messages form]
      private void Messages_Load(object sender, EventArgs e)
        {
            this.Width = lblMessage.Text.Length;   // always too narrow, cuts-off half of label.
        }


[Form1] calling Messages form to open....

      Messages msg = new Messages();            
      msg.lblMessage.Text = "Thank You For Choosing Us";  
      msg.Show();
      Thread.Sleep(3000);
      msg.Close();
0
Comment
Question by:kvnsdr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 11

Expert Comment

by:vo1d
ID: 17063029
implement a timer in your Messages form, which is started just after been shown.
if its count down from 3 seconds, close your Messages form.
0
 
LVL 1

Author Comment

by:kvnsdr
ID: 17063550
That sounds like a great idea.

Any idea why the message form doesn't expand to the correct width?
0
 
LVL 11

Expert Comment

by:vo1d
ID: 17064318
yes, do you want your message shown in one line or in multiline?
0
 
LVL 11

Accepted Solution

by:
vo1d earned 250 total points
ID: 17064417
here is an example, how you can do it. the message is in one line:

public partial class MessageForm : Form
    {
        private Timer _timer = new Timer();
       
        public MessageForm(string Message, int showTime)
        {
            InitializeComponent();                        
            this.FormBorderStyle      = FormBorderStyle.FixedSingle;
            this._messageLabel.Text = Message;
            this.ClientSize                = new Size(this._messageLabel.Width + 8, this._messageLabel.Height + 8);
            this._timer.Interval         = showTime;
            this._timer.Tick            += new EventHandler(TimerTickHandler);            
        }

        private void MessageForm_Load(object sender, EventArgs e)
        {            
            this._timer.Start();
        }
       
        void TimerTickHandler(object sender, EventArgs e)
        {
            this.Close();
        }
    }

the messageLabel has the location 4, 4.


in your mainform, you will just have to do this:

MessageForm frm = new MessageForm("Thank You For Choosing Us", 3000);
frm.ShowDialog();


if you wanna display short messages, you will have to change the line:
this.FormBorderStyle      = FormBorderStyle.FixedSingle;

to

this.FormBorderStyle      = FormBorderStyle.FixedToolWindow;

otherwise, the window will not size down  its width to the label width on short messages because of the caption bars control boxes.

regards, vo1d
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17065179
WshShell.Popup:

http://www.ss64.com/wsh/popup.html

Notice the 'nSecondsToWait'.

1) Add a COM reference to 'Windows Script Host Object Model'
2) Instantiate a WshShell object
3) Call the Popup method

Bob
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Where does legacy ASP.NET initialize language? 2 100
C# Service FileSystemwatcher isse 9 64
C# Get Current Exchange Rate from XE 9 42
asp.net repeater server posting 5 36
Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question