Bug in Metafile Export?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
CK
Newbie
Newbie
Posts: 2
Joined: Wed Mar 31, 2004 5:00 am
Location: Sydney

Bug in Metafile Export?

Post by CK » Thu Apr 01, 2004 2:52 am

I am trying to copy a chart to a metafile so I can paste it into a word document. It doesn't work whether I use the export gui available at design time or try to export it programatically via TChart1.Export.Image.Metafile.CopyToClipboard()
This is the same whether I specify a windows metafile or an enhanced metafile.
I am running with the latest version of the teechart.net pro, with visual studio.net 2003 on win2k.

If I try to export it to a file, sure enough the file appears but it is empty (size=0kb).

All of the other formats work (bmp,tiff etc) but these don't print out very well (they look pixelated) - so a metafile is what it is required.

Any help gratefully received...

Pep
Site Admin
Site Admin
Posts: 3273
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Thu Apr 01, 2004 9:27 am

Hi,

to export the Chart as metafile to ClipBoard you must use the following code :

Code: Select all

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;
     }
    
}

}

CK
Newbie
Newbie
Posts: 2
Joined: Wed Mar 31, 2004 5:00 am
Location: Sydney

Post by CK » Thu Apr 01, 2004 12:17 pm

Thanks for that -
It see,s that either
1) you need to update your documentation to say that the method CopyToClipboard of Export.MetafileFormat actually does nothing
or
2) You need to put the code you recommended in your response in the method CopyToClipboard which doesn't do anything at the moment.

or am i missing something here?

Pep
Site Admin
Site Admin
Posts: 3273
Joined: Fri Nov 14, 2003 5:00 am
Contact:

Post by Pep » Fri Apr 02, 2004 11:36 am

Hi,

>1) you need to update your documentation to say that the method >CopyToClipboard of Export.MetafileFormat actually does nothing
Yes, you're correct, we'll include more info about this in the help files.

2) You need to put the code you recommended in your response in the method CopyToClipboard which doesn't do anything at the moment.
We'll, we'll try to make it work for the next maintenance releases.

Post Reply