Click here to Skip to main content
15,910,872 members
Home / Discussions / C#
   

C#

 
GeneralRe: C# code SQL connection Pin
Christian Graus9-Mar-08 11:38
protectorChristian Graus9-Mar-08 11:38 
GeneralRe: C# code SQL connection Pin
Ravenet9-Mar-08 16:35
Ravenet9-Mar-08 16:35 
QuestionSimple way to round a decimal? Pin
Joplinazz9-Mar-08 10:23
Joplinazz9-Mar-08 10:23 
AnswerRe: Simple way to round a decimal? Pin
Christian Graus9-Mar-08 10:58
protectorChristian Graus9-Mar-08 10:58 
GeneralHelp with printDocument and printPreviewControl Pin
Jacob Dixon9-Mar-08 8:09
Jacob Dixon9-Mar-08 8:09 
GeneralRe: Help with printDocument and printPreviewControl Pin
Jacob Dixon9-Mar-08 9:28
Jacob Dixon9-Mar-08 9:28 
GeneralRe: Help with printDocument and printPreviewControl Pin
Christian Graus9-Mar-08 11:04
protectorChristian Graus9-Mar-08 11:04 
GeneralRe: Help with printDocument and printPreviewControl Pin
Jacob Dixon9-Mar-08 11:21
Jacob Dixon9-Mar-08 11:21 
I will post it, its kind of long.. but here it is:

public void getChilds(int Ccount)
{
    string path = Directory.GetCurrentDirectory();
    DirectoryInfo dInfo = new DirectoryInfo(path + @"\Children\");
    DirectoryInfo[] dirs = dInfo.GetDirectories();
    printPreviewControl1.Rows = dirs.Length;
    if (dirs.Length == Ccount)
    {
        currentChild = "Done";
        return;
    }

    if (currentChild != "Done")
    {
        switch (Ccount)
        {
            case 0:
                currentChild = dirs[0].Name;
                currentChildPath = dInfo + dirs[0].Name + @"\";
                break;
            case 1:
                currentChild = dirs[1].Name;
                currentChildPath = dInfo + dirs[1].Name + @"\";
                break;
            case 2:
                currentChild = dirs[2].Name;
                currentChildPath = dInfo + dirs[2].Name + @"\";
                break;
            case 3:
                currentChild = dirs[3].Name;
                currentChildPath = dInfo + dirs[3].Name + @"\";
                break;
            case 4:
                currentChild = dirs[4].Name;
                currentChildPath = dInfo + dirs[4].Name + @"\";
                break;
            case 5:
                currentChild = dirs[5].Name;
                currentChildPath = dInfo + dirs[5].Name + @"\";
                break;
            case 6:
                currentChild = dirs[6].Name;
                currentChildPath = dInfo + dirs[6].Name + @"\";
                break;
            case 7:
                currentChild = dirs[7].Name;
                currentChildPath = dInfo + dirs[7].Name + @"\";
                break;
            case 8:
                currentChild = dirs[8].Name;
                currentChildPath = dInfo + dirs[8].Name + @"\";
                break;
            case 9:
                currentChild = dirs[9].Name;
                currentChildPath = dInfo + dirs[9].Name + @"\";
                break;
            default:
                currentChild = "Done";
                return;
        }
        childCount++;
    }
    else
    {
        return;
    }
}

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
    getChilds(childCount);
    if (currentChild == "Done")
    {
        e.HasMorePages = false;
        return;
    }

    else
    {
        float x = e.PageBounds.Left;
        float r = e.MarginBounds.Right;
        float y = e.PageBounds.Top;
        float b = e.PageBounds.Bottom;
        float c = e.MarginBounds.Width / 2;

        e.Graphics.DrawString(top[0], new Font("Arial", 10), Brushes.Blue, r, y, new StringFormat(StringFormatFlags.DirectionRightToLeft));
        y += 1 + new Font("Arial", 10).GetHeight();
        e.Graphics.DrawString(top[1].ToString(), new Font("Arial", 10), Brushes.Blue, r, y, new StringFormat(StringFormatFlags.DirectionRightToLeft));
        y += 1 + new Font("Arial", 10).GetHeight();
        e.Graphics.DrawString(top[2], new Font("Arial", 10), Brushes.Blue, r, y, new StringFormat(StringFormatFlags.DirectionRightToLeft));
        y += 1 + new Font("Arial", 10).GetHeight();
        e.Graphics.DrawString(top[3], new Font("Arial", 10), Brushes.Blue, r, y, new StringFormat(StringFormatFlags.DirectionRightToLeft));
        y += (new Font("Arial", 10).GetHeight() * 2);

        e.Graphics.DrawString(currentChild, new Font("Times New Roman", 14, FontStyle.Bold ^ FontStyle.Underline), Brushes.Red, c - (currentChild.Length / 2), y, new StringFormat());

        FileStream fileOpen = new FileStream(currentChildPath + "Paid.daycare", FileMode.Open, FileAccess.Read);
        StreamReader fileSR = new StreamReader(fileOpen);
        string strLine = fileSR.ReadLine();
        times = 0;
        y += new Font("Times New Roman", 14, FontStyle.Bold ^ FontStyle.Underline).GetHeight();
        centerLine = y;
        rightLine = y;
        while (strLine != null)
        {
            if (times < 31)
            {
                y += 2 + new Font("Arial", 12).GetHeight();
                e.Graphics.DrawString(strLine, new Font("Arial", 10), Brushes.Black, x, y, new StringFormat());
                strLine = fileSR.ReadLine();
                times++;
            }
            else if (times > 30 && times < 61)
            {
                centerLine += 2 + new Font("Arial", 12).GetHeight();
                e.Graphics.DrawString(strLine, new Font("Arial", 10), Brushes.Black, c - strLine.Length, centerLine, new StringFormat());
                strLine = fileSR.ReadLine();
                times++;
            }
            else if (times > 60 && times < 91)
            {
                rightLine += 2 + new Font("Arial", 12).GetHeight();
                e.Graphics.DrawString(strLine, new Font("Arial", 10), Brushes.Black, r, rightLine, new StringFormat(StringFormatFlags.DirectionRightToLeft));
                strLine = fileSR.ReadLine();
                times++;
            }
        }
        e.HasMorePages = true;
    }
}


