[紧急求助]mapx 如何打印任何尺寸纸张?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[紧急求助]mapx 如何打印任何尺寸纸张?相关的知识,希望对你有一定的参考价值。

mapx 如何打印任何尺寸纸张?比如打印超大的图片,3M*3M的,如何写代码?

就是地图显示完整时,按照自己设定的纸张尺寸输出。目前可以设置,但输出的图比A2小的多,反而缩的更小了。
我们需要的是VB的,谢谢!以下都没有正确的。---10月12日下午2点更新

提供以下代码作参考:
Imports AxMDrawProLib
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Printing
'Imports PictureCtrl.PublicLayer

Public Class CMetaDrawPrinter

#Region "类说明及修改日志"
' 修改人:
' 修改内容:

#End Region

'声明事件
Private WithEvents PrnDocMetaDraw As PrintDocument
'传递控件的临时变量
Private _MetaDrawCtrl As AxMDrawPro
'传递剪裁、输出区域的信息
Private _PicType As MDrawProLib.C_PictureType
Private _sClipLeft, _sClipTop, _sClipWidth, _sClipHeight, _sExportLeft, _sExportTop, _sExportWidth, _sExportHeight, _sBlankLength, _sFullHeight, _sFullWidth As Single
Private _iPageNum, _iPrintPageNum As Integer
'纸型高、宽
Private _iPaperHeight, _iPaperWidth As Integer
'纸型:A4/A3
Private _iPaperKind As System.Drawing.Printing.PaperKind
'横纵打印
Private _bPaperLandscape As Boolean

'输出属性
Private _ExportOptions As MDrawProLib.C_ExportOptions

'打印机和显示器的DPI,暂时不加入此类中,由外部控制
'Private _iPrinterDPI, _iMonitorDPI As Integer

#Region "属性"
'获取当前使用的PrintDocument类
Public ReadOnly Property GetPrnDoc()
Get
Return PrnDocMetaDraw
End Get
End Property
'全图(大图)高度
Public Property FullHeight() As Single
Get
Return _sFullHeight
End Get
Set(ByVal Value As Single)
_sFullHeight = Value
End Set
End Property

'全图(大图)宽度
Public Property FullWidth() As Single
Get
Return _sFullWidth
End Get
Set(ByVal Value As Single)
_sFullWidth = Value
End Set
End Property

'2页之间的空白区域长度
Public Property BlankLength() As Single
Get
Return _sBlankLength
End Get
Set(ByVal Value As Single)
_sBlankLength = Value
End Set
End Property

'输出的页数
Public Property PageNum() As Integer
Get
Return _iPageNum
End Get
Set(ByVal Value As Integer)
_iPageNum = Value
End Set
End Property

' 获取输出图片格式
Private ReadOnly Property PicType() As MDrawProLib.C_PictureType
Get
Return _PicType
End Get
'Set(ByVal Value As MDrawProLib.C_PictureType)
' _PicType = Value
'End Set
End Property

'得到当前使用的MetaDraw控件
Private WriteOnly Property GetMetaDrawCtrl() As AxMDrawPro
Set(ByVal Value As AxMDrawPro)
_MetaDrawCtrl = Value
End Set
End Property

'得到当前使用的MetaDraw控件
Public WriteOnly Property SetExportOptions() As MDrawProLib.C_ExportOptions
Set(ByVal Value As MDrawProLib.C_ExportOptions)
_ExportOptions = Value
End Set
End Property

#Region "纸张"

'纸张:高
Public Property PaperKind() As PaperKind
Get
Return _iPaperKind
End Get
Set(ByVal Value As PaperKind)
_iPaperKind = Value
End Set
End Property

'纸张:高
Public Property PaperHeight() As Integer
Get
Return _iPaperHeight
End Get
Set(ByVal Value As Integer)
_iPaperHeight = Value
End Set
End Property
'纸张:宽
Public Property PaperWidth() As Integer
Get
Return _iPaperWidth
End Get
Set(ByVal Value As Integer)
_iPaperWidth = Value
End Set
End Property

