Print Page | Close Window

Copying Chart to Clipboard

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=19447
Printed Date: 16 June 2025 at 5:29pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Copying Chart to Clipboard
Posted By: ChristineK
Subject: Copying Chart to Clipboard
Date Posted: 30 January 2012 at 12:18pm
I am using ChartPro version 15.2.1
I need to be able to copy the chart that is drawn in my application to the clipboard for users to paste as a picture into something like Word or PowerPoint. Is there an easy way to do this?



Replies:
Posted By: ABuenger
Date Posted: 30 January 2012 at 2:19pm
Hello,

please open a ticket and I'll provide the necessary code.

Andre



-------------
Codejock support


Posted By: ChristineK
Date Posted: 01 February 2012 at 10:07am
I'm sorry...I am new to ChartPro and this message board. How do I open a ticket?


Posted By: evoX
Date Posted: 22 February 2012 at 9:19am
Why don't you post here the code? because I also need this.

-------------
Product: Xtreme ToolkitPro 19.30
Platform: Windows 10 64bit
Language: Visual C++ (VS 2019)


Posted By: Arnoutdv
Date Posted: 22 February 2012 at 9:38am
I accomplished this by using an invisible picture control on the form.

The Visible property is set to False
The AutoRedraw property is set to True

Private Sub ChartToClipBoard()
  picChartClipBoard.Width = theChart.Width
  picChartClipBoard.Height = theChart.Height
  theChart.PrintToDC picChartClipBoard.hdc, -1, -1, theChart.Width / Screen.TwipsPerPixelX, theChart.Height / Screen.TwipsPerPixelY
  Clipboard.Clear
  Clipboard.SetData picChartClipBoard.Image, vbCFBitmap
End Sub


-------------
VB6 SP6, SuitePro 16.3.0 / 18.2.0, Win10/64


Posted By: ChristineK
Date Posted: 22 February 2012 at 9:45am
I figured out how to do this on my own. Here's the function I wrote:
 

void MyClass::OnCopyToClipboardChart()

{

                // Get the size of the chart rectangle

                CRect rect;

                m_chartControl1.GetClientRect(rect);

                rect.NormalizeRect();   

                if(rect.IsRectEmpty() || rect.IsRectNull())

                                return; 

 

                // get the chart's device context

                CDC *pDc = m_chartControl1.GetWindowDC();

                CDC memDc;

                if(!memDc.CreateCompatibleDC(pDc))

                                return;

 

                // create a bitmap of the chart's current state

                CBitmap bitmap;

                if( !bitmap.CreateCompatibleBitmap(pDc,rect.Width(), rect.Height()))

                                return;

                CBitmap* pOldBitmap = memDc.SelectObject(&bitmap);

                memDc.BitBlt(0,0,rect.Width(),rect.Height(),pDc,rect.left ,  rect.top ,SRCCOPY );                              

                if(OpenClipboard())

                {

                                // empty clipboard data

                                EmptyClipboard();

                                // put the chart bitmap on the clipboard

                                SetClipboardData(CF_BITMAP,bitmap.GetSafeHandle());

                                CloseClipboard();

                }

                memDc.SelectObject(pOldBitmap);

}



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