Avatar billede _et Praktikant
16. september 2004 - 14:36 Der er 1 kommentar og
1 løsning

udskrift af stringe på angivne positioner

Jeg skal have udskrevet nogle stringe bestemte steder på et a4 papir.

Jeg har problemer med at funde ud af hvordan jeg bestemmer placeringen af udskriftet.

Et lille eksempel, der udskriver streng1 i højre top, og streng2 midt i bunden, ville være det ultimative, men gode hints/kode blokke vil også være fint.
Avatar billede _et Praktikant
17. september 2004 - 13:48 #1
Du skal bare gøre sådan her :

        protected void ThePrintDocument_PrintPage (object sender, System.Drawing.Printing.PrintPageEventArgs ev)
        {
            float linesPerPage = 0;
            float leftMargin = ev.MarginBounds.Left;
            float topMargin = ev.MarginBounds.Top;
            Font printFont = new Font("arial", 10f);

            SolidBrush myBrush = new SolidBrush(Color.Black);

            float Kolonne_1_Left = ev.MarginBounds.Width * 0.333f;
            float Kolonne_2_Left = ev.MarginBounds.Width * 0.666f;
            float Kolonne_3_Left = ev.MarginBounds.Width;

            float Felt_1_fra_top = ev.MarginBounds.Height * 0.125f;
            float Felt_2_fra_top = ev.MarginBounds.Height * 0.250f;
            float Felt_3_fra_top = ev.MarginBounds.Height * 0.375f;
            float Felt_4_fra_top = ev.MarginBounds.Height * 0.500f;
            float Felt_5_fra_top = ev.MarginBounds.Height * 0.625f;
            float Felt_6_fra_top = ev.MarginBounds.Height * 0.750f;
            float Felt_7_fra_top = ev.MarginBounds.Height * 0.875f;
            float Felt_8_fra_top = ev.MarginBounds.Height;

            linesPerPage = ev.MarginBounds.Height / printFont.GetHeight(ev.Graphics);
//Kolonne 1
            ev.Graphics.DrawString("Teddy Holm Roskvist", printFont, myBrush, Kolonne_1_Left, Felt_1_fra_top, new StringFormat());
            ev.Graphics.DrawString("Nattergalvej 15, st th", printFont, myBrush, Kolonne_1_Left, (Felt_1_fra_top + printFont.GetHeight(ev.Graphics)), new StringFormat());
            ev.Graphics.DrawString("8900 Randers", printFont, myBrush, Kolonne_1_Left, (Felt_1_fra_top + (2* printFont.GetHeight(ev.Graphics))), new StringFormat());
            ev.Graphics.DrawString("Danmark", printFont, myBrush, Kolonne_1_Left, (Felt_1_fra_top + (3 * printFont.GetHeight(ev.Graphics))), new StringFormat());

            ev.Graphics.DrawString(".250", printFont, myBrush, Kolonne_1_Left, Felt_2_fra_top, new StringFormat());
            ev.Graphics.DrawString(".375", printFont, myBrush, Kolonne_1_Left, Felt_3_fra_top, new StringFormat());
            ev.Graphics.DrawString(".500", printFont, myBrush, Kolonne_1_Left, Felt_4_fra_top, new StringFormat());
            ev.Graphics.DrawString(".625", printFont, myBrush, Kolonne_1_Left, Felt_5_fra_top, new StringFormat());
            ev.Graphics.DrawString(".750", printFont, myBrush, Kolonne_1_Left, Felt_6_fra_top, new StringFormat());
            ev.Graphics.DrawString(".875", printFont, myBrush, Kolonne_1_Left, Felt_7_fra_top, new StringFormat());
            ev.Graphics.DrawString("siddehøjde", printFont, myBrush, Kolonne_1_Left, Felt_8_fra_top, new StringFormat());
// Kolonne 2
            ev.Graphics.DrawString("K2 .125", printFont, myBrush, Kolonne_2_Left, Felt_1_fra_top, new StringFormat());
            ev.Graphics.DrawString(".250", printFont, myBrush, Kolonne_2_Left, Felt_2_fra_top, new StringFormat());
            ev.Graphics.DrawString(".375", printFont, myBrush, Kolonne_2_Left, Felt_3_fra_top, new StringFormat());
            ev.Graphics.DrawString(".500", printFont, myBrush, Kolonne_2_Left, Felt_4_fra_top, new StringFormat());
            ev.Graphics.DrawString(".625", printFont, myBrush, Kolonne_2_Left, Felt_5_fra_top, new StringFormat());
            ev.Graphics.DrawString(".750", printFont, myBrush, Kolonne_2_Left, Felt_6_fra_top, new StringFormat());
            ev.Graphics.DrawString(".875", printFont, myBrush, Kolonne_2_Left, Felt_7_fra_top, new StringFormat());
            ev.Graphics.DrawString("siddehøjde", printFont, myBrush, Kolonne_2_Left, Felt_8_fra_top, new StringFormat());
// Kolonne 3
            ev.Graphics.DrawString("K3 .125", printFont, myBrush, Kolonne_3_Left, Felt_1_fra_top, new StringFormat());
            ev.Graphics.DrawString(".250", printFont, myBrush, Kolonne_3_Left, Felt_2_fra_top, new StringFormat());
            ev.Graphics.DrawString(".375", printFont, myBrush, Kolonne_3_Left, Felt_3_fra_top, new StringFormat());
            ev.Graphics.DrawString(".500", printFont, myBrush, Kolonne_3_Left, Felt_4_fra_top, new StringFormat());
            ev.Graphics.DrawString(".625", printFont, myBrush, Kolonne_3_Left, Felt_5_fra_top, new StringFormat());
            ev.Graphics.DrawString(".750", printFont, myBrush, Kolonne_3_Left, Felt_6_fra_top, new StringFormat());
            ev.Graphics.DrawString(".875", printFont, myBrush, Kolonne_3_Left, Felt_7_fra_top, new StringFormat());
            ev.Graphics.DrawString("siddehøjde", printFont, myBrush, Kolonne_3_Left, Felt_8_fra_top, new StringFormat());

            myBrush.Dispose();
             
        }
Avatar billede _et Praktikant
17. september 2004 - 13:49 #2
Tak skal du have.

Du får point :-)
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
IT-kurser om Microsoft 365, sikkerhed, personlig vækst, udvikling, digital markedsføring, grafisk design, SAP og forretningsanalyse.

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester