Textbox drucken

Hallo,

Das sind doch Standartfehlermeldungen. Ein Blick in die Dokumentation oder Google hätte geholfen:
C#:
string[] lines = TextBox.Text.Split('\n');
 
Zuletzt bearbeitet von einem Moderator:
Hab ich, aber sogar auf anderen Seiten ist es so angegeben.

z.B.: textbox.text.split(char[],"-") hab ich auf einer Seite gefunden

Was macht den Unterschied?
 
Er macht mir den Zeilenumbruch nicht -.-

C#:
 void document_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {

float linesPerPage = 0;
            float yPos = 0;
            int count = 0;
            float leftMargin = e.MarginBounds.Left;
            float topMargin = e.MarginBounds.Top;
            string line = null;
            

            //X und Y Position des Texts auf der Seite bestimmen
            int x, y;
            x = e.MarginBounds.Left; //Ganz am linken Rand
            y = e.MarginBounds.Top; //Ganz oben

            //Schriftart laden in der gedruckt werden soll
            Font printFont = new Font("Arial", 10);

            linesPerPage = e.MarginBounds.Height;
            printFont.GetHeight(e.Graphics);

            string[] lines = textBox.Text.Split('\n');
            int lineCount = lines.Length;
           
            while (count < linesPerPage && count < lineCount)
            {
                yPos = topMargin + (count *
                  printFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(line, printFont, Brushes.Black,
                   leftMargin, yPos, new StringFormat());
                count++;
            }

            //Den Text der Textbox drucken
            e.Graphics.DrawString(textBox.Text, printFont, Brushes.Black,
                         x, y, new StringFormat());

            //Druckvorgang abschließen
            e.HasMorePages = false;
           
        }
 
Zuletzt bearbeitet von einem Moderator:
C#:
while (count < linesPerPage && count < lineCount)
            {
                yPos = topMargin + (count *
                  printFont.GetHeight(e.Graphics));
                e.Graphics.DrawString(line, printFont, Brushes.Black,
                   leftMargin, yPos, new StringFormat());
                count++;
            }
 
            //Den Text der Textbox drucken
            e.Graphics.DrawString(textBox.Text, printFont, Brushes.Black,
                         x, y, new StringFormat());

Ist es beabsichtigt, dass du zuerst Zeilenweise den Inhalt druckst, und dann nochmal über die erste Zeile den ganze String drüberschreibst?

Zu den Zeilenumbrüchen: Sind denn auch Zeilenumbrüche in dem String drinnen?
 
Zuletzt bearbeitet von einem Moderator:
C#:
           //X und Y Position des Texts auf der Seite bestimmen
            int x, y;
            x = e.MarginBounds.Left; //Ganz am linken Rand
            y = e.MarginBounds.Top; //Ganz oben

            //Schriftart laden in der gedruckt werden soll
            Font printFont = new Font("Arial", 10);

          

           

            Rectangle rect = new Rectangle(10, 10, this.ClientSize.Width - 20, this.ClientSize.Height - 20);

            using (StringFormat sf = new StringFormat())
            {
                sf.FormatFlags = StringFormatFlags.LineLimit;

                e.Graphics.DrawString(textBox.Text,printFont, Brushes.Black, rect, sf); 
                e.Graphics.DrawRectangle(Pens.Blue, rect);

                //e.Graphics.DrawString(textBox.Text, printFont, Brushes.Black,
                           //  x, y, new StringFormat());
            }
           
            
             e.HasMorePages = false; 
            //Druckvorgang abschließen

Jetzt gehts : )
 
Zuletzt bearbeitet von einem Moderator:

Neue Beiträge

Zurück