Using DOCMD with ActiveX drawing pane

P

Phil Hazell

Hi,

I am building a custom app using the drawing control and I have been able to
successfully call most Visio internal functions by referencing the
application object and using DOCMD, but I cannot get this to work for
PrintPreview or emailing.

The command constants I am using are:

PrintPreview: DoCmd(visCmdPrintPreview)
Email: DoCmd(visCmdSendAsMail)

In both cases I get "Requested Operation Is Presently Disabled"

Any suggestions?
 
M

Mai-lan [MS]

Hi, Phil: You can't get to PrintPreview through the control. Here's a
workaround:
Visio's Print methods target the current printer; use
Application.ActivePrinter to tell you what printer is current. The Visio
object model does not include a PrintPreview method. Here's one approach:
private void menuFilePrintPreview_Click(object sender,
System.EventArgs e)

{

try

{



PrintDocument pd = new PrintDocument(); //Assumes the
default printer



PrintPreviewDialog dlg = new PrintPreviewDialog();

pd.PrintController = new PreviewPrintController();





pd.PrintPage += new
PrintPageEventHandler(this.pd_PrintPage);



dlg.Document = pd;



dlg.ShowDialog();



//pd.Print();



}

catch (Exception exp)

{

Debug.WriteLine( exp.Message );

throw exp;

}

}





private void pd_PrintPage(object sender, PrintPageEventArgs ev)

{



Metafile mf = new Metafile( (IntPtr) visioPage.Picture.Handle,
false );



ev.Graphics.DrawImage( mf, 0, 0 );

}



To simulate Print Preview, you could use an Image control and make some sort
of Draw or Render call using the preview context and pass it a bitmap or
metafile presentation of the control. You can also Page.Picture to get an
enhanced metafile to render as an IPictureDisp.

Thanks,

Mai-lan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top