Page 1 of 1

Metafile copy does not display zoom correctly

Posted: Tue May 03, 2005 6:58 am
by 8122778
Hi!

Have used the code below to copy the chart to the clipboard.

However if the chart is zoomed in the y-axis the copy comes out with huge margins above and under the chart. Since I need to paste the copy correctly into a graphics object together with other stuff i would like a way to copy only the chart without margins also when it is zoomed in. (This works fine in x-axis - the copied chart does not have margins to the left or to the right.)

How can i get rid of the margins?

Best regards Elisabeth

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;

namespace WinCsharp
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private int clickedX;
private int clickedY;
private string msgText;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private Steema.TeeChart.TChart tChart1;
private Steema.TeeChart.Styles.Line line1;

[DllImport("user32.dll")]
static extern bool OpenClipboard(IntPtr hWndNewOwner);
[DllImport("user32.dll")]
static extern bool EmptyClipboard();
[DllImport("user32.dll")]
static extern IntPtr SetClipboardData(uint uFormat, IntPtr hMem);
[DllImport("user32.dll")]
static extern bool CloseClipboard();
[DllImport("gdi32.dll")]
static extern IntPtr CopyEnhMetaFile(IntPtr hemfSrc, IntPtr hNULL);
[DllImport("gdi32.dll")]
static extern bool DeleteEnhMetaFile(IntPtr hemf);


/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent
call
//
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

[STAThread]
static void Main()
{
Application.Run(new Form1());
}


#region Windows Form Designer generated code


private void Form1_Load(object sender, System.EventArgs e) {
line1.FillSampleValues(20);

System.IO.MemoryStream stream = new System.IO.MemoryStream();

System.Drawing.Imaging.Metafile mf;
Graphics g = this.CreateGraphics();
IntPtr hdc = g.GetHdc();
mf = new System.Drawing.Imaging.Metafile(stream, hdc);
g.ReleaseHdc(hdc);
g.Dispose();
g = Graphics.FromImage(mf);
tChart1.Draw(g);
g.Dispose();

PutEnhMetafileOnClipboard(this.Handle, mf);
}

static public bool PutEnhMetafileOnClipboard( IntPtr hWnd, Metafile
mf ) {
bool bResult = false;
IntPtr hEMF, hEMF2;
hEMF = mf.GetHenhmetafile(); // invalidates mf
if( ! hEMF.Equals( new IntPtr(0) ) ) {
hEMF2 = CopyEnhMetaFile( hEMF, new IntPtr(0) );
if( ! hEMF2.Equals( new IntPtr(0) ) ) {
if( OpenClipboard( hWnd ) ) {
if( EmptyClipboard() ) {
IntPtr hRes = SetClipboardData( 14 /*CF_ENHMETAFILE*/,
hEMF2 );
bResult = hRes.Equals( hEMF2 );
CloseClipboard();
}
}
} DeleteEnhMetaFile( hEMF );
} return bResult;
}

}

}

Posted: Fri May 13, 2005 2:44 pm
by Pep
Hi Elisabeth,

I cannot reproduce the problem using the same code as you. Could you be so kind to send me an example with which I can reproduce the problem "as is" here ? You can send it directly to me at pep@steema.com

Posted: Thu Oct 11, 2007 10:33 am
by 9640192
Hi

we have the same problem with exporting zoomed chart into meta_file.

add chart to form, add point series, fill series.
then save metafile after some zoom actions.

Code: Select all

        public Form1()
        {
            InitializeComponent();
            points1.BeginUpdate();
            points1.FillSampleValues(100);
            points1.EndUpdate();
            tChart1.Click += new EventHandler(tChart1_Click);
        }

        void tChart1_Click(object sender, EventArgs e)
        {
            MouseEventArgs me = e as MouseEventArgs;
            if (me.Button == MouseButtons.Right)
            {
                tChart1.Export.Image.Metafile.Save("tmp.emf");
                //tChart1.Export.Image.JPEG.Save("tmp.jpg");
            }
        }


Posted: Thu Oct 11, 2007 10:43 am
by narcis
Hi itc,

I'm not able to reproduce the problem here using latest TeeChart for .NET v2 update build available at the client area. Which TeeChart version are you using? Could you please test if latest update build solves the problem at your end?

Thanks in a advance.