VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,338 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,688 people online right now. Registration is fast and FREE... Join Now!




Multiple Defenitions with single signiture in webbrowser

 

Multiple Defenitions with single signiture in webbrowser, ~~~PROJECT FOR FRIDAY URGENT HELP PLS~~~

Jack Eagles1

10 Jun, 2009 - 02:45 AM
Post #1

D.I.C Head
**

Joined: 10 Dec, 2008
Posts: 249



Thanked: 5 times
My Contributions
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:
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:


CODE

  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:


CODE

   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:

CODE

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 Jun, 2009 - 09:11 AM

User is offlineProfile CardPM
+Quote Post


Jack Eagles1

RE: Multiple Defenitions With Single Signiture In Webbrowser

10 Jun, 2009 - 09:10 AM
Post #2

D.I.C Head
**

Joined: 10 Dec, 2008
Posts: 249



Thanked: 5 times
My Contributions
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?
User is offlineProfile CardPM
+Quote Post

RudiVisser

RE: Multiple Defenitions With Single Signiture In Webbrowser

10 Jun, 2009 - 09:14 AM
Post #3

.. does not guess solutions
Group Icon

Joined: 5 Jun, 2009
Posts: 1,872



Thanked: 137 times
Dream Kudos: 125
Expert In: PHP, MySQL, HTML, CSS, C#

My Contributions
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.
User is offlineProfile CardPM
+Quote Post

modi123_1

RE: Multiple Defenitions With Single Signiture In Webbrowser

10 Jun, 2009 - 09:36 AM
Post #4

Suiter #2
Group Icon

Joined: 12 Jun, 2008
Posts: 1,758



Thanked: 72 times
Dream Kudos: 150
My Contributions
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

User is offlineProfile CardPM
+Quote Post

Jack Eagles1

RE: Multiple Defenitions With Single Signiture In Webbrowser

10 Jun, 2009 - 10:00 AM
Post #5

D.I.C Head
**

Joined: 10 Dec, 2008
Posts: 249



Thanked: 5 times
My Contributions
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.
User is offlineProfile CardPM
+Quote Post

modi123_1

RE: Multiple Defenitions With Single Signiture In Webbrowser

10 Jun, 2009 - 10:23 AM
Post #6

Suiter #2
Group Icon

Joined: 12 Jun, 2008
Posts: 1,758



Thanked: 72 times
Dream Kudos: 150
My Contributions
Okay. I think I have it now.

Simply make your two events (with different names) and inside both have them call one specific method.


User is offlineProfile CardPM
+Quote Post

Jack Eagles1

RE: Multiple Defenitions With Single Signiture In Webbrowser

10 Jun, 2009 - 10:45 AM
Post #7

D.I.C Head
**

Joined: 10 Dec, 2008
Posts: 249



Thanked: 5 times
My Contributions
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 smile.gif thanks for trying :S
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/7/09 05:18PM

Live VB.NET Help!

Be Social

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

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month