473,657 Members | 2,453 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding a Click event to a Web Browser control

Can anyone point me to a good guide for how to do this or give me some
pointers? What I'm basically trying to do is use the Web Browser as a
picture box that has a web source for the image, but it doesn't have a click
event for the control (so I can pop up a new window with an enlarged image).
I can put a panel above it (on a user control) with a click event or even a
picture box, but Transparent background apparently isn't actually
transparent so I'm staring at a gray square until I click on it then it pops
up the enlarged image perfectly. If anyone knows a better way to do this
I'm game for that also.

TIA,
Jayyde
Oct 27 '06 #1
7 19836
Anyone?

Pretty please?

"Jayyde" <an**@hotmail.c omwrote in message
news:%2******** **********@TK2M SFTNGP02.phx.gb l...
Can anyone point me to a good guide for how to do this or give me some
pointers? What I'm basically trying to do is use the Web Browser as a
picture box that has a web source for the image, but it doesn't have a
click event for the control (so I can pop up a new window with an enlarged
image). I can put a panel above it (on a user control) with a click event
or even a picture box, but Transparent background apparently isn't
actually transparent so I'm staring at a gray square until I click on it
then it pops up the enlarged image perfectly. If anyone knows a better
way to do this I'm game for that also.

TIA,
Jayyde

Oct 30 '06 #2
Well, you could perhaps set the .ObjectForScrip ting to a C# object with a
method, and make the browser load some simple HTML (which you would write)
which places an IMG with an "onclick" that invokes a method on the scripting
object via javascript; something like below (all notepad jobs; not tested).

Marc
*** class def
[ComVisible(true )]
public class ScriptingObject {
internal event EventHandler Clicked;
public void SomeMethod() {
EventHandler handler = Clicked;
if(handler!=nul l) handler(this,Ev entArgs.Empty);
}
}
*** HTML extract
<IMG SRC="..." ONCLICK="window .external.SomeM ethod()"/>
*** UI code
ScriptingObject () obj = new ScriptingObject ();
obj.Clicked += // TODO: handle
myBrowser.Objec tForScripting = obj;
Oct 30 '06 #3
In fact, for a very similar example:

http://msdn2.microsoft.com/en-US/lib...scripting.aspx

Note also my "internal" was just me being lazy; the event should probably
just be [ComVisible(fals e)]. I would also recommend (unlike the MSDN
example) keeping a *very* tightly scoped object for this purpose to minimise
attack surfaces. Not that this is an issue for a simple job like this one.

Marc
Oct 30 '06 #4
Thanks for all the help Marc :). I just have 1 more question (one little
thing that's not cooperating). This thing is basically pulling image file
names from a db and creating individual thumbnails for them then needs to
update a selected image web browser (bigger) when they're clicked. It's
working perfectly for products that only have 1 image, but for those that
have more than 1 thumbnail it fires off the first click and resets the
document text for the selected image fine, but when the second one is
clicked it goes through the motions but never actually updates the document
text. I've tried it with and without a following .Refresh on the web
browser and with and without a .DocumentText = String.Empty before it tries
to update it. Is there something else that I need to do to make the
document text update?

TIA,
Jayyde

"Marc Gravell" <ma**********@g mail.comwrote in message
news:eh******** ******@TK2MSFTN GP02.phx.gbl...
In fact, for a very similar example:

http://msdn2.microsoft.com/en-US/lib...scripting.aspx

Note also my "internal" was just me being lazy; the event should probably
just be [ComVisible(fals e)]. I would also recommend (unlike the MSDN
example) keeping a *very* tightly scoped object for this purpose to
minimise attack surfaces. Not that this is an issue for a simple job like
this one.

Marc

Oct 31 '06 #5
Sorry, no idea from that description...

Marc
Oct 31 '06 #6
Maybe this will help and maybe it won't then lol. Basic form set up is a
panel of small thumbnails of products (100x100) with a slightly larger
thumbnail (180x180) spot over to the side that displays that slightly larger
image for whatever smaller thumbnail the user selects. The user can then
click to zoom the selected which just opens a new form where they can make
it as big as they want and save the picture locally if they want. (Note:
the context menus are turned on just so I can get to the view source to try
to figure out what the heck's going on--they won't be on release).

************** CODE *************** *************** **

private void LoadProductImag es(DataSet dsImages)
{
WebBrowser wb;
int i = 0;
int x = 0;

foreach (DataRow dr in dsImages.Tables[0].Rows)
{
i++;

wb = new WebBrowser();
pnlImages.Contr ols.Add(wb);

wb.Name = "webThumb" + i.ToString();
wb.AllowWebBrow serDrop = false;
wb.AllowNavigat ion = false;
wb.ScrollBarsEn abled = false;
wb.IsWebBrowser ContextMenuEnab led = true;
wb.WebBrowserSh ortcutsEnabled = false;
wb.ObjectForScr ipting = this;
wb.ScriptErrors Suppressed = true;
wb.DocumentText =
"<html><head><s tyle>" +
"body,table,tr, td,img{margin:0 px; padding:0px; display:inline;
vertical-align: bottom; }" +
"</style></head><body><cen ter>" +
"<img src=\"" + cIMAGE_HOST +
dr[ProductImageDCS chema.FileName].ToString() + "\" " +
"height=\"1 00\" " +
"onclick=\"wind ow.external.Thu mbnail_Click('" +
dr[ProductImageDCS chema.FileName].ToString() + "')\">" +
"</center></body></html>";
wb.Size = new Size(100, 100);
wb.Location = new Point((x + 3), 3);
wb.Refresh();

x += 103;
}
}

