Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Visual Studio 2005 Windows Application MsgBox = Text 2

Status
Not open for further replies.

gwoman

Programmer
Nov 16, 2004
199
0
0
US
I am a new programmer ... and I am working with a Windows App using C#. I am debugging and in one instance I am using the MsgBox()to display my my arguments passed into an OpenDocument function. It works fine but would like to have it displayed in a TextBox type environment so that I can cut and paste the argument string that is being passed.
I would greatly appreciate and suggestions or snipet of code anyone has to offer ... Thanks much!

gwoman
 
Just so you know - using a messagebox for debugging purposes is bad and I'll explain why.

I once saw a developer write something that is not exactly worksafe in a messagebox for debugging purposes. He forgot to erase it and since the code only executed when an exception occurred, he didn't see it. Then the day before release (thankfully) the boss of the company he was working for was doing some final testing and review when the exception occurred. That didn't go over so well.


Instead, use Console.WriteLine("youtexthere");

You can copy and paste from the output window in Visual Studio that way. There is also a Debug.WriteLine() which can be helpful in a production environment.
 
PERFECT!!! You Rock!
Thanks ... have a good one!
gwoman
 
I think the best way to do this is to use:

Code:
System.Diagnostics.Debug.WriteLine("Your message");

This writes the output to an attached debugger's output window (The debugger will probably be Visual Studio, but it might not). In a Windows application this is much the same thing that JurkMonkey's console.WriteLine will do. However Debug.WriteLine will be removed from the code when you do a release build.

Also it makes a big difference when you are writing a Console application. As in these project types console.WriteLine no longer goes to the debugger output, but to the console window instead. Debug.WriteLine continues to go to the debugger's output window.

If you want to be able to write to an attached Debugger's output window even with a Release build you can use.

Code:
System.Diagnostics.Trace.WriteLine("Your message");

With these functions you can also attach a System.Diagnostics.TraceListener class that can send the output to a file, email message or where ever else you want it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top