'纸张:横纵
Public Property PaperLandscape() As Boolean
Get
Return _bPaperLandscape
End Get
Set(ByVal Value As Boolean)
_bPaperLandscape = Value
End Set
End Property
#End Region

#Region "剪裁区域信息"

Public Property ClipLeft() As Single
Get
Return _sClipLeft
End Get
Set(ByVal Value As Single)
_sClipLeft = Value
End Set
End Property
'剪裁上边距
Public Property ClipTop() As Single
Get
Return _sClipTop
End Get
Set(ByVal Value As Single)
_sClipTop = Value
End Set
End Property
'剪裁宽度
Public Property ClipWidth() As Single
Get
Return _sClipWidth
End Get
Set(ByVal Value As Single)
_sClipWidth = Value
End Set
End Property
'剪裁高度
Public Property ClipHeight() As Single
Get
Return _sClipHeight
End Get
Set(ByVal Value As Single)
_sClipHeight = Value
End Set
End Property
#End Region

#Region "输出区域信息"
'输出左边距
Public Property ExportLeft() As Single
Get
Return _sExportLeft
End Get
Set(ByVal Value As Single)
_sExportLeft = Value
End Set
End Property
'输出上边距
Public Property ExportTop() As Single
Get
Return _sExportTop
End Get
Set(ByVal Value As Single)
_sExportTop = Value
End Set
End Property
'输出宽度
Public Property ExportWidth() As Single
Get
Return _sExportWidth
End Get
Set(ByVal Value As Single)
_sExportWidth = Value
End Set
End Property
'输出高度
Public Property ExportHeight() As Single
Get
Return _sExportHeight
End Get
Set(ByVal Value As Single)
_sExportHeight = Value
End Set
End Property
#End Region

#End Region

#Region "SUB方法"

Public Sub New(ByVal _MetaDrawCtrlTemp As AxMDrawPro)
PrnDocMetaDraw = New PrintDocument
'PrnDocMetaDraw.PrinterSettings.DefaultPageSettings.Landscape = True
'PrnDocMetaDraw.PrinterSettings.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize("Custom", 1169, 827)

_MetaDrawCtrl = _MetaDrawCtrlTemp

'默认的纸型设置
_iPaperKind = PaperKind.A4
_bPaperLandscape = True

'默认值
'图象格式
_PicType = MDrawProLib.C_PictureType.PICTYPE_ENHMETAFILE
'_PicType = MDrawProLib.C_PictureType.PICTYPE_METAFILE
'四周空白区域(边距),_BlankHeight * 2 = 2个小图的间距
_sBlankLength = 0

'默认剪裁区域信息
_sClipLeft = _sBlankLength
_sClipTop = _sBlankLength
_sClipWidth = 100
_sClipHeight = 100

'默认输出区域信息
_sExportLeft = 0
_sExportTop = 0
_sExportWidth = 0
_sExportHeight = 0

'全图(大图)高度
_sFullHeight = _MetaDrawCtrl.PicYSize

'分成小图的页数
_iPageNum = 1

'页码清0
_iPrintPageNum = 0

End Sub

'计算分页打印的页数
Private Sub CountPageNum()
Dim iPageX As Integer
Dim iPageY As Integer

If (_sFullWidth / _sClipWidth) > Int(_sFullWidth / _sClipWidth) Then
iPageX = Int(_sFullWidth / _sClipWidth + 1)
Else
iPageX = Int(_sFullWidth / _sClipWidth)
End If

If (_sFullHeight / _sClipHeight) > Int(_sFullHeight / _sClipHeight) Then
iPageY = Int(_sFullHeight / _sClipHeight + 1)
Else
iPageY = Int(_sFullHeight / _sClipHeight)
End If

_iPageNum = iPageX * iPageY

