[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Printing to a Form in C#.NET

Posted on 2007-04-03
5
Medium Priority
?
292 Views
Last Modified: 2013-12-16
Hello,

Why doesn't Console.WriteLine("hello") write anything to the form from which I'm calling it (C#.NET)?  What's the best way to tell the program to print to the form?
0
Comment
Question by:NigelRocks
[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
  • 2
5 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 150 total points
ID: 18847522
To print on the form you need a Graphics context.

For temporary graphics writes use:

    Graphics g = this.CreateGraphics();
    g.DrawString(...stuff in here...);
    g.Dispose();

These will get erased when the form is refreshed such as if someone minimized it or if another form obscured it.

For persistent graphics use the graphics provided in the "e" parameter of the forms Paint() event...
0
 
LVL 64

Assisted Solution

by:Fernando Soto
Fernando Soto earned 150 total points
ID: 18847528
Hi NigelRocks;

The reason is that Console.Writeline writes to a console window. When you are using a Windows Form application there is no Console. When executing the code in a Windows Form and from the development IDE Console messages go to the Output window.

To display messages you can place a textBox  on the form and set its MultiLine property to true and then expand the textBox so that multiple lines can be displayed in it and use code like this

            textBox1.AppendText("Hello World\n");
            textBox1.AppendText("Another Hello World Message\n");

to write to it.

Fernando
0
 
LVL 2

Assisted Solution

by:mahanatti
mahanatti earned 75 total points
ID: 18862569
Console.WriteLine can be used to write to the console window in a Console Application but not to Windows Application since it uses GUI but not Console.

To print your form you could use the PrintDocument class in the System.Drawing.Printing namespace. Please refer http://www.codeproject.com/csharp/printform.asp that has a sample.
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 19252884
Hi Bob;

I believe this should be a point split. Everyone provided valid information about the question.

Thanks;

Fernando
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

656 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