472,972 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,972 software developers and data experts.

IE Printing HTML file through ExecWB - print dialog comming up behindmy app - help!

I have implemented a printing scenario where an html file is
printed using the the following code:

public void PrintHtmlFile(string url)
{
RegistryKey IERegKey;
string header = null;
string footer = null;
object o = null;
InternetExplorerClass ie = null;
IWebBrowser wb = null;

// Get registry key for IE PageSetup and current values
for header and footer. If IE hasn't been
// through a print cycle, the PageSetup key will not
exist. Best thing to do is to run IE through
// at least one print job so the key will be set. With the
code below, the print will work, but the
// first printout will have headers and footers based on
default setting created on first print cycle.
// Once the registry key is in place - the following will
effectively hide the header and footer on
// printouts.
IERegKey = Registry.CurrentUser.OpenSubKey("software\
\Microsoft\\Internet Explorer\\PageSetup", true);
if (IERegKey != null)
{
footer = IERegKey.GetValue("footer", 0).ToString();
header = IERegKey.GetValue("header", 0).ToString();

// Set header and foot to blank
IERegKey.SetValue("footer", "");
IERegKey.SetValue("header", "");
}

// Create Internet Explorer instance - this (or the wb
object below) will fail if IE has not been through
// it's initial first run sequence.
ie = new InternetExplorerClass();

// Create web browser page - this (or the ie object above)
will fail if IE has not been through
// it's initial first run sequence.
wb = (IWebBrowserApp)ie;

//ie.Visible = true; // Shows the IE instance.

wb.Navigate(url, ref o, ref o, ref o, ref o);

// Wait for IE object to be ready - otherwise intermittant
errors occur when print is initiated.
while (ie.ReadyState !=
SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
{
Application.DoEvents();
}
// Print the page - prompt user
ie.ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT,
OLECMDEXECOPT.OLECMDEXECOPT_PROMPTUSER, ref o, ref o);

if (IERegKey != null)
{
// Replace IE Page settings
IERegKey.SetValue("footer", footer);
IERegKey.SetValue("header", header);
}

This works pretty well. Anyway, when the user clicks the 'Print'
button on the application form, this sub is called with the full path
to the file passed via the URL parameter. The user then has a Print
Dialog box pop up letting them select the printer to print to. All
they have to do it click ok/print and it prints out. The problem is
that the print dialog box is coming up behind the application. How can
I make the dialog box come up on top of the application?

Thanks in advance!
Jul 16 '08 #1
0 5223

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jgctr4 | last post by:
I'm trying to print an HTML file using AxWebBrowser.ExecWB but it it gives a run time error "Trying to revoke a drop target that has not been registered". Does anyone have any suggestions? ...
1
by: Hasani | last post by:
right now, for printing HTML in .net I use a AxBrowser and I do ExecWB(SHDocVw.OLECMDID.OLECMDID_PRINT, SHDocVw.OLECMDEXECOPT.OLECMDEXECOPT_DONTPROMPTUSER) I then call Application.DoEvents() in...
1
by: Curtis Justus | last post by:
Hi, My back is against the wall and I've tried to figure out something to do. Here is my scenario: I have an automated process running in a service that generates HTML files. Each resulting...
4
by: Suzanka | last post by:
Hello, I have an application written in C# on visual studio .NET. It is a web aplication. The application consists of many different forms, that users occassionaly want to print out for filing....
0
by: Curtis Justus | last post by:
Hi, I need to have the ability to take HTML files and print them out to a printer (each document may have to be sent to a different printer). This needs to be done without user interaction...
1
by: eskildb | last post by:
First, please be gently. I am fairly new to the programming world (1.5 years with some expermentation prior to). I have been working on a project that has to print HTML pages with graphics in a...
1
by: eskildb | last post by:
First, please be gently. I am fairly new to the programming world (1.5 years with some expermentation prior to). I have been working on a project that has to print HTML pages with graphics in a...
12
by: Alex Clark | last post by:
Greetings, (.NET 2.0, WinXP Pro/Server 2003, IE6 with latest service packs). I've decided to take advantage of the layout characteristics of HTML documents to simplify my printing tasks, but...
0
by: Andrew Meador | last post by:
I have implemented a printing scenario where an html file is printed using the the following code: public void PrintHtmlFile(string url) { RegistryKey IERegKey; string header = null; string...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.