1

印刷プレビューダイアログに問題があります。印刷プレビューをクリックしても、プレビューページを印刷しても何も表示されません。プレビュー印刷出力を設定するメソッドを作成しました。どこが恋しかったのかわからない!

以下は私のコードです:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace movieList
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

    private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
    {
        // setup output
        Font printFont = new Font("Arial", 14);
        //print heading
        e.Graphics.DrawString("Select Name", printFont, Brushes.Black, 100, 100);

    }

    private void exitToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // terminate application
        this.Close();
    }

    private void clearAllCategoriesToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // clear all the list of the category 
        // first we use dialog box for confirmation request
        DialogResult confirmDialog = MessageBox.Show("Do you want to delete all category list ?","Clear Category List",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
        if (confirmDialog == DialogResult.Yes) 
        {
            // clearing the comboBox list
            categoryComboBox.Items.Clear();
        }
    }

    private void displayTheMovieCategoryCountToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // count the number of category list
        int listCountInteger = categoryComboBox.Items.Count;
        MessageBox.Show("There are " + listCountInteger + " categories in the list", "ComboBox Count", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }

    private void removeACategoryToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // remove a category name from list
        // first checking if a category has selected
        if (categoryComboBox.SelectedIndex == -1)
        {
            MessageBox.Show("Please Select a Category", "Wrong Selection", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else 
        {
            categoryComboBox.Items.RemoveAt(categoryComboBox.SelectedIndex);
        }
    }

    private void addACategoryToolStripMenuItem_Click(object sender, EventArgs e)
    {
        // add a category to list 
        // first checking for no duplicate name

        int indexNumberInteger=0;
        bool foundNameBoolean=false;

        if (categoryComboBox.Text == string.Empty)
        {
            //empty string has been entered
            MessageBox.Show("Please Enter the new category Name !", "Empty Name", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        else
        { 
            while(indexNumberInteger<categoryComboBox.Items.Count && !foundNameBoolean)
            {
                if (categoryComboBox.Text.ToUpper() == categoryComboBox.Items[indexNumberInteger++].ToString().ToUpper())
                {
                    MessageBox.Show("This Category is already in the list, Please write a new one !", "Duplicate Data", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    foundNameBoolean = true;
                }

            }

            if (!foundNameBoolean)
            { 
                // add new name to category
                categoryComboBox.Items.Add(categoryComboBox.Text);
                categoryComboBox.Text = string.Empty;
                MessageBox.Show("Category has been updated !");
            }
        }

    }

    private void printTheCategoryListToolStripMenuItem_Click(object sender, EventArgs e)
    {
       // print preview
        printPreviewDialog1.Document = printDocument1;
        printPreviewDialog1.ShowDialog();
    }
}

}

そしてプレビュー画像:

ここに画像の説明を入力してください

4

1 に答える 1

4

PrintPageイベントが接続されていることを確認してください。

public Form1() {
  InitializeComponent();
  printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
}
于 2012-11-17T13:20:21.837 に答える