TeePreviewPanel Printing

TeeChart for ActiveX, COM and ASP
Post Reply
MNE
Newbie
Newbie
Posts: 5
Joined: Tue Jul 06, 2004 4:00 am
Location: New York, U.S.A
Contact:

TeePreviewPanel Printing

Post by MNE » Tue Dec 06, 2005 7:53 pm

I am Using VB6 + TeeChart AX 6.0

I have combined 8 charts into one TeePreviewPanel and am having the following problems:

1. I need to print a Title for every page I print - which consists of many charts. I cannot print the Text that I am writing to the canvas. The example you have is for adding text to a tchart. I need to do it for a teePreviewPanel. I wrote the text in the following way:


Private Sub tpp1_OnAfterDraw()
Dim PrintText as String
PrintText = “Hydraulic Pressure in PSI”
With tpp1.Canvas
.Font.Color = vbBlue
.Font.Size = 10
.TextOut PrintX, 100, PrintText
End With
End Sub

This shows on the screen but does not print. I have seen one example you have http://www.teechart.net/support/viewtop ... t=printing but that is for the Chart Canvas and not the TeePreviewPanel. Please provide complete working code if possible.

2. How do I Center the text Horizontally? The Printer.TextWidth and TeePreviewPanel.Canvas.Left and TeePreviewPanel.Canvas.Width are different units. So I cannot center the text.

3. How can I get a Printer Dialog Box if I want to print a TeePreviewPanel? We need to re-direct the print to a black and white or color printer – so we need to see that dialog. TeePreviewPanel.PrintPage sends the output directly to the printer.

Thanks.

Narcís
Site Admin
Site Admin
Posts: 14730
Joined: Mon Jun 09, 2003 4:00 am
Location: Banyoles, Catalonia
Contact:

Post by Narcís » Wed Dec 07, 2005 10:04 am

Hi MNE,

Please find below the answers to your questions:
1. I need to print a Title for every page I print - which consists of many charts. I cannot print the Text that I am writing to the canvas. The example you have is for adding text to a tchart. I need to do it for a teePreviewPanel. I wrote the text in the following way:


Private Sub tpp1_OnAfterDraw()
Dim PrintText as String
PrintText = “Hydraulic Pressure in PSI”
With tpp1.Canvas
.Font.Color = vbBlue
.Font.Size = 10
.TextOut PrintX, 100, PrintText
End With
End Sub

You should do it manually adding each chart and the title at the print doc. Below there's an example where 4 charts are displayed in the preview panel and how you should add the title and the charts to the document for printing them.

Code: Select all

Dim PrintText As String
Private Sub Command1_Click()
Dim HWidth, HHeight, ChartLeft, ChartTop, ChartRight, ChartBottom ' Declare variables.
  
    On Error GoTo ErrorHandler  ' Set up error handler.
    Printer.Orientation = vbPRORPortrait
    'Scale & position text.
    HWidth = Printer.TextWidth(Text1.Text) / 2 ' Get half width.
    HHeight = Printer.TextHeight(Text1.Text) / 2   ' Get half height.
    Printer.CurrentX = Printer.ScaleWidth / 3 - HWidth
    Printer.CurrentY = Printer.ScaleHeight / 3 - HHeight
  
    Printer.Print PrintText ' Print 1st Text box
    With TChart1.Printer
      'Chart needs to orientated separately
  
      .Orientation = poPortrait
      'Set the chart position
      ChartLeft = .PageWidth / 3
      ChartTop = (.PageHeight / 3) + 30
      ChartRight = (.PageWidth / 3) * 2
      ChartBottom = (2 * (.PageHeight / 3)) - HHeight - 10
      'Attach the Chart output to the open print job
      .PrintPartialHandle Printer.hDC, ChartLeft, _
           ChartTop, ChartRight, ChartBottom
  
    End With
    Printer.CurrentY = 2 * Printer.ScaleHeight / 3 - HHeight
    Printer.CurrentX = Printer.ScaleWidth / 3 - HWidth
  
  
    With TChart2.Printer
      'Chart needs to orientated separately
  
      .Orientation = poPortrait
      'Set the chart position
      ChartLeft = .PageWidth / 3
      ChartTop = (.PageHeight / 3) + 30
      ChartRight = (.PageWidth / 3) * 2
      ChartBottom = (2 * (.PageHeight / 3)) - HHeight - 10
      'Attach the Chart output to the open print job
      .PrintPartialHandle Printer.hDC, ChartLeft, _
           ChartTop, ChartRight, ChartBottom
  
    End With
  
  
  
    Printer.Print Text2.Text ' Print 2nd Text box
    Printer.EndDoc  ' Printing is finished.
    Exit Sub
    
ErrorHandler:
    MsgBox "There was a problem printing to your printer."
    Exit Sub
End Sub
  


Private Sub Form_Load()
Text1.Text = "This first text box should be placed on top of the TeeChart Object."
With TChart1
    .Series(0).FillSampleValues 100
End With
With TChart2
    .Series(0).FillSampleValues 100
End With
With TChart3
    .Series(0).FillSampleValues 100
End With
With TChart4
    .Series(0).FillSampleValues 100
End With
Text2.Text = "This second text box should be placed below the TeeChart Object."
 TeePreviewPanel1.Chart = TChart1
 TeePreviewPanel1.AddChart TChart2
 TeePreviewPanel1.AddChart TChart3
 TeePreviewPanel1.AddChart TChart4
 
 
   With TChart1.Printer
    .PrintProportional = False
    .MarginLeft = 2
    .MarginTop = 2
    .MarginRight = 50
    .MarginBottom = 50
  End With
  With TChart2.Printer
    .PrintProportional = False
    .MarginLeft = 50
    .MarginTop = 50
    .MarginRight = 2
    .MarginBottom = 2
  End With
  With TChart3.Printer
    .PrintProportional = False
    .MarginLeft = 50
    .MarginTop = 0
    .MarginRight = 0
    .MarginBottom = 50
  End With
  With TChart4.Printer
    .PrintProportional = False
    .MarginLeft = 0
    .MarginTop = 50
    .MarginRight = 50
    .MarginBottom = 0
  End With
End Sub

Private Sub TeePreviewPanel1_OnAfterDraw()
    
    PrintText = "Hydraulic Pressure in PSI"
 
    With TeePreviewPanel1.Canvas
        .Font.Color = vbBlue
        .Font.Size = 10
        .TextOut 10, 10, PrintText
    End With
End Sub
2. How do I Center the text Horizontally? The Printer.TextWidth and TeePreviewPanel.Canvas.Left and TeePreviewPanel.Canvas.Width are different units. So I cannot center the text.

You can get the center using page.width.
3. How can I get a Printer Dialog Box if I want to print a TeePreviewPanel? We need to re-direct the print to a black and white or color printer – so we need to see that dialog. TeePreviewPanel.PrintPage sends the output directly to the printer.
It should work using a CommonDialog component and using the code below to select the printer:

Code: Select all

    CommonDialog1.ShowPrinter
Best Regards,
Narcís Calvet / Development & Support
Steema Software
Avinguda Montilivi 33, 17003 Girona, Catalonia
Tel: 34 972 218 797
http://www.steema.com
Image Image Image Image Image Image
Instructions - How to post in this forum

Post Reply