If _iPageNum < 1 Then
_iPageNum = 1
End If
End Sub

'Public Function GetClipImage() As Image

' _MetaDrawCtrl.PictureType = _PicType
' '_MetaDrawCtrl.Current = MDrawProLib.C_ResHandle.OBJ_CONT_MAIN
' '输出区域
' _MetaDrawCtrl.ExportOptions = MDrawProLib.C_ExportOptions.EXOPT_CLIPPING Or MDrawProLib.C_ExportOptions.EXOPT_USEZOOM

' '剪切区域信息
' _MetaDrawCtrl.ClipLeft = _ClipLeft
' _MetaDrawCtrl.ClipTop = _ClipTop
' _MetaDrawCtrl.ClipWidth = _ClipWidth
' _MetaDrawCtrl.ClipHeight = _ClipHeight

' '输出区域信息
' _MetaDrawCtrl.ExportLeft = _ExportLeft
' _MetaDrawCtrl.ExportTop = _ExportTop
' _MetaDrawCtrl.ExportWidth = _ExportWidth
' _MetaDrawCtrl.ExportHeight = _ExportHeight

' Return _MetaDrawCtrl.PictureClip
'End Function

''计算小图页数
'Private Sub CountPageNum()
' '_iPageNum = Int((_sFullHeight / (_sClipHeight + _sBlankLength * 2)) * (_sFullWidth / (_sClipWidth + _sBlankLength * 2)))
' _iPageNum = Int((_sFullHeight * _sFullWidth) / ((_sClipHeight + _sBlankLength * 2) * (_sClipWidth + _sBlankLength * 2)))

' 'If _iPageNum < (_sFullHeight / (_sClipHeight + _sBlankLength * 2)) * (_sFullWidth / (_sClipWidth + _sBlankLength * 2)) Then
' If _iPageNum < (_sFullHeight * _sFullWidth) / ((_sClipHeight + _sBlankLength * 2) * (_sClipWidth + _sBlankLength * 2)) Then

' _iPageNum = _iPageNum + 1
' End If

' If _iPageNum < 1 Then
' _iPageNum = 1
' End If

'End Sub

Private Sub PrnDocMetaDraw_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrnDocMetaDraw.PrintPage
'此处使用PICTYPE_BITMAP,没有PICTYPE_METAFILE清晰。
'但是使用PICTYPE_METAFILE后, 某些元素角度会改变。

_MetaDrawCtrl.PictureType = _PicType
'_MetaDrawCtrl.Current = MDrawProLib.C_ResHandle.OBJ_CONT_MAIN
'输出区域
'加入EXOPT_USEZOOM是为了保持尺寸
_MetaDrawCtrl.ExportOptions = _ExportOptions
'_MetaDrawCtrl.ExportOptions = MDrawProLib.C_ExportOptions.EXOPT_CLIPPING

'剪切区域信息
_MetaDrawCtrl.ClipLeft = _sClipLeft
_MetaDrawCtrl.ClipTop = _sClipTop

'_MetaDrawCtrl.ClipWidth = 400
'_MetaDrawCtrl.ClipHeight = 400

_MetaDrawCtrl.ClipWidth = _sClipWidth
_MetaDrawCtrl.ClipHeight = _sClipHeight

'输出区域信息
_MetaDrawCtrl.ExportLeft = _sExportLeft
_MetaDrawCtrl.ExportTop = _sExportTop
_MetaDrawCtrl.ExportWidth = _sExportWidth
_MetaDrawCtrl.ExportHeight = _sExportHeight

'_MetaDrawCtrl.ExportWidth = 400
'_MetaDrawCtrl.ExportHeight = 400

'设置打印区域尺寸
'Dim RgleF As New RectangleF
'Dim SizF As New SizeF
'SizF.Height = iPrintHeight
'SizF.Width = iPrintWidth

