【发布时间】:2018-07-24 08:38:33
【问题描述】:
是否可以在使用 webbrowser 控件时更改打印机的方向?我需要将其更改为横向。如果我需要更改打印机本身的打印机默认设置,那没关系,因为我会在完成后将它们重新设置。 (这就是我目前在使用非默认打印机打印时所要做的)。
我目前使用它来临时设置默认打印机,然后在我完成打印作业后将其重新设置...
private string SetDefaultPrinter(string newDefaultPrinter)
{
//Get the list of configured printers:
string strQuery = "SELECT * FROM Win32_Printer";
string currentDefault = string.Empty;
System.Management.ObjectQuery oq = new System.Management.ObjectQuery(strQuery);
System.Management.ManagementObjectSearcher query1 = new System.Management.ManagementObjectSearcher(oq);
System.Management.ManagementObjectCollection queryCollection1 = query1.Get();
System.Management.ManagementObject newDefault = null;
foreach (System.Management.ManagementObject mo in queryCollection1)
{
System.Management.PropertyDataCollection pdc = mo.Properties;
if ((bool)mo["Default"])
{
currentDefault = mo["Name"].ToString().Trim();
if (newDefaultPrinter == null || newDefaultPrinter == string.Empty)
{
//Just need to know the default name
break;
}
}
else if (mo["Name"].ToString().Trim() == newDefaultPrinter)
{
//Save this for later
newDefault = mo;
}
}
//Reset the default printer
if (newDefault != null)
{
//Execute the method
System.Management.ManagementBaseObject outParams = newDefault.InvokeMethod("SetDefaultPrinter", null, null);
}
return currentDefault;
}
有人知道如何改变方向吗?
【问题讨论】:
-
谢谢杰伊,是的,我找到了那个,并试图在该问题的给定答案中检查应用程序。永远无法使项目中的应用程序正常工作。但是对于这个问题,我从来没有看到真正回答了这个问题的答案。我还发现了一些其他问题,例如我在 SO 上的问题,但没有一个直接引用 c# 或非 wpf。我还想添加一些关于我当前代码的信息以设置默认打印机。 ;)
-
抱歉,我没有注意到您的非 WPF 状况。我最初回答说没有办法做你所要求的并引用kb236777。我意识到虽然我从来没有真正检查过这个,所以删除了我的答案。
-
:) 我希望这必须是在打印机上设置默认设置的某种方式......我现在并不关心 WebBrowser......我想我可以设置打印机默认值,然后打印。
标签: c# printing webbrowser-control orientation