Write Carriage Return in Multiline textbox

T

Tim

Hi Guys,

I want to write a string to a multiline textbox. Below is the code.
Works great except the carriage returns are displayed as squares.

What do I need to do to have the text displayed properly with returns.

Tim

PrintDocument pDoc = new PrintDocument();
Margins margins;

string strDefaultPrinter = pDoc.PrinterSettings.PrinterName;
string results = "";
PrinterMargins pMargins = new PrinterMargins();

foreach(string strPrinter in PrinterSettings.InstalledPrinters)
{
pDoc.PrinterSettings.PrinterName = strPrinter;

results += pDoc.PrinterSettings.PrinterName + "\n\r\n\r";

if(pDoc.PrinterSettings.IsValid)
{
margins = pMargins.GetHardMargins(pDoc.PrinterSettings, false);
results += "Top: " + margins.Top.ToString() + "\n\r";
results += "Left: " + margins.Left.ToString() + "\n\r";
results += "Bottom: " + margins.Bottom.ToString() + "\n\r";
results += "Right: " + margins.Right.ToString() + "\n\r";
}
else
{
results += "This printer is not a valid printer!";
}

results += "\n\r\n\r\n\r";
}

this.txtPrintTestResults.Text = results;
 
G

Guest

I've used the following to insert a new line and used the 'nl' variable
instead of the \n

static string nl = Environment.NewLine;
 
C

cwineman

I think Enviroment.NewLine will work.

TextBox1.Text() = "Abbot and" + Environment.NewLine + " Costello"

-cwineman
 
C

cwineman

Cool. I guess my example should have actually been in C# instead of VB.NET.
Anyway, you figured it out.
 
S

Saleh M. Ghaleb

Tim

Environment.NewLine will do the trick but for your code to work you should
use "\r\n" instead of "\n\r"

Saleh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top