Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WebBrowser Object: change settings per instance 1

Status
Not open for further replies.

CubeE101

Programmer
Nov 19, 2002
1,492
US
Is there a way to set this setting:
set Print background colors and images
Per instance, to allow background image to print for watermark?

I would like to leave the main setting untouched, to avoid printing unwanted background images and colors...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Why not change the registry setting

HKEY_CURRENT_USER\Software\Mic­rosoft\Internet Explorer\Main\Print_Background

prior to printing, in the event WebBrowser1_PrintTemplateInstantiation

then back again in the event WebBrowser1_PrintTemplateTeardown



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I did not think of that...
So... I guess It would look something like this:
Code:
Private Const PRINTKEY = "HKCU\Software\Microsoft\Internet Explorer\Main\Print_Background"
Private OldKeyVal As String

...

Private Sub WebBrowser1_PrintTemplateInstantiation(...)
  With CreateObject("WScript.Shell")
    OldKeyVal = .RegRead(PRINTKEY)
    .RegWrite PRINTKEY, "yes"
  End With
End Sub

Private Sub WebBrowser1_PrintTemplateTeardown(...)
  If OldKeyVal <> "" Then
    CreateObject("WScript.Shell").RegWrite PRINTKEY, OldKeyVal
  End If
End Sub
Right?

I'll try it out when I get back to my PC in a little while...

Thanks!!!

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Yes, but I would also add the code

If OldKeyVal <> "" Then
CreateObject("WScript.Shell").RegWrite PRINTKEY, OldKeyVal
End If

to some error handling just incase an error occurs during printing.



Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
...Works Great!

Now, where would you put the error handling?

I wouldn't think it would be NavigateError

Are you saying to do something like this?
Code:
Private Sub WebBrowser1_PrintTemplateInstantiation(...)
  [b]On Error Goto ResetKey[/b]
  With CreateObject("WScript.Shell")
    OldKeyVal = .RegRead(PRINTKEY)
    .RegWrite PRINTKEY, "yes"
  End With
[b]ResetKey:
  If (Err <> 0) And (OldKeyVal <> "") Then
    CreateObject("WScript.Shell").RegWrite PRINTKEY, OldKeyVal
  End If
  On Error Goto 0[/b]
End Sub

Other than that, it should hit PrintTemplateTeardown so what happens in between?

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Good point, I was thinking what if the printer had no paper and timed out, was disconnected, etc. but in those cases I believe the PrintTemplateInstantiation would have not fired.


Two strings walk into a bar. The first string says to the bartender: 'Bartender, I'll have a beer. u.5n$x5t?*&4ru!2[sACC~ErJ'. The second string says: 'Pardon my friend, he isn't NULL terminated'.
 
I guess...
If nothing else...
You could read the setting at LOAD, and Reset it at UNLOAD...

But it would, effectively undo any change made to the setting while the program is running...

So I think I will leave it as is until if & when problems surface.

Thanks again for your help,
-Josh

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top