Click to See Complete Forum and Search --> : [RESOLVED] webBrowser Class replacement


Saeed
November 11th, 2009, 11:43 PM
:eek:
WebBrowser is an Active X control that can display an HTML document within a form.

webBrowser1.Navigate(HTMLfile);

and to print it

webBrowser1.Print();

Due to various reasons ,Active X controls can not be allowed in this project and I am trying to find a replacement without losing too much quality that would get the Job done.

One way is to call Winword to load the file and print it from there but that is one messy way and involves more clicking and I am trying to avoid.

I'd appreciate any positive thoughts or ideas that you you may have .
:D
Cheers

HanneSThEGreaT
November 17th, 2009, 11:08 AM
I come in peace :) :blush:

Are you allowed to reference DLL fiiles ¿

Saeed
November 17th, 2009, 04:12 PM
I dont see any white flag waving left and right Mr M M;)
Yea ofcourse DLLs are allowed . ActiveX has been identified as unsecure.
What do you have in mind.

HanneSThEGreaT
November 18th, 2009, 12:50 AM
do
{
White_Flag(Left);
White_Flag(Right);
}while (Seeking(Peace) == "true");

OK, Saeed, I have 2 options for you :)

First option.
Add a reference to SHDocVw.dll. If you don't find it in the list, you'll have to browse for it, in the System32 folder. Then, add this :

using SHDocVw; // Internet Explorer Reference

public void OpenIE(string MyURL)
{
object NULL = null;
SHDocVw.InternetExplorer ObjIE = new
SHDocVw.InternetExplorerClass();
IWebBrowserApp Browser = (IWebBrowserApp)ObjIE;
Browser.Visible = true;
Browser.Navigate(MyURL, ref NULL, ref NULL, ref NULL, ref NULL);
}

private void Form1_Load(object sender, EventArgs e)
{

OpenIE("http://www.codeguru.com");

}

This would open Internet Explorer, navigate to codeguru, when the form is loaded.

Option 2:

Add this to the top of your class :
using System.Runtime.InteropServices;

Then, add this :
[DllImport("user32.dll")]
static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

private void button1_Click(object sender, EventArgs e)
{
Process pr = Process.Start("C:\\Program Files\\Internet Explorer\\iexplore.exe");
Thread.Sleep(500);
SetParent(pr.MainWindowHandle, panel1.Handle);
}
}

When our button is clicked, it will launch Internet Explorer, and display the Internet Explorer window inside a panel. Funky! ( At least I think so )

So, the IE window is hosted inside the panel. you have to remember though, that it will how the default home page, so perhaps if you could just temporarily set the home page to your file you want, or inform users to browse for it.

You could always, do this to show your Internet Explorer options, before launching IE :
Process.Start("rundll32.exe", "shell32.dll,Control_RunDLL inetcpl.cpl");
So, if you put that on a separate button, let users click that first, or you, and set your homepage to whatever so that when Option 2 works, you shouldn't have problems.

You could also change this registry key :
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main\Start Page

For your IE home page.

I hope my post was useful :)

Saeed
November 18th, 2009, 06:56 PM
Thanks mate I liked your peace.c code ;)
Maybe i shoudl have explained myself better.

WebBrowser control was enabling me to display an HTML file and
by another push of a button it would be printing

webBrowser1.Print();


Firing up another thread to load IE or Winword and load the file and then
User :FILE/PRINT/.... involves more human interactions (a few more clicks x 1000 a day) that I am trying to avoid.
If you still have a solution to my probelm by all means drop me a line.

Thanks for your response anyway.

Saeed

HanneSThEGreaT
November 19th, 2009, 12:34 AM
Hello again Saeed.

I see what you're saying. I think I should have included examples to my previous post.

I have used both methods in conjunction with each other.
One button displays the web browser inside the panel - you could always do this in Form Load
One button prints the document

I'm attaching a sample here, so that you can see if I understood you right - I really hope so :)

I should mention that This was real fun.

I really hope this helps.

Hannes

Saeed
November 19th, 2009, 12:51 AM
bool Seeking(peace)
{
return true;
/* comented
*/
}

Warning :1 The variable 'peace' is declared but never used

Thanks for your ZIP file. I am out of town for a few days as soon as I get back I ll give that a go. cheers mate.

HanneSThEGreaT
November 19th, 2009, 07:50 AM
Let's hope for the best. There might be little tweaking with displaying the IE window maxmised, but let us cross that bridge when we get there.

Saeed
November 25th, 2009, 09:24 PM
Good work
I just had time to have a go at your attachment and ran it.
Yea the idea is there.

Thanks a lot ;)
Saeed

HanneSThEGreaT
November 26th, 2009, 12:25 AM
That's great news, glad I could help :)

Keep up the good work! :thumb: