1
我有一個控件,我想在Form和打印時以不同的方式繪製它。來這裏的路上,我做到了:GetDeviceCaps技術
private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
Rectangle rect = myControl.ClientRectangle;
myControl.Render(e.Graphics, rect);
e.HasMorePages = false;
}
和渲染功能
public void Render(Graphics g, Rectangle rect) {
DeviceCapTechnology dct = (DeviceCapTechnology)GetDeviceCaps(hDC, (int)DeviceCap.TECHNOLOGY);
if((dct & DeviceCapTechnoloy.DT_RASPRINTER) == DeviceCapTechnoloy.DT_RASPRINTER) {
//logic for print to printer
} else {
//normal logic
}
}
public enum DeviceCapTechnology
{
DT_PLOTTER = 0, //Vector plotter
DT_RASDISPLAY = 2, //Raster display
DT_RASPRINTER = 4, //Raster printer
DT_RASCAMERA = 6, //Raster camera
DT_CHARSTREAM = 8, //Character stream
DT_METAFILE = 10, //Metafile
DT_DISPFILE = 12 //Display file
}
但當PrintDocumentDialog顯示,測試的結果總是DT_RASDISPLAY不是我預計DT_RASPRINTER。
那麼正確的做法是什麼?
謝謝