Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 19.09.2010, 17:54   #1
strS
Пользователь
 
Регистрация: 16.01.2009
Сообщений: 19
По умолчанию напечатать форму (c#)

Подскажите пожалуйста как вывести форму на печать через printdialog в c#?

Вот нагуглил кое-что:

Код:
// Declare the PrintDocument object.
	private System.Drawing.Printing.PrintDocument docToPrint = 
		new System.Drawing.Printing.PrintDocument();

	// This method will set properties on the PrintDialog object and
	// then display the dialog.
	private void Button1_Click(System.Object sender, 
		System.EventArgs e)
	{

		// Allow the user to choose the page range he or she would
		// like to print.
		PrintDialog1.AllowSomePages = true;

		// Show the help button.
		PrintDialog1.ShowHelp = true;

		// Set the Document property to the PrintDocument for 
		// which the PrintPage Event has been handled. To display the
		// dialog, either this property or the PrinterSettings property 
		// must be set 
		PrintDialog1.Document = docToPrint;

		DialogResult result = PrintDialog1.ShowDialog();

		// If the result is OK then print the document.
		if (result==DialogResult.OK)
		{
			docToPrint.Print();
		}

	}

	// The PrintDialog will print the document
	// by handling the document's PrintPage event.
	private void document_PrintPage(object sender, 
		System.Drawing.Printing.PrintPageEventArgs e)
	{

		// Insert code to render the page here.
		// This code will be called when the control is drawn.

		// The following code will render a simple
		// message on the printed document.
		string text = "In document_PrintPage method.";
		System.Drawing.Font printFont = new System.Drawing.Font
			("Arial", 35, System.Drawing.FontStyle.Regular);

		// Draw the content.
		e.Graphics.DrawString(text, printFont, 
			System.Drawing.Brushes.Black, 10, 10);
	}
Взял из http://msdn.microsoft.com/ru-ru/libr...intdialog.aspx

Там сказано что для docToPrint нужно подключить событие PrintPage, а как его подключить я хз, особенно если у printdialog одно-единственное событие HelpRequest
strS вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Как создать форму в ручную и освободить из памяти предыдущую форму, на С++Builder 2009? AndreyK Общие вопросы C/C++ 1 18.01.2012 20:54
Одну и ту же форму использовать как MDI-child форму и как модальную форму? PrimaryPro Общие вопросы Delphi 2 10.03.2010 20:52
напечатать текст из Memo Sanek777 Общие вопросы Delphi 1 30.08.2008 21:25
НАпечатать наибольшую последовательность состоящую gred Помощь студентам 6 23.03.2008 16:12
Как изменить стандартную форму на форму любой сложности QwErEn Общие вопросы Delphi 9 08.06.2007 11:44