gpt4 book ai didi

c# - GetDeviceCaps 技术

转载 作者:太空宇宙 更新时间:2023-11-03 22:25:52 28 4
gpt4 key购买 nike

我有一个控件,我想在表单和打印时以不同的方式绘制它。这是我做的方式:

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。

那么正确的做法是什么?

谢谢

最佳答案

你的 DeviceCapTechnology 枚举是错误的

/* 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 */

关于c# - GetDeviceCaps 技术,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1437073/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com