'SizF.Height = _MetaDrawCtrl.PicYSize
'SizF.Width = _MetaDrawCtrl.PicXSize
'SizF.Height = 602
'SizF.Width = 931
'SizF.Height = mdpUser.PicYSize
'SizF.Width = mdpUser.PicXSize

'RgleF.Size = SizF
'RgleF.X = _sExportLeft
'RgleF.Y = _sExportTop

'打印图象
Dim _g As Graphics
_g = e.Graphics
_g.DrawImage(_MetaDrawCtrl.PictureClip, _sExportLeft, _sExportTop)

'_g.DrawImage(_MetaDrawCtrl.PictureClip, RgleF)

''打印页码

'_iPrintPageNum = 1 + _iPrintPageNum
'Dim _Bursh As New SolidBrush(Color.Black)
'Dim _Font As New System.Drawing.Font("宋体, 9pt", 9, FontStyle.Bold)
'_g.DrawString("页码:" & _iPrintPageNum, _Font, _Bursh, 10, 10)

'是否打印多页
If _iPageNum >= 2 Then
e.HasMorePages = True
_iPageNum = _iPageNum - 1
'_BlankHeight为空白区域高度
'横向平移打印
_sClipLeft = _sClipLeft + _sClipWidth + _sBlankLength * 2
'当横向结束后,向下纵向平移,重新开始纵向打印
If _sClipLeft > _sFullWidth Then
_sClipLeft = 0
_sClipTop = _sClipTop + _sClipHeight
End If
Else
e.HasMorePages = False
CountPageNum()
_sClipLeft = 0
_sClipTop = 0
End If

''是否打印多页
'If _iPageNum >= 2 Then
' e.HasMorePages = True
' _iPageNum = _iPageNum - 1
' '_BlankHeight为空白区域高度
' '纵向打印
' _sClipTop = _sClipTop + _sClipHeight + _sBlankLength * 2
' '当纵向结束后,向右横向平移,重新开始纵向打印
' If _sClipTop > _sFullHeight Then
' _sClipTop = 0
' _sClipLeft = _sClipLeft + _sClipWidth
' End If
'Else
' e.HasMorePages = False
'End If

End Sub

#Region "注释掉部分-打印页码"
''打印函数子的函数,打印页码
'Private Sub PrintPageNum()

' Dim _g As Graphics

' Dim _Bursh As New SolidBrush(Color.Black)

' Dim _Font As New System.Drawing.Font("宋体, 9pt", 9, FontStyle.Bold)
' _g.DrawString("1", _Font, _Bursh, 1, 1)

'End Sub
#End Region

'打印
Public Sub Print()
'设置纸型
SetupPaper()

'得到页数
CountPageNum()

PrnDocMetaDraw.Print()
End Sub
'预览
Public Sub Preview()
Try
'设置纸型
SetupPaper()

'得到页数
CountPageNum()

Dim _PreviewDialog As New PrintPreviewDialog
'MsgBox(PrnDocMetaDraw.DefaultPageSettings.PaperSize.Kind)
_PreviewDialog.Document = PrnDocMetaDraw
_PreviewDialog.ShowDialog()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
Public Sub PrinterSetup()
Dim _PrintDialog As New PrintDialog
_PrintDialog.Document = PrnDocMetaDraw
_PrintDialog.ShowDialog()
End Sub
Public Sub PageSetup()
Dim _PageSetupDialog As New PageSetupDialog
_PageSetupDialog.Document = PrnDocMetaDraw
_PageSetupDialog.ShowDialog()
End Sub
'局部调用,设置纸型:横纵向、高、宽。
Private Sub SetupPaper()
Try
'PrnDocMetaDraw.DefaultPageSettings.PaperSize = New System.Drawing.Printing.PaperSize("Custom", _iPaperWidth, _iPaperHeight)
PrnDocMetaDraw.DefaultPageSettings.Landscape = _bPaperLandscape

