Solved

messagebox size?

Posted on 2006-06-16
3
476 Views
Last Modified: 2008-02-01
Hi

I do

MessageBox.Show("No response from " + listBox1.SelectedItem.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

but sometimes listBox1.SelectedItem is quite long (over 30 characters)

And this seems to make the messagebox massive (way bigger than required)

Is there a way to avoid a lot of whitespace?

Thanks
0
Comment
Question by:boofulls
3 Comments
 
LVL 5

Accepted Solution

by:
pgloor earned 20 total points
ID: 16919237
Idea: Split your message (e.g. into word tokens) and add a NewLine after any 50 characters or so, before showing the message on the screen.
--------------------------------------------------------------------------------------------------

const int LINE_SIZE = 50; // Max # of characters / line
String message = "No response from " + listBox1.SelectedItem.ToString();
string output = "";
String [] wordTokens = message.Split(new Char [] {' '});
int count = 0;
foreach (String token in wordTokens) {
  if (count + token.Length > LINE_SIZE) {
    output += Environment.NewLine + token;
    count = token.Length + 1;
  } else {
    if (output.Length == 0) {
      output = token;
      count = token.Length + 1;
    } else {
      output += " " + token;
      count += token.Length + 1;
    }
  }
}
MessageBox.Show(output, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

685 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