public void Thumbnail_Click (string ImageFileName)
{
webSelectedImag e.DocumentText = String.Empty;
mstrSelectedIma geFileName = ImageFileName;
** webSelectedImag e.DocumentText =
"<html><head><s tyle>" +
"body,table,tr, td,img{margin:0 px; padding:0px; display:inline;
vertical-align: bottom; }" +
"</style></head><body><cen ter>" +
"<img src=\"" + cIMAGE_HOST + ImageFileName + "\" " +
"height=\"1 80\" " +
"onclick=\"wind ow.external.Sel ectedImage_Clic k('" + ImageFileName +
"')\">" +
"</center></body></html>";
webSelectedImag e.Refresh();
}

public void SelectedImage_C lick(string ImageFileName)
{
if (webSelectedIma ge.DocumentText != String.Empty)
EnlargeImage();
else
MessageBox.Show ("Please select an image to enlarge.");
}

*************** *************** *************** *******

It's on that **ed line where it gets messed up for some reason. The first
thumbnail that gets clicked sets it fine. When another one gets clicked it
sends ImageFileName ok, but the DocumentText doesn't actually save to the
new one. When I break point it and hover over it it's almost like it hasn't
refreshed. Freakishly, however, when I view source on the selected image
web browser all it has as its DocumentText is "<HTML></HTML".

I have no idea if any of that explains the situation better, but for my sake
I hope it does ;).

"Marc Gravell" <ma**********@g mail.comwrote in message
news:eU******** ******@TK2MSFTN GP03.phx.gbl...
Sorry, no idea from that description...

Marc

Oct 31 '06 #7
Eesh that's a lot of WebBrowsers... any reason you couldn't just lay out all
the thumbnails in one browser within a single HTML block? Or better, any
reason you can't do the bulk of this (presumably excluding EnlargeImage)
with a single DHTML page? Still, C# is a viable solution...

A quick (!) test shows that this concept generally works OK (i.e. with
multiple WebBrowsers all updating the DocumentText of another one).

My first suspicion would be that you html is malformed. Hard to tell without
looking at the final string; as a debugging aid, write the HTML to a
variable first, and either view it (break point) in a the HTML viewer, else
save it to the file system (e.g. File.WriteAllTe xt() to a temp file), and
then inspect this file carefully. Or try loading it into a browser. See what
happens.

Personally, I don't really like inline HTML etc; you simply can't debug it
properly in this way. I tend to keep the HTML template in either a simple
text file (with token replacement), or build it via xslt (which makes it
easier to avoid "escaping" bugs). That said, it would be even less postable
if you had done it in a tidy way, so that isn't a dig! For all I know your
"real" code has the HTML off to one side...

Marc
Oct 31 '06 #8

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

Similar topics

8
2018
by: George Hester | last post by:
In a page I have when the user left-clicks the page a Input box for a form gets the focus. But if the user right-clicks the page the Input box is not getting the focus. I'd like the Input box to get the focus no matter where on the page the user clicks be it right-click or left-click. Right now there is no context menu when the user right-clicks. Do you think that's the problem? Any ideas how to get this right-click left-click Input box...
4
4780
by: yfng | last post by:
In a web form, I want the user clicks on one button and this button will trigger another button/link which will open a new browser window? How to do that? Is there any method like Button.performclick? Thanks
15
12362
by: crjunk | last post by:
I have 4 TextBoxes on my form that I'm trying to add together to get a grand total. Here is the code I'm using: <SCRIPT LANGUAGE="JavaScript"> <!-- Beginning of JavaScript - function calcTotalPub() { var tempFed = +document.Form1.value; var tempState = +document.Form1.value;
2
18564
by: RobG | last post by:
I am trying to dynamically add an onclick to an element, however I just can't get the syntax right. consider the following function: function doClick (evt,x) { // do things with evt and x } Which is called statically by: <button onclick="doClick(event,this);">Click me</button>
3
4871
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
3
2339
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
5
8504
by: Mark Rae | last post by:
Hi, Is it possible to add events, specifically a Click event, to a dynamically created TableCell? I have an <asp:Table...> control to which I'm dynamically adding TableRow controls made up of TableCell controls - before you ask, the underlying data is really not suitable for a DataGrid or Repeater... Now, the client is asking for each dynamically added TableCell control to
2
15065
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
1
3681
by: Rotsey | last post by:
Hi, I have a form with a webbrowser control set to fill the form. I want to capture when the form is clicked. As the browser control is filling the form the user would click on the browser conttrol, but it does not have a click event. How can I trap the click event for a form like this????
0
8420
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8324
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8842
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8516
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8617
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7353
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6176
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.