乐筑天下

搜索
欢迎各位开发者和用户入驻本平台 尊重版权,从我做起,拒绝盗版,拒绝倒卖 签到、发布资源、邀请好友注册,可以获得银币 请注意保管好自己的密码,避免账户资金被盗
查看: 24|回复: 1

ShowModalDialog窗体在打印预览时出现的问题

[复制链接]

9

主题

29

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2011-3-24 17:02:00 | 显示全部楼层 |阅读模式
'环境:VS2008+CAD2010
  1. ‘启动打印窗体
  2. Public Shared Sub ShowPrint()
  3.         Dim frm As New FrmPrint
  4.        Application.ShowModalDialog(frm)
  5.     End Sub
用命令行方式(窗体没有运行时)调用过程一切正常
  1. '测试函数
  2.      Public Shared Sub CS()
  3.         MultiSheetPreview()'过程代码见二楼、三楼
  4.     End Sub
但在窗体里用按钮调用的时候会出预览界面鼠标点击无反应的情况,好像无法获得焦点
  1. '预览按钮代码
  2.     Private Sub BtnYuLan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnYuLan.Click
  3.         Me.Visible = False
  4.         MultiSheetPreview()'过程代码见二楼、三楼
  5.         Me.Visible = True
  6.     End Sub
求助如何解决?
回复

使用道具 举报

9

主题

29

帖子

1

银币

初露锋芒

Rank: 3Rank: 3Rank: 3

铜币
65
发表于 2011-3-25 07:55:00 | 显示全部楼层

