Jump to content
Software FX Community

Chart doesn't print inside picture box


User (Legacy)

Recommended Posts

Posted

Hi,

I can really use some help here. There are a number of places that explain

how to print the contents

of a visual basic picturebox. I used some of the sample code provided and

makes sense. But to

my discovery I found that ChartFx control doesn't print.

The ChartFX control is placed inside the picture box along with some label

control arrays to tabulate

the data in the chart. The chart control and label controls are in the same

picturebox. The following code is used to print the content picture box.

Everything prints except the ChartFX control.

The following code copies the contents by painting the image from Picture3

picturebox control to a dummy picturebox control, Picture4.

Public Const WM_PAINT = &HF

Public Const WM_PRINT = &H317

Public Const PRF_CLIENT = &H4&

Public Const PRF_CHILDREN = &H10&

Public Const PRF_OWNED = &H20&

Public Declare Function SendMessage Lib "user32" Alias _

"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _

ByVal wParam As Long, ByVal lParam As Long) As Long

Public Declare Function GetDeviceCaps Lib "gdi32" _

(ByVal hdc As Long, ByVal nindex As Long) As Long

Private Sub Form_load()

Picture3.BorderStyle = NONE

Picture3.AutoRedraw = True

Picture4.AutoRedraw = True

Picture4.BorderStyle = NONE

Picture4.Visible = False

End Sub

Private Sub printBtn_Click()

Dim retval As Long, xmargin As Single, ymargin As Single

Dim x As Single, y As Single

Dim xsize As Single, ysize As Single

x = 1: y = 1

xsize = 6: ysize = 4.5

With Printer

.ScaleMode = vbInches

xmargin = GetDeviceCaps(.hdc, 112) 'PHYSICALOFFSETX

' Convert margin given in pixels to inches

xmargin = (xmargin * .TwipsPerPixelX) / 1440

' ymargin = GetDeviceCaps(.hdc, 113) 'PHYSICALOFFSETY

' Convert margin given in pixels to inches

ymargin = (ymargin * .TwipsPerPixelY) / 1440

Picture4.width = Picture3.width

Picture4.Height = Picture3.Height

DoEvents

Picture3.SetFocus

retval = SendMessage(Picture3.hwnd, WM_PAINT, Picture4.hdc, 0)

retval = SendMessage(Picture3.hwnd, WM_PRINT, Picture4.hdc,

PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)

Picture4.Picture = Picture4.Image

Printer.Print ""

.PaintPicture Picture4.Picture, x - xmargin, y - ymargin, xsize,

ysize

.EndDoc

End With

End Sub

Why isn't ChartFX control part of Picture3?

Please HELP!

Mike

Posted

This approach will not work with an ActiveX control, it only works with

simple controls (built-in controls).

We provide a method called Paint that allows you to draw the chart into a

Device Context, you must use this method instead of sending a WM_PAINT

message to the chart control.

--

FP

Software FX, Inc.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...