By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,980 Members | 1,302 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,980 IT Pros & Developers. It's quick & easy.

Embed in word

P: n/a
MRe
Hi,

Is there any way to write a graphical program in CSharp that could be
embedded into Word2000. I've read .NET doesn't support creation of ActiveX
controls (unless done using C++) but is there any other option, like an
existing ActiveX that can embed some CSharp program.

What I'd like to do is; whenever I'm writing an assignment for college, I
usually want to add some diagram that isn't easy to create with the tools
available to me, so I write a program to do it, take a snapshot, and put it
into the doc as a bitmap. However, when printing, the bitmap comes out
blurry, so if I could embed the program and send vector data to the printer,
that would be awesome!

Thanks for any help,
Kind regards,
Eliott
Jan 31 '07 #1
Share this Question
Share on Google+
1 Reply


P: n/a
You actually don't need to embed anything into word to accomplish the task
you have described. Just draw your graphics as vectors instead of bitmap and
no blurring will ocurr.

It's possible with GDI, but you'll need to apply a little hack:

using (Graphics g = this.CreateGraphics()) //or Graphics from your paint
event
{
IntPtr dc = g.GetHdc();

using (Metafile metafile = new Metafile("foo.wmf", dc)) //your vector image
will be stored as foo.wmf
{
using (Graphics graphics = Graphics.FromImage(metafile))
{
graphics.DrawEllipse(Pens.Red, new Rectangle(0, 0, 50, 50));
//do your drawing here

//metafile.Save("boo.wmf", ImageFormat.Wmf); //I first guessed this
should allow you to save the image but this would throw a "generic error"
from GDI, so "foo.wmf" will be the only place where the image gets saved
}
}
}

Just insert the result (foo.wmf) into word as any other image - but you can
scale this one without any blur.

This is the only way I've found that seems to work. Plain image.Save(name,
ImageFormats.Wmf) saves it as png, since there is no wmf encoder in GDI+.
This seems a little too hacky for me, but it works. If there's anyone who
knows how to save images as wmf in .NET in a "more straightforward way" I'd
be very glad to hear from him.

"MRe" <m.r.e.@.d.u.b.l.i.n...i.ewrote in message
news:ut**************@TK2MSFTNGP03.phx.gbl...
Hi,

Is there any way to write a graphical program in CSharp that could be
embedded into Word2000. I've read .NET doesn't support creation of ActiveX
controls (unless done using C++) but is there any other option, like an
existing ActiveX that can embed some CSharp program.

What I'd like to do is; whenever I'm writing an assignment for college, I
usually want to add some diagram that isn't easy to create with the tools
available to me, so I write a program to do it, take a snapshot, and put
it into the doc as a bitmap. However, when printing, the bitmap comes out
blurry, so if I could embed the program and send vector data to the
printer, that would be awesome!

Thanks for any help,
Kind regards,
Eliott

Feb 3 '07 #2

This discussion thread is closed

Replies have been disabled for this discussion.