浪花闪闪
路人甲
路人甲
  • 注册日期2005-10-12
  • 发帖数28
  • QQ
  • 铜币244枚
  • 威望0点
  • 贡献值0点
  • 银元0个
阅读:1628回复:2

打印的一段代码,碰到的问题!

楼主#
更多 发布于:2005-11-29 12:40
<P>下面是关于打印的一段代码,很经典的例子,VB编的,问问有人翻译成net没有,最好是.VB.net,因为VB中Printer是对象,但net不一样。</P>
<P>大侠请出手!!!</P>
<P>Private Function ConvertMapUnitsToPixels(RWUnits As Double) As Double<BR>On Error GoTo ErrorHandler<BR><BR>Dim realWorldDisplayExtent As Double<BR>Dim pixelExtent As Long<BR>Dim sizeOfOnePixel As Double<BR>Dim pDT As esriCore.IDisplayTransformation<BR>Dim deviceRECT As tagRECT<BR>Dim pEnv As esriCore.IEnvelope<BR><BR><BR>' Get the width of the display extents in Pixels<BR>' and get the extent of the displayed data<BR>' work out the size of one pixel and then return<BR>' the pixels units passed in mulitplied by that value<BR>Dim pActiveView As esriCore.IActiveView<BR>Set pActiveView = m_pHook.ActiveView<BR>Set pDT = pActiveView.ScreenDisplay.DisplayTransformation<BR>deviceRECT = pDT.DeviceFrame<BR>pixelExtent = deviceRECT.Right - deviceRECT.Left<BR>Set pEnv = pDT.FittedBounds<BR><BR>realWorldDisplayExtent = pEnv.Width<BR>sizeOfOnePixel = realWorldDisplayExtent / pixelExtent<BR>ConvertMapUnitsToPixels = RWUnits / sizeOfOnePixel<BR><BR><BR>Exit Function<BR>ErrorHandler:<BR>HandleError False, "ConvertMapUnitsToPixels " ; c_ModuleFileName ; " " ; GetErrorLineNumberString(Erl), Err.Number, Err.Source, Err.Description, 1<BR>End Function<BR><BR>Private Sub PrintToPrinter()<BR>On Error GoTo ErrorHandler<BR><BR>Dim pPrinter As esriCore.IPrinter<BR>Dim screenResolution As Long<BR>Dim userRECT As tagRECT<BR>Dim pDriverBounds As esriCore.IEnvelope<BR>Dim oPrinter As Object<BR><BR>Set oPrinter = Printer<BR><BR>If (oPrinter Is Nothing) Then<BR>Beep<BR>MsgBox "To plot the map you must have a printer installed", vbExclamation + vbOKOnly, "No Printer Installed"<BR>Exit Sub<BR>End If<BR><BR>SetupPrinter oPrinter, pPrinter<BR><BR>Dim pActiveView As esriCore.IActiveView<BR>Set pActiveView = m_pHook.ActiveView<BR>screenResolution = pActiveView.ScreenDisplay.DisplayTransformation.Resolution<BR>pPrinter.Resolution = screenResolution<BR><BR>userRECT.Top = 0<BR>userRECT.Left = 0<BR>userRECT.Right = ConvertMapUnitsToPixels(pActiveView.Extent.Width)<BR>userRECT.bottom = ConvertMapUnitsToPixels(pActiveView.Extent.Height)<BR><BR>Set pDriverBounds = New Envelope<BR>pDriverBounds.PutCoords userRECT.Left, _<BR>userRECT.bottom, _<BR>userRECT.Right, _<BR>userRECT.Top<BR>pActiveView.Output pPrinter.StartPrinting(pDriverBounds, 0), screenResolution, userRECT, pActiveView.Extent, Nothing<BR>pPrinter.FinishPrinting<BR><BR><BR>Exit Sub<BR>ErrorHandler:<BR>HandleError False, "PrintToPrinter " ; c_ModuleFileName ; " " ; GetErrorLineNumberString(Erl), Err.Number, Err.Source, Err.Description, 1<BR>End Sub<BR><BR>Private Sub SetupPrinter(oPrinter As Object, pPrinter As esriCore.IPrinter)<BR>On Error GoTo ErrorHandler<BR><BR>Dim pPsPrinter As esriCore.IPsPrinter<BR>Dim pPaper As esriCore.IPaper<BR>Dim vbPrinter As Printer<BR><BR>If (oPrinter Is Nothing) Then Exit Sub<BR>Set vbPrinter = oPrinter<BR><BR>' Build the Postscript printer object<BR>Set pPsPrinter = New PsPrinter<BR>Set pPrinter = pPsPrinter<BR>Set pPaper = New Paper<BR><BR>pPaper.PrinterName = vbPrinter.DeviceName<BR>Set pPrinter.Paper = pPaper<BR>pPaper.Orientation = vbPrinter.Orientation<BR><BR><BR>Exit Sub<BR>ErrorHandler:<BR>HandleError True, "SetupPrinter " ; c_ModuleFileName ; " " ; GetErrorLineNumberString(Erl), Err.Number, Err.Source, Err.Description, 1<BR>End Sub<BR></P><img src="images/post/smile/dvbbs/em02.gif" />
喜欢0 评分0
yansike
路人甲
路人甲
  • 注册日期2003-07-30
  • 发帖数60
  • QQ
  • 铜币279枚
  • 威望0点
  • 贡献值0点
  • 银元0个
1楼#
发布于:2006-12-27 13:12
SetupPrinter oPrinter, pPrinter是怎么写的!!
举报 回复(0) 喜欢(0)     评分
zhousky
论坛版主
论坛版主
  • 注册日期2003-08-01
  • 发帖数281
  • QQ
  • 铜币1027枚
  • 威望3点
  • 贡献值0点
  • 银元0个
2楼#
发布于:2006-12-28 15:43
需要翻译吗,呵,我们有写成现成的,QQ:171567188
不要看我噢
举报 回复(0) 喜欢(0)     评分
游客

返回顶部