在vb.net中打印之前如何调整图表大小 [英] How to resize a chart before printing in vb.net
问题描述
我想在vb.net应用程序中打印图表,但是当我打印它时,它很小,我找不到如何调整其大小的方法.
目前,我正在使用以下代码:(位于此处:
----------------------------------------编辑-------------------------------------
当我向您解释答案的注释时,我现在可以更改图表的位置和大小,但是会出现空白方块,我不知道为什么!
好吧,我终于在这里找到了对我有用的东西,并根据情况进行了调整:
我添加了一个对话框来选择打印机,并修改一些原始代码,如您在此处看到的:
Private Sub BT_Print_Click(作为对象发送,作为EventArgs发送)处理BT_Print.Click打印预览()结束子公共子Print_Preview()昏暗的Print_Doc作为PrintDocumentPrint_Doc = Chart_Requis.Printing.PrintDocumentAddHandler Print_Doc.PrintPage,新建PrintPageEventHandler(AddressOf Print_Page)表格参数Print_Doc.DefaultPageSettings.Landscape = TruePrint_Doc.DefaultPageSettings.Margins =新的Printing.Margins(0,1,1,1)Print_Doc.DefaultPageSettings.Color = True'选择打印机和其他参数昏暗的Print_dlg作为新的PrintDialogPrint_dlg.Document = Print_Doc昏暗的结果为DialogResult = Print_dlg.ShowDialog()'如果对话框正确,则继续,否则否如果(结果= DialogResult.OK)然后'将标记放到正确的尺寸对于i = 0到Chart_Requis.Series.Count-1Chart_Requis.Series(i).MarkerSize = 1下一个'打印前检查Chart_Requis.Printing.PrintPreview()万一结束子私有子Print_Page(ByVal发送者为对象,ByVal ev为PrintPageEventArgs)'DEFINI LA POSITION ET LA TAILLE DU GRAPHIQUE昏暗的图表位置为新矩形(-70,-50,2500,2300)Chart_Requis.Printing.PrintPaint(ev.Graphics,chartPosition)结束子
希望它可以帮助今天遇到同样麻烦的人...
I would like to print a chart in my vb.net application but when I print it, it's very small and I can't find how to resize it.
For now, I'm using this code: (Found here : Some msdn printing subject)
Private Sub BT_Print_Click(sender As Object, e As EventArgs) Handles BT_Print.Click
Dim pdS As New PrintDocument()
AddHandler pdS.PrintPage, AddressOf pds_PrintPage
pdS.DefaultPageSettings.Landscape = True
Dim PrintDialog1 As New PrintPreviewDialog
PrintDialog1.Document = pdS
If (PrintDialog1.ShowDialog = DialogResult.OK) Then
Chart_Requis.Printing.PrintDocument.DefaultPageSettings.Landscape = True
pdS.Print()
End If
End Sub
Private Sub pds_PrintPage(sender As Object, ev As PrintPageEventArgs)
Dim chartPosition As New Rectangle(1, 1, ev.MarginBounds.Width, ev.MarginBounds.Height)
Chart_Requis.Printing.PrintPaint(ev.Graphics, chartPosition)
End Sub
After all my attempt I just reached to move margins... which is good but I still cannot read my chart correctly...
Do someone had the same issue and found a solution ?
----------------------------------------EDIT-------------------------------------
As I explain it the comment of your answer, I now can change chart's position and size but blank squares appears and I don't know why !
Ok, I finally found something which worked for me here and I adapt it to my case : Another Stackoverflow subject
I let you see the final chart here :
I add a dialogbox to choose the printer and adapt a bit the original code as you can see here :
Private Sub BT_Print_Click(sender As Object, e As EventArgs) Handles BT_Print.Click
Print_Preview()
End Sub
Public Sub Print_Preview()
Dim Print_Doc As PrintDocument
Print_Doc = Chart_Requis.Printing.PrintDocument
AddHandler Print_Doc.PrintPage, New PrintPageEventHandler(AddressOf Print_Page)
'SHEET PARAMETERS
Print_Doc.DefaultPageSettings.Landscape = True
Print_Doc.DefaultPageSettings.Margins = New Printing.Margins(0, 1, 1, 1)
Print_Doc.DefaultPageSettings.Color = True
'CHOOSING PRINTER AND OTHER PARAMETERS
Dim Print_dlg As New PrintDialog
Print_dlg.Document = Print_Doc
Dim result As DialogResult = Print_dlg.ShowDialog()
'IF DIALOGBOX OK THEN CONTINUE OTHERWISE NO
If (result = DialogResult.OK) Then
'PUT MARKERS TO THE RIGHT SIZE
For i = 0 To Chart_Requis.Series.Count - 1
Chart_Requis.Series(i).MarkerSize = 1
Next
'CHECKING BEFORE PRINTING
Chart_Requis.Printing.PrintPreview()
End If
End Sub
Private Sub Print_Page(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
'DEFINI LA POSITION ET LA TAILLE DU GRAPHIQUE
Dim chartPosition As New Rectangle(-70, -50, 2500, 2300)
Chart_Requis.Printing.PrintPaint(ev.Graphics, chartPosition)
End Sub
Hope it will help someone in the same trouble than me today...
这篇关于在vb.net中打印之前如何调整图表大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!