2009-09-17 4 views
1

J'ai un contrôle et je veux peindre différemment dans la forme et lors de l'impression. Voici la façon dont je l'ai fait:GetDeviceCaps Technology

private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e) 
    { 
     Rectangle rect = myControl.ClientRectangle; 
     myControl.Render(e.Graphics, rect); 
     e.HasMorePages = false; 
    } 

et en fonction Render

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 
    } 

Mais quand le spectacle PrintDocumentDialog, le résultat du test est toujours DT_RASDISPLAY pas ce que je pensais être DT_RASPRINTER.

Alors, quelle est la bonne façon de le faire?

Merci

Répondre

4

Votre énumération DeviceCapTechnology est erroné

/* Device Technologies */ 
#define DT_PLOTTER   0 /* Vector plotter     */ 
#define DT_RASDISPLAY  1 /* Raster display     */ 
#define DT_RASPRINTER  2 /* Raster printer     */ 
#define DT_RASCAMERA  3 /* Raster camera     */ 
#define DT_CHARSTREAM  4 /* Character-stream, PLP   */ 
#define DT_METAFILE   5 /* Metafile, VDM     */ 
#define DT_DISPFILE   6 /* Display-file      */ 
Questions connexes