如何打开原生PRINTER DIALOG - 请帮助! [英] How to OPEN native PRINTER DIALOG -- Please HELP !!

查看:44
本文介绍了如何打开原生PRINTER DIALOG - 请帮助!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做我自己的PrintDialog,并在那里放置了一个带有

打印机名称的组合,就像VB.NET提供的PrintDialog一样。


以下是问题:如何为当前打印机打开本机Windows打印机对话框

,以便根据用户设置我当前的

PrintDocument.PrinterSettings选择




谢谢

-Pamela

我的代码问题。假设您已使用组合框ComboBoxPrinterNames停止了MyPrintDialog

表单。列出打印机和

按钮ButtonSelectedPrinterProperties

来设置当前的打印机属性。


----- ----------------------------------

Private Sub ButtonSelectedPrinterProperties_Click(ByVal sender As

System.Object,ByVal e As System.EventArgs)句柄

ButtonSelectedPrinterProperties.Click


Me.PrintDocument.PrinterSettings.PrinterName =

Me.ComboBoxPrinterNames.SelectedText

如果不是Me.PrintDocument.PrinterSettings.IsValid那么

MsgBox(Invalid printer,MsgBoxStyle.Information )

退出Sub

结束如果


Me.OpenPrinterPropertiesDialog(PrintDocument)

End Sub


Sub OpenPrinterPropertiesDialog(ByVal PrintDocument As

PrintDocument)


''????????我的问题:如何打开windows对话框

设置PrintDocument.PrinterSettings


结束子

------ --------------------------------------

I am doing my own PrintDialog, and have placed there a combo with the
printer names, as in the PrintDialog provided by VB.NET.

Here is the question: how do I open the native windows printer dialog
for the current printer, so that my current
PrintDocument.PrinterSettings will be set according to the User choices
?

Thanks
-Pamela
My question in code. Assume you have ceated a MyPrintDialog
form with a combo box "ComboBoxPrinterNames" listing the printers and a
button "ButtonSelectedPrinterProperties"
to set the current printer properties.

---------------------------------------
Private Sub ButtonSelectedPrinterProperties_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
ButtonSelectedPrinterProperties.Click

Me.PrintDocument.PrinterSettings.PrinterName =
Me.ComboBoxPrinterNames.SelectedText
If Not Me.PrintDocument.PrinterSettings.IsValid Then
MsgBox("Invalid printer", MsgBoxStyle.Information)
Exit Sub
End If

Me.OpenPrinterPropertiesDialog(PrintDocument)
End Sub

Sub OpenPrinterPropertiesDialog(ByVal PrintDocument As
PrintDocument)

'' ???????? my question: how to open the windows dialog for
setting PrintDocument.PrinterSettings

End Sub
--------------------------------------------

推荐答案




< pa *********** @ libero.it>在消息中写道

news:11 ********************** @ o13g2000cwo.googlegr oups.com ...
Hi,

<pa***********@libero.it> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
我正在做自己的PrintDialog,并在那里放置了一个带有
打印机名称的组合,就像VB.NET提供的PrintDialog一样。

这是一个问题:如何为当前打印机打开本机Windows打印机对话框,以便根据用户选择设置我当前的PrintDocument.PrinterSettings


谢谢
-Pamela

我的代码问题。假设您已使用组合框ComboBoxPrinterNames停止了MyPrintDialog
表单。列出打印机和
按钮ButtonSelectedPrinterProperties
以设置当前的打印机属性。

----------------- ----------------------
I am doing my own PrintDialog, and have placed there a combo with the
printer names, as in the PrintDialog provided by VB.NET.

Here is the question: how do I open the native windows printer dialog
for the current printer, so that my current
PrintDocument.PrinterSettings will be set according to the User choices
?

Thanks
-Pamela
My question in code. Assume you have ceated a MyPrintDialog
form with a combo box "ComboBoxPrinterNames" listing the printers and a
button "ButtonSelectedPrinterProperties"
to set the current printer properties.

---------------------------------------




没有太多保证虽然应该可以用一些原生的

函数:


公共类YourPrinterSettingsDialog

''本机函数

私有声明自动函数GlobalLock Lib" kernel32.dll" _

