在打印时控制行间距!!
在打印时控制行间距和对齐方式怎么写啊。谢谢了。我知道用PrintPageEventArgs.Graphics 最后一个参数来控制。但是那个参数应该怎么写我不会!!
[此贴子已经被作者于2006-10-20 20:20:50编辑过]
获取用于绘制页的 Graphics。
命名空间:System.Drawing.Printing
程序集:System.Drawing(在 system.drawing.dll 中)
Visual Basic(声明) |
---|
Public ReadOnly Property Graphics As Graphics |
Visual Basic(用法) |
---|
Dim instance As PrintPageEventArgs Dim value As Graphics value = instance.Graphics |
C# |
---|
public Graphics Graphics { get; } |
C++ |
---|
public: property Graphics^ Graphics { Graphics^ get (); } |
J# |
---|
/** @property */ public Graphics get_Graphics () |
JScript |
---|
public function get Graphics () : Graphics |
下面的代码示例假定已经在 printButton_Click
方法创建 PrintDocument 类的一个实例,调用
pd_PrintPage
方法,然后打印 pd_PrintPage
方法中指定的 .bmp
文件。若要运行该示例,请更改要打印的位图的路径。
将
Visual Basic |
复制代码 |
---|---|
' Specifies what happens when the user clicks the Button. Private Sub printButton_Click(sender As Object, e As EventArgs) Try ' Assumes the default printer. Dim pd As New PrintDocument() AddHandler pd.PrintPage, AddressOf Me.pd_PrintPage pd.Print() Catch ex As Exception MessageBox.Show("An error occurred while printing", _ ex.ToString()) End Try End Sub ' Specifies what happens when the PrintPage event is raised. Private Sub pd_PrintPage(sender As Object, ev As PrintPageEventArgs) ' Draw a picture. ev.Graphics.DrawImage(Image.FromFile("C:\My Folder\MyFile.bmp"), _ ev.Graphics.VisibleClipBounds) ' Indicate that this is the last page to print. ev.HasMorePages = False End Sub |
C# | 复制代码 |
---|---|
// Specifies what happens when the user clicks the Button. |
C++ |
复制代码 |
---|---|
private: // Specifies what happens when the user clicks the Button. void printButton_Click( Object^ /*sender*/, EventArgs^ /*e*/ ) { try { // Assumes the default printer. PrintDocument^ pd = gcnew PrintDocument; pd->PrintPage += gcnew PrintPageEventHandler( this, &Form1::pd_PrintPage ); pd->Print(); } catch ( Exception^ ex ) { MessageBox::Show( "An error occurred while printing", ex->ToString() ); } } // Specifies what happens when the PrintPage event is raised. void pd_PrintPage( Object^ /*sender*/, PrintPageEventArgs^ ev ) { // Draw a picture. ev->Graphics->DrawImage( Image::FromFile( "C:\\My Folder\\MyFile.bmp" ), ev->Graphics->VisibleClipBounds ); // Indicate that this is the last page to print. ev->HasMorePages = false; } |
J# |
复制代码 |
---|---|
// Specifies what happens when the user clicks the Button. private void printButton_Click(Object sender, EventArgs e) { try { // Assumes the default printer. PrintDocument pd = new PrintDocument(); pd.add_PrintPage(new PrintPageEventHandler(this.pd_PrintPage)); pd.Print(); } catch (System.Exception ex) { MessageBox.Show("An error occurred while printing", ex.ToString()); } } //printButton_Click // Specifies what happens when the PrintPage event is raised. private void pd_PrintPage(Object sender, PrintPageEventArgs ev) { // Draw a picture. ev.get_Graphics().DrawImage(Image.FromFile ("C:\\My Folder\\MyFile.bmp"), ev.get_Graphics().get_VisibleClipBounds()); // Indicate that this is the last page to print. ev.set_HasMorePages(false); } //pd_PrintPage |
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见