Print Page | Close Window

Very small chart using PrintToDC

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Chart Control
Forum Description: Topics Related to Codejock Chart Control
URL: http://forum.codejock.com/forum_posts.asp?TID=18461
Printed Date: 04 December 2024 at 2:24pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Very small chart using PrintToDC
Posted By: robertmdc
Subject: Very small chart using PrintToDC
Date Posted: 28 May 2011 at 5:00am
On screen, this is my chart:



To print, I use PrintToDC method (VB6):

  Printer.Print " ";
  ChartControl.PrintToDC Printer.hDC, 500, 500, 3000, 3000
  Printer.EndDoc

...on Printer



Why chart and labels are very small?
How to print chart like "wysiwhg" using PrintToDC method?








Replies:
Posted By: Oleg
Date Posted: 30 May 2011 at 1:31pm
Most easy way is to use our PrintPreview control from CommandBars.
for 15.0.3 we added new methods to show PrintPreview and send to printer.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: Fabian
Date Posted: 31 May 2011 at 9:54am
Hi Robertmdc
 
Probably the following code snippet in VB6 will help. but the result still depends on the printer resolution (BTW: I use the VSPrinter as canvas control):
 
Public Sub DrawChart(VSPrinter1 As VSPrinter, ChartControl1 As ChartControl, ByVal x1 As Long, ByVal y1 As Long, ByVal x2 As Long, ByVal y2 As Long, Optional ByVal AsBitmap_OK As Boolean = False)
  Const MM_ISOTROPIC = 7
  Const MM_ANISOTROPIC = 8
  Dim Path          As String
  Dim OldMapMode    As Long
  Dim OldVE         As POINTAPI
  Dim OldWE         As POINTAPI
  Dim OldOrg        As POINTAPI
  Dim OldSize       As POINTAPI
  Dim PW            As Long
  Dim ph            As Long
 
  If AsBitmap_OK Then
    Path = GetTempPathName() + ".BMP"
    Call ChartControl1.SaveAsImage(Path, (x2 - x1) / Screen.TwipsPerPixelX, (y2 - y1) / Screen.TwipsPerPixelY)
    Call VSPrinter1.DrawPicture(LoadPicture(Path), x1, y1, x2 - x1, y2 - y1)
    Call KillFiles(Path)
  Else
    PW = (VSPrinter1.PageWidth - 1440) / VSPrinter1.TwipsPerPixelX
    ph = (VSPrinter1.PageHeight - 1440) / VSPrinter1.TwipsPerPixelY / 3
    OldMapMode = SetMapMode(VSPrinter1.hDC, MM_ISOTROPIC)
    Call SetWindowOrgEx(VSPrinter1.hDC, 0, 0, OldOrg)
    Call SetWindowExtEx(VSPrinter1.hDC, PW, ph, OldWE)
    Call SetViewportExtEx(VSPrinter1.hDC, PW / 100, ph / 100, OldVE)
    Call ScaleViewportExtEx(VSPrinter1.hDC, 1200 / VSPrinter1.TwipsPerPixelX, 1, 1200 / VSPrinter1.TwipsPerPixelY, 1, OldSize)
    Call ChartControl1.PrintToDC(VSPrinter1.hDC, x1 / 12, y1 / 12, (x2 - x1) / 12, (y2 - y1) / 12)
   
    Call SetWindowOrgEx(VSPrinter1.hDC, OldOrg.x, OldOrg.y, OldOrg)
    Call SetViewportExtEx(VSPrinter1.hDC, OldVE.x, OldVE.y, 0)
    Call SetWindowExtEx(VSPrinter1.hDC, OldWE.x, OldWE.y, 0)
    Call SetMapMode(VSPrinter1.hDC, OldMapMode)
  End If
End Sub


-------------
Product: Xtreme SuitePro (ActiveX) version 16.2.3

Platform: Windows 7 (32bit)

Language: Visual Basic 6.0 / SP6


Posted By: robertmdc
Date Posted: 31 May 2011 at 5:10pm
Hi Fabian
Thank you! Everything works fine!



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net