Dim tPaperSize As PaperSize
Dim i As Integer
For i = 0 To PrnDocMetaDraw.PrinterSettings.PaperSizes.Count - 1
If PrnDocMetaDraw.PrinterSettings.PaperSizes(i).Kind = _iPaperKind Then
tPaperSize = PrnDocMetaDraw.PrinterSettings.PaperSizes(i)
Exit For
End If
Next

PrnDocMetaDraw.DefaultPageSettings.PaperSize = tPaperSize

'PrnDocMetaDraw.DefaultPageSettings.PaperSize = System.Drawing.Printing.PaperKind.A4
Catch ex As Exception
MsgBox(ex.ToString)
End Try

End Sub
#End Region
End Class
参考技术A mapx 打印地图时的参数如何设置
在mapx 的 printmap方法:PrintMap (hDC x, y, w, h)之中,w,h,x,y的单位为himetric,1 himetric=0.01毫米。所以,打印地图时需要将w,h 乘100换算为毫米。

在vb 中例子:

Private Sub Command4_Click()

On Error GoTo ErrorHandler ` Set up error handler.

' coords must be in himetric

' print same size as on screen, in upper left of page

ScaleMode = 6 `set mode to mm

' there is no Printer.StartDoc method, it seems it is done

' implicitly when you use one of the printer.print methods

' so we need to print something before we print our map

' to start the page

Printer.CurrentX = 0

Printer.CurrentY = 0

Printer.Print " "

Map1.PrintMap Printer.hDC, 0, 0, Map1.Width * 100, _

Map1.Height * 100

Printer.NewPage ` Send new page.

Printer.EndDoc ` Printing is finished.

Exit Sub

在vc中例子

// Map.PaperUnit Property

// Map.PrintMap Method

void CSampleProjectView::OnPrintMap(CDC* pDC,CPrintInfo* pInfo)

try

// get paper width in mm and convert to HIMETRIC (100th of a mm)

m_Map.SetPaperUnit(miUnitMillimeter);

double pw = m_Map.GetMapPaperWidth() * 100;

double ph = m_Map.GetMapPaperHeight()* 100;

m_Map.PrintMap((long)pDC->m_hDC,

pInfo->m_rectDraw.left,pInfo->m_rectDraw.

top,(long)pw,(long)ph);

catch (COleDispatchException *e)

e->ReportError();

e->Delete();

catch (COleException *e)

e->ReportError();

e->Delete();




看下是不是单位有问题本回答被提问者采纳
参考技术B 在mapx 的 printmap方法:PrintMap (hDC x, y, w, h)之中,w,h,x,y的单位为himetric,1 himetric=0.01毫米。所以,打印地图时需要将w,h 乘100换算为毫米。 参考技术C 祝你好运

(紧急求助)请问PB中如何实现单据的审核,单据的状态有未审核以及审核两种状态,谢谢

参考技术A 加一个标志字段 比如zt 如果审核过就将Zt置成1,未审核置成0;同时一上来打开单据时候判断这个值 如果是1 就将数据窗口的readonly属性置成true 就不允许他改了 只允许看!
dw_1.Object.datawindow.Readonly = True
参考技术B 加一个字段呗
如果审核了就用sql语句直接update 成1
弃审了就用sql语句直接update 成0
参考技术C 在数据窗口中加个字段status,未审核为0,已审核为1,审核完成后更新就行了

以上是关于[紧急求助]mapx 如何打印任何尺寸纸张?的主要内容,如果未能解决你的问题,请参考以下文章

(紧急求助)请问PB中如何实现单据的审核,单据的状态有未审核以及审核两种状态,谢谢

紧急求助!!width:100%出现一个水平滚动条怎么办

在BIOS中如何设置出串行总线控制器???紧急求助!!!!!!!!!!

latex紧急求助,如何将目录的颜色变为黑色

紧急求助 如何将在Latex中实现某段文章高亮

[求助]FastReport显示数据问题!