(ByVal handle As IntPtr)As IntPtr

私有声明自动函数GlobalUnlock Lib" kernel32.dll" _

(ByVal handle As IntPtr)As Integer

私有声明自动函数GlobalFree Lib" kernel32.dll" _

(ByVal handle As IntPtr)As IntPtr

私有声明自动函数DocumentProperties Libwinspool.drv _

(ByVal hWnd As IntPtr,ByVal hPrinter作为IntPtr,_

ByVal pDeviceName As String,ByVal pDevModeOutput As IntPtr,_

ByVal pDevModeInput作为IntPtr,ByVal fMode As Int32)作为整数

Private Sub ButtonSelectedPrinterProperties_Click(...)...

''仅在需要时更改PrinterName,而不是每次都更改用户

按下

''按钮,设置一个printername重置一些设置

If(ComboBoxPrinterNames.SelectedIndex<> - 1)然后

If(Me.PrintDocument.PrinterSettings.PrinterName<>

ComboBoxPrinterNames.Text)然后

Me.PrintDocument.PrinterSettings .PrinterName =

ComboBoxPrinterNames.Text

结束如果

如果Me.PrintDocument.PrinterSettings.IsValid那么

我.OpenPrinterPropertiesDialog(PrintDocument.Print erSettings)

Else

