Nota
O acesso a esta página requer autorização. Pode tentar iniciar sessão ou alterar os diretórios.
O acesso a esta página requer autorização. Pode tentar alterar os diretórios.
Frequentemente, você desejará imprimir gráficos no seu aplicativo baseado em Windows.A classe Graphics fornece métodos para desenhar objetos em um dispositivo, como a tela ou a impressora.
Para imprimir gráficos
Adicione um componente PrintDocument ao seu formulário.
No manipulador de eventos PrintPage, use a propriedade Graphics da classe PrintPageEventArgs para instruir a impressora sobre o tipo de gráfico que você quer imprimir.
O código exemplo a seguir mostra um manipulador de eventos usado para criar uma elipse azul dentro de um retângulo.O retângulo tem o seguinte local e dimensões: começando em 100, 150 com uma largura de 250 e uma altura de 250.
Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage e.Graphics.FillEllipse(Brushes.Blue, New Rectangle(100, 150, 250, 250)) End Subprivate void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.Graphics.FillRectangle(Brushes.Blue, new Rectangle(100, 150, 250, 250)); }private void printDocument1_PrintPage(Object sender, System.Drawing.Printing.PrintPageEventArgs e) { e.get_Graphics().FillRectangle(Brushes.get_Blue(), new Rectangle(100, 150, 250, 250)); }private: void printDocument1_PrintPage(System::Object ^ sender, System::Drawing::Printing::PrintPageEventArgs ^ e) { e->Graphics->FillRectangle(Brushes::Blue, Rectangle(100, 150, 250, 250)); }(Visual C#, Visual J# e Visual C++) Coloque o seguinte código no construtor do formulário para registrar o manipulador de eventos.
this.printDocument1.PrintPage += new System.Drawing.Printing.PrintPageEventHandler (this.printDocument1_PrintPage);this.printDocument1.add_PrintPage(new System.Drawing.Printing.PrintPageEventHandler( this.printDocument1_PrintPage));this->printDocument1->PrintPage += gcnew System::Drawing::Printing::PrintPageEventHandler (this, &Form1::printDocument1_PrintPage);