Solved

messagebox size?

Posted on 2006-06-16
3
471 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Unit testing, moq, best practices 7 28
send mail from app.net 8 28
creating a flowchart from an algorithm 5 22
Expando 4 34
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.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now