MsgBox(Invalid printersettings",MsgBoxStyle.Information)

结束如果

否则

MsgBox(选择打印机,MsgBoxStyle.Information)

结束如果

End Sub


Sub OpenPrinterPropertiesDialog(ByVal设置为PrinterSettings)

''PrinterSettings + PageSettings - > hDEVMODE

Dim hDevMode As IntPtr = _

Settings.GetHdevmode(Settings.DefaultPageSettings)


''Show Dialog([In ,out] pDEVMODE)

Dim pDevMode As IntPtr = GlobalLock(hDevMode)

DocumentProperties(Me.Handle,IntPtr.Zero,_

设置.PrinterName,pDevMode,pDevMode,14)

GlobalUnlock(hDevMode)


''hDEVMODE - > PrinterSettings + PageSettings

Settings.SetHdevmode(hDevMode)

Settings.DefaultPageSettings.SetHdevmode(hDevMode)


GlobalFree(hDevMode)

结束次级


结束班级


HTH,

问候



Without much guarantee though it should be possible with a few native
functions:

Public Class YourPrinterSettingsDialog
'' native functions
Private Declare Auto Function GlobalLock Lib "kernel32.dll" _
(ByVal handle As IntPtr) As IntPtr
Private Declare Auto Function GlobalUnlock Lib "kernel32.dll" _
(ByVal handle As IntPtr) As Integer
Private Declare Auto Function GlobalFree Lib "kernel32.dll" _
(ByVal handle As IntPtr) As IntPtr
Private Declare Auto Function DocumentProperties Lib "winspool.drv" _
(ByVal hWnd As IntPtr, ByVal hPrinter As IntPtr, _
ByVal pDeviceName As String, ByVal pDevModeOutput As IntPtr, _
ByVal pDevModeInput As IntPtr, ByVal fMode As Int32) As Integer
Private Sub ButtonSelectedPrinterProperties_Click( ... )...
'' only change PrinterName when it is required, NOT each time the user
presses
'' the button, setting a printername resets some of the settings
If (ComboBoxPrinterNames.SelectedIndex <> -1) Then
If (Me.PrintDocument.PrinterSettings.PrinterName <>
ComboBoxPrinterNames.Text) Then
Me.PrintDocument.PrinterSettings.PrinterName =
ComboBoxPrinterNames.Text
End If
If Me.PrintDocument.PrinterSettings.IsValid Then
Me.OpenPrinterPropertiesDialog(PrintDocument.Print erSettings)
Else
MsgBox("Invalid printersettings", MsgBoxStyle.Information)
End If
Else
MsgBox("Choose a printer", MsgBoxStyle.Information)
End If
End Sub

Sub OpenPrinterPropertiesDialog(ByVal Settings As PrinterSettings)
'' PrinterSettings+PageSettings -> hDEVMODE
Dim hDevMode As IntPtr = _
Settings.GetHdevmode(Settings.DefaultPageSettings)

'' Show Dialog ( [In,Out] pDEVMODE )
Dim pDevMode As IntPtr = GlobalLock(hDevMode)
DocumentProperties(Me.Handle, IntPtr.Zero, _
Settings.PrinterName, pDevMode, pDevMode, 14)
GlobalUnlock(hDevMode)

'' hDEVMODE -> PrinterSettings+PageSettings
Settings.SetHdevmode(hDevMode)
Settings.DefaultPageSettings.SetHdevmode(hDevMode)

'' cleanup
GlobalFree(hDevMode)
End Sub

End Class

HTH,
Greetings


亲爱的巴特,


真的非常感谢你!为您的贡献。


您还提供了一些额外的建议。让我学习并尝试实现它。


这个对我的工作非常重要。事实上PrintDialog提供的

与.NET太原始了

在实际程序中很有用,一旦重写一个就无法逃脱

任务手动调用打印机设置。


我将继续处理它,稍后可能会提出一些问题,在

的情况下我遇到问题。


我非常感激,


-Pamela

Dear Bart,

Really THANK YOU VERY MUCH !!! for your contribution.

You also provide some additional advice. Let me study and try to
implement it.

This one is very important for my work. Infact the PrintDialog provided
with .NET is too primitive
to be useful in real programs, and once one rewrite one cannot escape
the task to manually call the printer setup.

I will work on it and will probably poput later with some question, in
case I have problems.

I am very grateful,

-Pamela


亲爱的伯特,


我试过你的代码(在XP上)。实际上它已经相当完整了。你完全可以完成所有工作。
几乎已经完成了b $ b。我也很感激您对打印机名称设置

的更正。

你真的是天使!


我还没有尝试过打印,因为现在它在这里的夜晚,我不是在我的办公室


但打印机属性对话框弹出正常。如果出现问题

我会告诉你。


如果可以,我需要一些进一步的信息进行一些改进。

我在组合中加载打印机名称(或者我将使用

树视图):

类似于:


-------------------------------------

Private Sub YourPrinterSettingsDialog_Load (ByVal发送者...)句柄

MyBase.Load


Dim PrinterNames作为新的ArrayList

每个PrinterName作为String In

PrinterSettings.InstalledPrinters

试试

PrinterNames.Add(PrinterName)

Catch

结束尝试

下一个PrinterName

Me.ComboBoxPrinterNames.Items.AddRange(PrinterName s.ToArray)


End Sub

------------------------------------


我需要认识到:1。默认打印机,2。网络打印机,

改变外观

他们的图标。所以,我猜,我需要2个布尔函数:


函数IsDefaulPrinter(PrinterName as string)as boolean

函数IsNetworkPrinter(PrinterName as string)boolean

(其他人认为是本地的,我猜)


你知道怎么做这些功能吗?

任何建议都是非常受欢迎的。谢谢,


-Pamela

Dear Burt,

I have tried your code (on XP). Actually it is quite complete. You
have practically
done the all job. I also appreciated your correction about setting
the printer name.
You are really an angel!

I have not tried yet to print because now its night here and I am
not at my office,
but the printer properties dialog pops up fine. In case of problems
I will tell you.

If I may, I would need some further info for some refinements.
I am loading the printer names in a combo (or perhaps I will use a
treeview):
with something like:

-------------------------------------
Private Sub YourPrinterSettingsDialog_Load(ByVal sender...) Handles
MyBase.Load

Dim PrinterNames As New ArrayList
For Each PrinterName As String In
PrinterSettings.InstalledPrinters
Try
PrinterNames.Add(PrinterName)
Catch
End Try
Next PrinterName
Me.ComboBoxPrinterNames.Items.AddRange(PrinterName s.ToArray)

End Sub
------------------------------------

I need to recognize: 1. the Default Printer, 2. Network printers, to
change the appearance
of their icons. So, I guess, I need 2 boolean functions:

function IsDefaulPrinter(PrinterName as string) as boolean
function IsNetworkPrinter(PrinterName as string) as boolean
(others assumed local, I guess)

Do you know how to make these functions?
Any suggestion is very welcome. Thanks,

-Pamela


这篇关于如何打开原生PRINTER DIALOG - 请帮助!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