IDataObject iData = Clipboard.GetDataObject();
string[] formats = iData.GetFormats(true);
the formats array gets two strings, "MetaFilePict"
and "EnhancedMetafile". I then execute
if (iData.GetDataPresent(DataFormats.MetafilePict)) {
object o = iData.GetData(DataFormats.MetafilePict);
}
GetDataPresent returns true, but the object returned from
GetData is always null.
I've tried using DataFormats.EnhancedMetafile, or even an
actual string returned from GetFormats, but the object is
still null.
I've used PowerPoint XP to put a metafile on the
clipboard. It posts many other formats too, but
EnhancedMetafile is still in the list. Again,
GetDataPresent reports that the format is present, but the
object returned is null.
I have experienced the same problems with metafiles. I am unable to
create a metafile programitically on the fly, without getting an exception.
You are probably getting a value of null, because the creation of the
metafile image is failing. This is what I found but I still can't find a
way around it.
It appears that GDI+ is not handling the refrenced HDC that was used to
create the metafile correctly. The problem is that the new Metafile image
instance relies on the Graphics object instance that was used to get the HDC
for the image. Once the referenced HDC is freed the Metafile object is
invalid. Maybe someone has more insight into this problem.
Here is the code I used to generate the metafile.
private Metafile FMetafileImage;
//Some method
using(Graphics LGraphics = Graphics.FromHwnd(Handle))
{
FMetafileImage = new Metafile(LGraphics.GetHdc(), new
Rectangle(0,0,10,10);
using(Graphics LImageGraphics = Graphics.FromImage(FMetafileImage))
//Draw something with the LImageGraphics...
LImageGraphics.DrawLine(...
}
John
"Dennis Austin" <denn...@pacbell.net> wrote in message
news:c41b01c119ee$acc5a770$b1e62ecf@tkmsftngxa04...
I don't think the problem you are seeing is the same one I
have, but Metafile objects do seem to be broken in
multiple ways. I was finally able to get a metafile from
the clipboard by putting the code in an unmanaged DLL
written in C and calling that from C# where I converted
the metafile handle to a Metafile object.
I have noticed another problem now in trying to copy
metafiles TO the clipboard. The method GetHenhmetafile()
is supposed to return the windows handle to the underlying
enhanced metafile, but the value it returns seems to be
wrong. Also, the very act of calling the method damages
the Metafile object so that it can't be drawn anymore.
--Dennis
>.
>