School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!
Welcome to Dream.In.Code
Become an Expert!

Join 340,156 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 3,990 people online right now. Registration is fast and FREE... Join Now!



Multiple Defenitions with single signiture in webbrowser

Page 1 of 1

Multiple Defenitions with single signiture in webbrowser ~~~PROJECT FOR FRIDAY URGENT HELP PLS~~~ Rate Topic: -----

#1 Jack Eagles1  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 366
  • Joined: 10-December 08


Dream Kudos: 50

Posted 10 June 2009 - 02:45 AM

Hi, I have this code for some custom events in a webbrowser I'm making. The events are meant to be for when the user carries out certain actions, here are the actions:


Mouse Enters a link (HTMLElement)
Mouse Exits a link (HTMLElement)
Mouse Clicks a link (HTMLElement)

Mouse Enters an image (HTMLElement)
Mouse Exits an image (HTMLElement)



Here is the code:
  Private Sub nav() Handles Me.DocumentCompleted
	  Dim link As HtmlElement
		Dim links As HtmlElementCollection = Me.document.Links
		For Each link In links
			link.AttachEventHandler("onclick", AddressOf LinkClicked)
			link.AttachEventHandler("onmouseover", AddressOf onmouseenter)
			link.AttachEventHandler("onmouseleave", AddressOf onmouseleave)
		Next
		Dim picture As HtmlElement
		Dim pictures As HtmlElementCollection = Me.document.Images
		For Each picture In pictures
			picture.AttachEventHandler("mouseon", AddressOf onmouseenter)
			picture.AttachEventHandler("mouseon", AddressOf onmouseleave)
		Next
end sub




Here is the code to handle the link events:


  Private Sub onmouseenter(ByVal sender As Object, ByVal e As EventArgs)
		CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ContextMenuStrip = Form1.LinkContextMenu
	End Sub
	Private Sub onmouseleave(ByVal sender As Object, ByVal e As EventArgs)
		CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).IsWebBrowserContextMenuEnabled = False
		CType(Form1.TabControl1.SelectedTab.Controls.Item(0), WebBrowser).ContextMenuStrip = Form1.MyContextMenu
	End Sub
	 Private Sub LinkClicked(ByVal sender As Object, ByVal e As EventArgs)
'complicated stuff which is irrelevant
   end sub




Here is the code to handle the Image events:


   Private Sub onmouseenter(ByVal sender As Object, ByVal e As EventArgs)
	   'Set a different context menu
	End Sub
   Private Sub onmouseleave(ByVal sender As Object, ByVal e As EventArgs)
	'Set a different context menu
	End Sub




Here is my problem: I have the event handler with the same name for both my Picture event and my Link events. How can I change my code so that the same function is carried out as I want, but the names for each of the events are different?


Here is the error which I am yielding:

Error	3	'Private Sub onmouseenter(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.	C:\Users\Josh The Great\Documents\Visual Studio 2008\Projects\Net Browser\Net Browser\Forms\Form1.vb	2164	17	Net Browser


This post has been edited by Jack Eagles1: 10 June 2009 - 09:11 AM

Was This Post Helpful? 0
  • +
  • -


#2 Jack Eagles1  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 366
  • Joined: 10-December 08


Dream Kudos: 50

Posted 10 June 2009 - 09:10 AM

Maybe no one has replied because I did not explain very well. I want to use the AttatchEventHandler class twice in the same class, using the same 'onclick' Function, but I get an error, because I have the same onclick function twice. Can anyone help pls?
Was This Post Helpful? 0
  • +
  • -

#3 RudiVisser  Icon User is offline

  • .. does not guess solutions
  • Icon
  • Group: Members w/DIC++
  • Posts: 1,931
  • Joined: 05-June 09


Dream Kudos: 150

Expert In: PHP, MySQL, HTML, CSS, C#

Posted 10 June 2009 - 09:14 AM

I don't do VB, but your error seems fairly simple. If you're just having 2 functions, one for images and one for links, why not name them accordingly?

Asin, onmouseenter_Link/onmouseenter_Image. It doesn't matter what they're called to be assigned as an event handler.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suiter #2
  • Icon
  • View blog
  • Group: Authors
  • Posts: 2,099
  • Joined: 12-June 08


Dream Kudos: 150

Posted 10 June 2009 - 09:36 AM

I'm not sure if I fully get what your issue is, but let me take a stab.

You have an action on this html element - a mouse click. You want it to do two different things depending on what it clicks, right? One for links and one for images, right? Are these two things being loaded into the same control? If so then have one event for the mouse click and in the event determine what you clicked.

Quote

object click event

if i clicked on a link then
do this
else if I clicked on an image then
do that
end if

Was This Post Helpful? 0
  • +
  • -

#5 Jack Eagles1  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 366
  • Joined: 10-December 08


Dream Kudos: 50

Posted 10 June 2009 - 10:00 AM

Yeah, the problem is I cannot rename the functions, I have, but I'm not sure if it is impossible. If someone puts this code into vb.net, you will see what i mean. Thanks for any help in advance.
Was This Post Helpful? 0
  • +
  • -

#6 modi123_1  Icon User is offline

  • Suiter #2
  • Icon
  • View blog
  • Group: Authors
  • Posts: 2,099
  • Joined: 12-June 08


Dream Kudos: 150

Posted 10 June 2009 - 10:23 AM

Okay. I think I have it now.

Simply make your two events (with different names) and inside both have them call one specific method.
Was This Post Helpful? 0
  • +
  • -

#7 Jack Eagles1  Icon User is offline

  • D.I.C Regular
  • Icon
  • Group: Authors
  • Posts: 366
  • Joined: 10-December 08


Dream Kudos: 50

Posted 10 June 2009 - 10:45 AM

The point is I get an error every time I try to name on of the methods! If you can find me a way to name the methods, then that would be beyond great :) thanks for trying :S
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1


Fast Reply

  

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month