5 Replies - 2060 Views - Last Post: 22 November 2010 - 04:28 PM Rate Topic: -----

#1 eddychamoun  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-November 10

How could I create declaration(event) to a variable control in VB .net

Posted 22 November 2010 - 12:40 AM

How could I create declaration(event) to a variable control in VB .net ?
i.e:
DIM newweb AS new webbrowser


(in declaration) newweb_documentcompleted
textbox1.text = newweb.document.title
end sub

please i need to know how to insert this (declaration) newweb_DocumentCompleted it's similar to WebBrowser_DocumentCompleted but it's a variable
Is This A Good Question/Topic? 0
  • +

Replies To: How could I create declaration(event) to a variable control in VB .net

#2 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: How could I create declaration(event) to a variable control in VB .net

Posted 22 November 2010 - 01:41 AM

View Posteddychamoun, on 22 November 2010 - 04:40 PM, said:

How could I create declaration(event) to a variable control in VB .net ?
i.e:
DIM newweb AS new webbrowser


(in declaration) newweb_documentcompleted
textbox1.text = newweb.document.title
end sub

please i need to know how to insert this (declaration) newweb_DocumentCompleted it's similar to WebBrowser_DocumentCompleted but it's a variable


Some time after you have created the control, add something like the following to your code:
AddHandler newweb.DocumentCompleted, AddressOf SomeSubToRunWhenDocumentCompletedIsCalled

(syntax from memory, may contain minor, easily correctable errors (like a missing () ))

Then make sure you have something like this later:

Public Sub SomeSubToRunWhenDocumentCompletedIsCalled()
...
End Sub


Hope that helped. Don't forget to rate if it did. ;)
Was This Post Helpful? 0
  • +
  • -

#3 eddychamoun  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-November 10

Re: How could I create declaration(event) to a variable control in VB .net

Posted 22 November 2010 - 03:27 AM

View Postdawmail333, on 22 November 2010 - 12:41 AM, said:

View Posteddychamoun, on 22 November 2010 - 04:40 PM, said:

How could I create declaration(event) to a variable control in VB .net ?
i.e:
DIM newweb AS new webbrowser


(in declaration) newweb_documentcompleted
textbox1.text = newweb.document.title
end sub

please i need to know how to insert this (declaration) newweb_DocumentCompleted it's similar to WebBrowser_DocumentCompleted but it's a variable


Some time after you have created the control, add something like the following to your code:
AddHandler newweb.DocumentCompleted, AddressOf SomeSubToRunWhenDocumentCompletedIsCalled

(syntax from memory, may contain minor, easily correctable errors (like a missing () ))

Then make sure you have something like this later:

Public Sub SomeSubToRunWhenDocumentCompletedIsCalled()
...
End Sub


Hope that helped. Don't forget to rate if it did. ;)



IT works only if I declare the variable in the PUBLIC CLASS FORM but when I declare IT in a PRIVATE SUB BUTTON IT WONT WORK cause the " newweb " is not declared in the PUBLIC SUB this is what i want exactly

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newtab As New TabPage
Dim newweb As New WebBrowser

TabControl2.TabPages.Add(newtab)
TabControl2.SelectTab(TabControl2.TabCount - 1)
TabControl2.SelectedTab.Controls.Add(newweb)
newweb.Dock = DockStyle.Fill
TabControl2.SelectedTab.BackgroundImage = My.Resources.green

End Sub

Public Sub newwebsub()
???????
TabControl2.SelectedTab.Text = newweb.document.Url.AbsoluteUri
End Sub

N.B : This is what i need.I need to declare newweb in a PRIVATE SUB
thank you very much dawmail333 :bigsmile: for replying me hope you solve me this problem
Was This Post Helpful? 0
  • +
  • -

#4 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: How could I create declaration(event) to a variable control in VB .net

Posted 22 November 2010 - 05:25 AM

Try this:

TabControl2.SelectedTab.Text = TabControl2.SelectedTab.Controls(0).document.url.absoluteuri

(Once again, from memory)

How's that?
If you have more controls than that in the tab, I'll knock up some working code. Just tell me what version of .Net you are using first.
Was This Post Helpful? 1
  • +
  • -

#5 eddychamoun  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 35
  • Joined: 22-November 10

Re: How could I create declaration(event) to a variable control in VB .net

Posted 22 November 2010 - 07:17 AM

View Postdawmail333, on 22 November 2010 - 04:25 AM, said:

Try this:

TabControl2.SelectedTab.Text = TabControl2.SelectedTab.Controls(0).document.url.absoluteuri

(Once again, from memory)

How's that?
If you have more controls than that in the tab, I'll knock up some working code. Just tell me what version of .Net you are using first.


THANK YOU SO MUCH DAWMAIL333 :bigsmile: FOR GIVING ME YOUR IDEAS AND FOR SOLVING ME THIS PROBLEM
Finally it worked like that :


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newtab As New TabPage
Dim newweb As New WebBrowser

TabControl2.TabPages.Add(newtab)
TabControl2.SelectTab(TabControl2.TabCount - 1)
TabControl2.SelectedTab.Controls.Add(newweb)
newweb.Dock = DockStyle.Fill
TabControl2.SelectedTab.BackgroundImage = My.Resources.green
AddHandler newweb.DocumentCompleted, AddressOf newwebsub
End Sub


Public Sub newwebsub()

TabControl2.SelectedTab.Text = CType(TabControl2.SelectedTab.Controls.Item(0), WebBrowser).document.Url.AbsoluteUri
End Sub

finally it ended by calling the newweb in the selectedtab according to the index tab and type
DAWMAIL333 plz If u dont mind could u write me your E-MAIL address If i needed help ! THANK YOU :bigsmile: again
Was This Post Helpful? 0
  • +
  • -

#6 dawmail333  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 27
  • View blog
  • Posts: 174
  • Joined: 02-July 07

Re: How could I create declaration(event) to a variable control in VB .net

Posted 22 November 2010 - 04:28 PM

No worries, glad I could help.

If you have a problem in future, make another post, then PM me with a link to the post. Don't PM me directly, as it's best to give everyone a chance to reply. I'm definitely not the best programmer, I'm self taught, and I've only been going for three years.

Also, try to phrase your questions more clearly to start with, make sure you give a good context (e.g. that code you gave in the second post), and remember to use
Code Here


You should get a reply more quickly that way.

Cheers!

This post has been edited by dawmail333: 22 November 2010 - 04:30 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1