A lot of that is to make it print like 30 lines, then if it is over 30 lines then it prints in the center of the page, then if it is over 60 lines then it starts printing on the right side of the page.

Now my problem is, that it prints correctly to the PrintPreviewControl, but it just prints a blank page when you click print!

private void printToolStripMenuItem_Click(object sender, EventArgs e)
{
    printDocument1.Print();
}


the printpreviewControl document is set to: printDocument1. The printDocument1 name is printDocument1, but why does it print a blank page when this code actually prints the information to the printDocument and it SHOWS it on the printPreviewControl?
GeneralRe: Help with printDocument and printPreviewControl Pin
Christian Graus9-Mar-08 11:43
protectorChristian Graus9-Mar-08 11:43 
GeneralRe: Help with printDocument and printPreviewControl Pin
Jacob Dixon9-Mar-08 11:51
Jacob Dixon9-Mar-08 11:51 
GeneralRe: Help with printDocument and printPreviewControl Pin
Jacob Dixon9-Mar-08 12:17
Jacob Dixon9-Mar-08 12:17 
GeneralRe: Help with printDocument and printPreviewControl Pin
Jacob Dixon9-Mar-08 12:34
Jacob Dixon9-Mar-08 12:34 
GeneralRe: Help with printDocument and printPreviewControl Pin
bhavik s25-May-11 1:27
bhavik s25-May-11 1:27 
GeneralChannels Pin
ytubis9-Mar-08 7:36
ytubis9-Mar-08 7:36 
GeneralRe: Channels Pin
Luc Pattyn9-Mar-08 8:27
sitebuilderLuc Pattyn9-Mar-08 8:27 
GeneralRe: Channels Pin
ytubis9-Mar-08 9:51
ytubis9-Mar-08 9:51 
GeneralRe: Channels Pin
Luc Pattyn9-Mar-08 10:18
sitebuilderLuc Pattyn9-Mar-08 10:18 
GeneralRe: Channels Pin
Christian Graus9-Mar-08 11:05
protectorChristian Graus9-Mar-08 11:05 
GeneralSplash Screen Dispose Pin
gmhanna9-Mar-08 7:14
gmhanna9-Mar-08 7:14 
GeneralRe: Splash Screen Dispose Pin
Judah Gabriel Himango9-Mar-08 11:02
sponsorJudah Gabriel Himango9-Mar-08 11:02 
GeneralRe: Splash Screen Dispose Pin
gmhanna16-Mar-08 6:36
gmhanna16-Mar-08 6:36 
QuestionOpening files [modified] Pin
nike_arh9-Mar-08 7:12
nike_arh9-Mar-08 7:12 
GeneralRe: Opening files Pin
Giorgi Dalakishvili9-Mar-08 9:29
mentorGiorgi Dalakishvili9-Mar-08 9:29 
GeneralSome questions regarding ListView fundamental behaviour Pin
eyalbi0079-Mar-08 6:55
eyalbi0079-Mar-08 6:55 
GeneralRe: Some questions regarding ListView fundamental behaviour Pin
LongRange.Shooter10-Mar-08 9:22
LongRange.Shooter10-Mar-08 9:22 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.