附Kean代码
  1. Public Shared Sub MultiSheetPreview()
  2.         Dim doc As Document = Application.DocumentManager.MdiActiveDocument
  3.         Dim ed As Editor = doc.Editor
  4.         Dim db As Database = doc.Database
  5.         Dim layoutsToPlot As New ObjectIdCollection()
  6.         Dim tr As Transaction = db.TransactionManager.StartTransaction()
  7.         Using tr
  8.             ' First we need to collect the layouts to
  9.             ' plot/preview in tab order
  10.             Dim layoutDict As New SortedDictionary(Of Integer, ObjectId)()
  11.             Dim bt As BlockTable = DirectCast(tr.GetObject(db.BlockTableId, OpenMode.ForRead), BlockTable)
  12.             For Each btrId As ObjectId In bt
  13.                 Dim btr As BlockTableRecord = DirectCast(tr.GetObject(btrId, OpenMode.ForRead), BlockTableRecord)
  14.                 If btr.IsLayout AndAlso btr.Name.ToUpper()  BlockTableRecord.ModelSpace.ToUpper() Then
  15.                     ' The dictionary we're using will
  16.                     ' sort on the tab order of the layout
  17.                     Dim lo As Layout = DirectCast(tr.GetObject(btr.LayoutId, OpenMode.ForRead), Layout)
  18.                     layoutDict.Add(lo.TabOrder, btrId)
  19.                 End If
  20.             Next
  21.             ' Let's now get the layout IDs and add them to a
  22.             ' standard ObjectIdCollection
  23.             Dim vc As SortedDictionary(Of Integer, ObjectId).ValueCollection = layoutDict.Values
  24.             For Each id As ObjectId In vc
  25.                 layoutsToPlot.Add(id)
  26.             Next
  27.             ' Committing is cheaper than aborting
  28.             tr.Commit()
  29.         End Using
  30.         ' PlotEngines do the previewing and plotting
  31.         If PlotFactory.ProcessPlotState = Autodesk.AutoCAD.PlottingServices.ProcessPlotState.NotPlotting Then
  32.             Dim layoutNum As Integer = 0
  33.             Dim isFinished As Boolean = False
  34.             Dim isReadyForPlot As Boolean = False
  35.             While Not isFinished
  36.                 ' Create the preview engine with the appropriate
  37.                 ' buttons enabled - this depends on which
  38.                 ' layout in the list is being previewed
  39.                 Dim flags As PreviewEngineFlags = PreviewEngineFlags.Plot
  40.                 If layoutNum > 0 Then
  41.                     flags = flags Or PreviewEngineFlags.PreviousSheet
  42.                 End If
  43.                 If layoutNum = 0 Then
  44.             ' Preview is really pre-sheet, so we reduce the
  45.             ' sheet collection to contain the one we want
  46.             layoutsToPlot = New ObjectIdCollection()
  47.             layoutsToPlot.Add(layoutSet(layoutNumIfPreview))
  48.         Else
  49.             ' If we're plotting we need all the sheets,
  50.             ' so copy the ObjectIds across
  51.             Dim ids As ObjectId() = New ObjectId(layoutSet.Count - 1) {}
  52.             layoutSet.CopyTo(ids, 0)
  53.             layoutsToPlot = New ObjectIdCollection(ids)
  54.         End If
  55.         Dim tr As Transaction = db.TransactionManager.StartTransaction()
  56.         Using tr
  57.             ' Create a Progress Dialog to provide info
  58.             ' and allow thej user to cancel
  59.             Dim ppd As New PlotProgressDialog(isPreview, layoutsToPlot.Count, True)
  60.             Using ppd
  61.                 Dim numSheet As Integer = 1
  62.                 For Each btrId As ObjectId In layoutsToPlot
  63.                     Dim btr As BlockTableRecord = DirectCast(tr.GetObject(btrId, OpenMode.ForRead), BlockTableRecord)
  64.                     Dim lo As Layout = DirectCast(tr.GetObject(btr.LayoutId, OpenMode.ForRead), Layout)
  65.                     ' We need a PlotSettings object
  66.                     ' based on the layout settings
  67.                     ' which we then customize
  68.                     Dim ps As New PlotSettings(lo.ModelType)
  69.                     ps.CopyFrom(lo)
  70.                     ' The PlotSettingsValidator helps
  71.                     ' create a valid PlotSettings object
  72.                     Dim psv As PlotSettingsValidator = PlotSettingsValidator.Current
  73.                     ' We'll plot the extents, centered and
  74.                     ' scaled to fit
  75.                     psv.SetPlotType(ps, Autodesk.AutoCAD.DatabaseServices.PlotType.Extents)
  76.                     psv.SetUseStandardScale(ps, True)
  77.                     psv.SetStdScaleType(ps, StdScaleType.ScaleToFit)
  78.                     psv.SetPlotCentered(ps, True)
  79.                     ' We'll use the standard DWFx PC3, as
  80.                     ' this supports multiple sheets
  81.                     psv.SetPlotConfigurationName(ps, "DWFx ePlot (XPS Compatible).pc3", "ANSI_A_(8.50_x_11.00_Inches)")
  82.                     ' We need a PlotInfo object
  83.                     ' linked to the layout
  84.                     Dim pi As New PlotInfo()
  85.                     pi.Layout = btr.LayoutId
  86.                     ' Make the layout we're plotting current
  87.                     LayoutManager.Current.CurrentLayout = lo.LayoutName
  88.                     ' We need to link the PlotInfo to the
  89.                     ' PlotSettings and then validate it
  90.                     pi.OverrideSettings = ps
  91.                     Dim piv As New PlotInfoValidator()
  92.                     piv.MediaMatchingPolicy = MatchingPolicy.MatchEnabled
  93.                     piv.Validate(pi)
  94.                     ' We set the sheet name per sheet
  95.                     ppd.PlotMsgString(PlotMessageIndex.SheetName) = (doc.Name.Substring(doc.Name.LastIndexOf("") + 1) & " - ") + lo.LayoutName
  96.                     If numSheet = 1 Then
  97.                         ' All other messages get set once
  98.                         ppd.PlotMsgString(PlotMessageIndex.DialogTitle) = "Custom Preview Progress"
  99.                         ppd.PlotMsgString(PlotMessageIndex.CancelJobButtonMessage) = "Cancel Job"
  100.                         ppd.PlotMsgString(PlotMessageIndex.CancelSheetButtonMessage) = "Cancel Sheet"
  101.                         ppd.PlotMsgString(PlotMessageIndex.SheetSetProgressCaption) = "Sheet Set Progress"
  102.                         ppd.PlotMsgString(PlotMessageIndex.SheetProgressCaption) = "Sheet Progress"
  103.                         ppd.LowerPlotProgressRange = 0
  104.                         ppd.UpperPlotProgressRange = 100
  105.                         ppd.PlotProgressPos = 0
  106.                         ' Let's start the plot/preview, at last
  107.                         ppd.OnBeginPlot()
  108.                         ppd.IsVisible = True
  109.                         pe.BeginPlot(ppd, Nothing)
  110.                         ' We'll be plotting a single document
  111.                         pe.BeginDocument(pi, doc.Name, Nothing, 1, Not isPreview, filename)
  112.                     End If
  113.                     ' Which may contains multiple sheets
  114.                     ppd.LowerSheetProgressRange = 0
  115.                     ppd.UpperSheetProgressRange = 100
  116.                     ppd.SheetProgressPos = 0
  117.                     Dim ppi As New PlotPageInfo()
  118.                     pe.BeginPage(ppi, pi, (numSheet = layoutsToPlot.Count), Nothing)
  119.                     ppd.OnBeginSheet()
  120.                     pe.BeginGenerateGraphics(Nothing)
  121.                     ppd.SheetProgressPos = 50
  122.                     pe.EndGenerateGraphics(Nothing)
  123.                     ' Finish the sheet
  124.                     Dim pepi As New PreviewEndPlotInfo()
  125.                     pe.EndPage(pepi)
  126.                     ret = pepi.Status
  127.                     ppd.SheetProgressPos = 100
  128.                     ppd.OnEndSheet()
  129.                     numSheet += 1
  130.                     ' Update the overall progress
  131.                     ppd.PlotProgressPos += (100 / layoutsToPlot.Count)
  132.                 Next
  133.                 ' Finish the document
  134.                 pe.EndDocument(Nothing)
  135.                 ' And finish the plot
  136.                 ppd.PlotProgressPos = 100
  137.                 ppd.OnEndPlot()
  138.                 pe.EndPlot(Nothing)
  139.             End Using
  140.         End Using
  141.         Return ret
  142.     End Function
回复

使用道具 举报

发表回复

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

  • 微信公众平台

  • 扫描访问手机版

  • 点击图片下载手机App

QQ|关于我们|小黑屋|乐筑天下 繁体中文

GMT+8, 2025-3-15 12:56 , Processed in 0.335503 second(s), 56 queries .

© 2020-2025 乐筑天下

联系客服 关注微信 帮助中心 下载APP 返回顶部 返回列表