?
Solved

messagebox size?

Posted on 2006-06-16
3
Medium Priority
?
480 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
[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 Comments
 
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

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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

764 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