在标准PrintDialog中,有四个与选定打印机关联的值:状态,类型,位置和注释.
如果我知道打印机的名称,我怎样才能在C#2.0中获得这些值?
在我的WPF应用程序中,我将打印ListBox的内容.我想在PrintDialog框中添加一个新控件,以选择要打印的行数(项).
是否可以自定义现有的PrintDialog框并添加一个新的控件来绑定到ListBox.Count?
或者有更好的方法吗?
使用Wpf DocumentViewer控件我无法弄清楚当用户单击打印按钮时,如何在PrintDialog上设置DocumentViewer显示的PageOrientation.有没有办法搞定这个?
我正在开发的内部应用程序在Windows 7(64位)PC上表现得很奇怪.
如果我创建一个PrintDialog的实例,并调用它的ShowDialog()方法,该方法立即返回DialogResult.Cancel而不显示打印机对话框窗体.
Windows 7 PC确实安装了打印机(带有可用的默认打印机).
PrintDialog printDialog = new PrintDialog();
printDialog.PrinterSettings.Copies = 2;
printDialog.AllowCurrentPage = false;
printDialog.AllowPrintToFile = false;
printDialog.AllowSelection = false;
printDialog.AllowSomePages = false;
DialogResult dialogResult = printDialog.ShowDialog(this);
if (dialogResult == DialogResult.Cancel)
return;
Run Code Online (Sandbox Code Playgroud)
任何线索为什么会发生这种情况?
我刚开始学习如何在Java/Swing中打印窗口.(编辑:刚刚找到Java打印指南)
当我这样做:
protected void doPrint() {
PrinterJob job = PrinterJob.getPrinterJob();
job.setPrintable(this);
boolean ok = job.printDialog();
if (ok) {
try {
job.print();
}
catch (PrinterException ex) {
ex.printStackTrace();
}
finally {
}
}
}
Run Code Online (Sandbox Code Playgroud)
我得到这个打印机对话框(在Windows XP上):
如何更改页面范围,使其不是1-9999?
编辑:使用Pageable
/ Book
设置页面范围(如@t_barbz帮助指出)需要一个PageFormat,在这种情况下我有一个catch-22,因为我想要打印对话框来选择它,我似乎没有从打印对话框中获取返回值.
我有自定义控件与打印工具栏项.当打印控件对话框没有进入Windows 7与64位操作系统在其他系统操作系统工作正常.仅在具有64位的Windows 7中出现问题.
我的问题printdialog没有进入64位的Windows 7操作系统.
我已检查并分析 - > PrintDialog.ShowDialog()返回immeaditely取消instaed显示该问题的对话框.
我通过搜索以下链接找到了问题的解决方案:
http://social.msdn.microsoft.com/Forums/en/netfx64bit/thread/8760fb6c-ae63-444e-9606-cd3295ce6b5d
http://msdn.microsoft.com/en-us/library/system.windows.forms.printdialog.useexdialog.aspx
通过将true设置为printdialog的UseExDialog属性,对话框出现并且工作正常.但是这个对话框样式就像Windows XP而不是windows7样式.所以这不是解决方案.
UseExDialog属性设置为true表示工作正常.但打印对话框样式看起来像Windows XP打印不像Windows 7.我需要一些其他解决方案在Windows 7 os 64位显示打印对话框.
请为此问题提供完整的解决方案
谢谢
湿婆
我想使用SendMessage Windows API获取在Acrobat PrintDialog中选择的打印机的名称.
这是示例代码.
static string GetWindowText( hwnd_printDialog_in_Acrobat )
{
int comboBoxCount = 0;
int HWND_PRINTER_NAME = 1 ;
List<IntPtr> ChildPtrList = GetChildWindows(hwnd_printDialog_in_Acrobat);
for( i=0 ; i < ChildPtrList.Size(); i++) {
GetClassName( ChildPtrList[i], sClass, 100);
if (sClass.ToString() == "ComboBox") {
comboBoxCount++;
if (comboBoxCount == HWND_PRINTER_NAME ) {
hwnd = ChildPtrList[i];
break;
}
}
}
ChildPtrList.Clear();
int sSize ;
sSize = SendMessageW( hwnd, WM_GETTEXTLENGTH, IntPtr.Zero, IntPtr.Zero )+1;
StringBuilder sbTitle = new StringBuilder( sSize );
SendMessageW( hwn, WM_GETTEXT, (IntPtr)sSize, sbTitle);
return …
Run Code Online (Sandbox Code Playgroud) 我想在打印文档之前显示打印对话框,因此用户可以在打印前选择其他打印机.打印代码是:
private void button1_Click(object sender, EventArgs e)
{
try
{
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(PrintImage);
pd.Print();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ToString());
}
}
void PrintImage(object o, PrintPageEventArgs e)
{
int x = SystemInformation.WorkingArea.X;
int y = SystemInformation.WorkingArea.Y;
int width = this.Width;
int height = this.Height;
Rectangle bounds = new Rectangle(x, y, width, height);
Bitmap img = new Bitmap(width, height);
this.DrawToBitmap(img, bounds);
Point p = new Point(100, 100);
e.Graphics.DrawImage(img, p);
}
Run Code Online (Sandbox Code Playgroud)
这段代码能够打印当前表格吗?
我有一个WPF应用程序,需要在5分钟不活动后注销用户.
但是如果用户打开任何页面的打印对话框,并且不触摸屏幕5分钟,即使我注销用户并清除所有子元素,打印对话框仍然保留在WPF表单的顶部,有人可以继续打印什么永远的页面用户留下.
我试着用;
Window window = Application.Current.MainWindow;
Run Code Online (Sandbox Code Playgroud)
要么
FocusManager.GetFocusedElement();
Run Code Online (Sandbox Code Playgroud)
但无法实现访问PrintDialog并关闭它.
有没有办法访问它并关闭如果用户没有响应打印对话框?
我尝试打印出我的编辑器的内容:
PrintDialog pd = new PrintDialog();
pd.PageRangeSelection = PageRangeSelection.AllPages;
pd.UserPageRangeEnabled = true;
FlowDocument fd = DocumentPrinter.CreateFlowDocumentForEditor(CurrentDocument.Editor);
DocumentPaginator dp = ((IDocumentPaginatorSource)fd).DocumentPaginator;
bool? res = pd.ShowDialog();
if (res.HasValue && res.Value)
{
fd.PageHeight = pd.PrintableAreaHeight;
fd.PageWidth = pd.PrintableAreaWidth;
fd.PagePadding = new Thickness(50);
fd.ColumnGap = 0;
fd.ColumnWidth = pd.PrintableAreaWidth;
pd.PrintDocument(dp, CurrentDocument.Editor.FileName);
}
Run Code Online (Sandbox Code Playgroud)
我使用的测试文档大约有14页(使用此页面大小设置).我测试了它:printdialog出现了,我选择了一个页面范围(我在文本框中键入"1-3")并单击print
.上面printdocument()
我设置一个断点,看着PrintDialog类对象.它说pd.PageRangeSelection = PageRangeSelection.UserPage
和pd.PageRange = {1-3}
.我想这是对的,因为我只想打印出第1-3页.然后printdocument()
执行和输出-pdf(用于测试我使用pdf打印机)有14页(整个文件被打印).
我的错在哪里?为什么页面范围设置不起作用?
谢谢你的帮助