Click here to Skip to main content
16,005,178 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: How to Retiveing Time now? Pin
GuyThiebaut21-Sep-07 2:34
professionalGuyThiebaut21-Sep-07 2:34 
GeneralRe: How to Retiveing Time now? Pin
somsakchoto21-Sep-07 2:43
somsakchoto21-Sep-07 2:43 
GeneralRe: How to Retiveing Time now? Pin
GuyThiebaut21-Sep-07 2:52
professionalGuyThiebaut21-Sep-07 2:52 
GeneralRe: How to Retiveing Time now? Pin
somsakchoto21-Sep-07 3:03
somsakchoto21-Sep-07 3:03 
GeneralRe: How to Retiveing Time now? Pin
Colin Angus Mackay21-Sep-07 4:24
Colin Angus Mackay21-Sep-07 4:24 
QuestionPrint a Formm Pin
Trupti Mehta21-Sep-07 1:35
Trupti Mehta21-Sep-07 1:35 
AnswerRe: Print a Formm Pin
Duncan Edwards Jones21-Sep-07 3:15
professionalDuncan Edwards Jones21-Sep-07 3:15 
AnswerRe: Print a Formm Pin
JamesS[C1]21-Sep-07 3:42
JamesS[C1]21-Sep-07 3:42 
Hello Trupti,

Printing in Windows Forms consists primarily of using the PrintDocument Component (Windows Forms) component to enable the user to print, and the PrintPreviewDialog Control (Windows Forms) control, PrintDialog Component (Windows Forms) and PageSetupDialog Component (Windows Forms) components to provide a familiar graphical interface to users accustomed to the Windows operating system.

Typically, you create a new instance of the PrintDocument component, set the properties that describe what to print using the PrinterSettings and PageSettings classes, and call the Print method to actually print the document.

During the course of printing from a Windows-based application, the PrintDocument component will show an abort print dialog box to alert users to the fact that printing is occurring and to allow the print job to be canceled.

The foundation of printing in Windows Forms is the PrintDocument component—more specifically, the PrintPage event. By writing code to handle the PrintPage event, you can specify what to print and how to print it.

To create a print job:

1. Add a PrintDocument component to your form.

2. Write code to handle the PrintPage event.

You will have to code your own printing logic. Additionally, you will have to specify the material to be printed.

In the following code example, a sample graphic in the shape of a red rectangle is created in the PrintPage event handler to act as material to be printed.

Visual Basic Copy Code

Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
e.Graphics.FillRectangle(Brushes.Red, New Rectangle(500, 500, 500, 500))
End Sub



C# Copy Code

private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red,
new Rectangle(500, 500, 500, 500));
}



J# Copy Code
private void printDocument1_PrintPage(Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.get_Graphics().FillRectangle(Brushes.get_Red(),
new Rectangle(500, 500, 500, 500));
}


C++ Copy Code
private:
void printDocument1_PrintPage(System::Object ^ sender,
System::Drawing::Printing::PrintPageEventArgs ^ e)
{
e->Graphics->FillRectangle(Brushes::Red,
Rectangle(500, 500, 500, 500));
}

(Visual C#, Visual J# and Visual C++) Place the following code in the form's constructor to register the event handler.

C# Copy Code
this.printDocument1.PrintPage += new
System.Drawing.Printing.PrintPageEventHandler
(this.printDocument1_PrintPage);



J# Copy Code
this.printDocument1.add_PrintPage(new
System.Drawing.Printing.PrintPageEventHandler
(this.printDocument1_PrintPage));



C++ Copy Code
printDocument1->PrintPage += gcnew
System::Drawing::Printing::PrintPageEventHandler
(this, &Form1::printDocument1_PrintPage);

You may also want to write code for the BeginPrint and EndPrint events, perhaps including an integer representing the total number of pages to print that is decremented as each page prints.

Note

You can add a PrintDialog component to your form to provide a clean and efficient user interface (UI) to your users. Setting the Document property of the PrintDialog component enables you to set properties related to the print document you are working with on your form. For more information about the PrintDialog component, see PrintDialog Component (Windows Forms).

I hope this helps.

Have a nice day.

Regards,
James Smith


James Smith
www.componentone.com

Question, Print a Formm Pin
Trupti Mehta21-Sep-07 1:32
Trupti Mehta21-Sep-07 1:32 
QuestionDecimal Digits - can't figure why? Pin
Trupti Mehta21-Sep-07 1:32
Trupti Mehta21-Sep-07 1:32 
AnswerRe: Decimal Digits - can't figure why? Pin
Dave Kreskowiak21-Sep-07 5:20
mveDave Kreskowiak21-Sep-07 5:20 
GeneralRe: Decimal Digits - can't figure why? Pin
Trupti Mehta21-Sep-07 19:48
Trupti Mehta21-Sep-07 19:48 
GeneralRe: Decimal Digits - can't figure why? Pin
Dave Kreskowiak22-Sep-07 3:08
mveDave Kreskowiak22-Sep-07 3:08 
QuestionRedrawing the same line in vbnet 2003 Pin
Yasin78621-Sep-07 1:22
Yasin78621-Sep-07 1:22 
AnswerRe: Redrawing the same line in vbnet 2003 Pin
Ajay.k_Singh21-Sep-07 1:48
Ajay.k_Singh21-Sep-07 1:48 
GeneralRe: Redrawing the same line in vbnet 2003 Pin
Tom Deketelaere21-Sep-07 2:08
professionalTom Deketelaere21-Sep-07 2:08 
QuestionUsing Regular Expression Pin
Osama12320-Sep-07 23:30
Osama12320-Sep-07 23:30 
AnswerRe: Using Regular Expression Pin
Dave Kreskowiak21-Sep-07 5:08
mveDave Kreskowiak21-Sep-07 5:08 
QuestionText file to CSV file Pin
csridevi20-Sep-07 23:16
csridevi20-Sep-07 23:16 
AnswerRe: Text file to CSV file Pin
pmarfleet21-Sep-07 0:16
pmarfleet21-Sep-07 0:16 
GeneralRe: Text file to CSV file Pin
csridevi21-Sep-07 0:28
csridevi21-Sep-07 0:28 
AnswerRe: Text file to CSV file Pin
GuyThiebaut21-Sep-07 1:16
professionalGuyThiebaut21-Sep-07 1:16 
GeneralRe: Text file to CSV file Pin
txmrm21-Sep-07 10:12
txmrm21-Sep-07 10:12 
GeneralRe: Text file to CSV file Pin
GuyThiebaut21-Sep-07 10:15
professionalGuyThiebaut21-Sep-07 10:15 
QuestionHow to call the existing libraries containing unmanaged C++ classes Pin
Paramhans Dubey20-Sep-07 21:29
professionalParamhans Dubey20-Sep-07 21:29 

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.