?
Solved

messagebox size?

Posted on 2006-06-16
3
Medium Priority
?
482 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
1 Comment
 
LVL 5

Accepted Solution

by:
pgloor earned 80 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

862 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