473,320 Members | 1,887 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Dynamic Controls - referencing

Hello,

I am creating my own webbrowser to learn VB .Net. I am stuck on an issue
with regards to dynamically-created controls, in this case tabs on a
tabcontrol and webbrowsers created within each new tab.

Using AddHandler in a class, I can get the delegate Sub to display the name
of the webbrowser that has been clicked (by using msgbox(sender.tag), where
I set the .tag value when creating the control).
What I need to be able to do is use Back, Forward, Stop, Print buttons etc
on ANY webbrowser currently with focus.

In a nutshell at runtime the user might have 6 tabs in a tabcontrol contain
a webbrowser each. How do I pass the value of the currently-selected
webbrowser, dynamically created, to these buttons from the class where I
created the tabs/webbrowsers?

I guess to do something like (quazi code)

webbrowser(x).goback

is what I seek....any ideas? Completely stumped

O.
Feb 17 '06 #1
7 2539
O

Having the same problem myself - if anyone answers this, it will be a
miracle?

Gray

"msdev" <ms*******@nospam.nospam> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am creating my own webbrowser to learn VB .Net. I am stuck on an issue
with regards to dynamically-created controls, in this case tabs on a
tabcontrol and webbrowsers created within each new tab.

Using AddHandler in a class, I can get the delegate Sub to display the
name of the webbrowser that has been clicked (by using msgbox(sender.tag),
where I set the .tag value when creating the control).
What I need to be able to do is use Back, Forward, Stop, Print buttons etc
on ANY webbrowser currently with focus.

In a nutshell at runtime the user might have 6 tabs in a tabcontrol
contain a webbrowser each. How do I pass the value of the
currently-selected webbrowser, dynamically created, to these buttons from
the class where I created the tabs/webbrowsers?

I guess to do something like (quazi code)

webbrowser(x).goback

is what I seek....any ideas? Completely stumped

O.

Feb 17 '06 #2
jvb
Have you tried getting the selected tab page from the tab control?

Feb 17 '06 #3
jvb

yep started there first of all. Problem is, it gives me the tabcontrol tab
that has been selected, but not the webbrowser contained within that tab.

I have been playing with addhandler, as I am sure it had something to do
with it, but to no avail.

What I need to do is to send the value of the currently-selected browser to
some "central settings" point, so that one set of buttons can control any
number of dynamically-created webbrowsers. The stumbling block for me is
trying to send the "currently selected" webbrowser to the goback, goforward,
print, stop buttons, so they only apply to that webbrowser in focus. If the
user selects another tab/webbrowser, the buttons will switch to work with
that focussed browser and so on.

I am probably not explaining it too well! Sorry

Did this help?

"jvb" <go*****@gmail.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Have you tried getting the selected tab page from the tab control?

Feb 17 '06 #4
jvb
If you know tab page selected, can you make the assumption that the
browser on that page is active? So in your code, in the button's click
event, you could try...

CType(TabControl1.SelectedTab.Controls.Item(TabCon trol1.SelectedTab.Controls.GetChildIndex(<Your
Dynamically Created Web Control>)), AxSHDocVw.AxWebBrowser).GoBack()

AxSHDocVw.AxWebBrowser is the browser control i use, not sure if you
are using the same.

Feb 17 '06 #5
You can always track the references yourself. i.e. when you dynamically
create the tab, put in a hashtable the TabIdentifier as the key and a
reference to the webbrowser control contained on that tab. Then as you
change tabs you can set the object reference of web browser (the reference
that is wired to the events) to the one from the hashtable.

something like this (fake code)

dim myBrowserControl as webbrowser

form_load
addhandler browser.next, someproc

init_tab
create new tab tab
myhash(tabindex) = webrowsercontrol on this tab

sub TabChange
myBrowserControl = myHash(tabIndex)
end
"msdev" <ms*******@nospam.nospam> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am creating my own webbrowser to learn VB .Net. I am stuck on an issue
with regards to dynamically-created controls, in this case tabs on a
tabcontrol and webbrowsers created within each new tab.

Using AddHandler in a class, I can get the delegate Sub to display the
name of the webbrowser that has been clicked (by using msgbox(sender.tag),
where I set the .tag value when creating the control).
What I need to be able to do is use Back, Forward, Stop, Print buttons etc
on ANY webbrowser currently with focus.

In a nutshell at runtime the user might have 6 tabs in a tabcontrol
contain a webbrowser each. How do I pass the value of the
currently-selected webbrowser, dynamically created, to these buttons from
the class where I created the tabs/webbrowsers?

I guess to do something like (quazi code)

webbrowser(x).goback

is what I seek....any ideas? Completely stumped

O.

Feb 19 '06 #6
Jeff,

I think you might be on to something here. Is there any chance you can
expand on your code a bit? I am new to dynamic controls in vb.net 2005.

If I replace webbrowser1.goback with mybrowsercontrol.goback, will this
work too?

G
Jeff Jarrell wrote:
You can always track the references yourself. i.e. when you dynamically
create the tab, put in a hashtable the TabIdentifier as the key and a
reference to the webbrowser control contained on that tab. Then as you
change tabs you can set the object reference of web browser (the reference
that is wired to the events) to the one from the hashtable.

something like this (fake code)

dim myBrowserControl as webbrowser

form_load
addhandler browser.next, someproc

init_tab
create new tab tab
myhash(tabindex) = webrowsercontrol on this tab

sub TabChange
myBrowserControl = myHash(tabIndex)
end
"msdev" <ms*******@nospam.nospam> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
Hello,

I am creating my own webbrowser to learn VB .Net. I am stuck on an issue
with regards to dynamically-created controls, in this case tabs on a
tabcontrol and webbrowsers created within each new tab.

Using AddHandler in a class, I can get the delegate Sub to display the
name of the webbrowser that has been clicked (by using msgbox(sender.tag),
where I set the .tag value when creating the control).
What I need to be able to do is use Back, Forward, Stop, Print buttons etc
on ANY webbrowser currently with focus.

In a nutshell at runtime the user might have 6 tabs in a tabcontrol
contain a webbrowser each. How do I pass the value of the
currently-selected webbrowser, dynamically created, to these buttons from
the class where I created the tabs/webbrowsers?

I guess to do something like (quazi code)

webbrowser(x).goback

is what I seek....any ideas? Completely stumped

O.


Feb 19 '06 #7
It is going to look a little like this. I'd be careful to pick a good key
for the dictionary. In this case I am using the count of tab pages as part
of the key but that won't work if you ultimately take tab pages out. You
might also want to look at the "InitializeComponent" on similar components
created at design time and set those same properties on the creation of the
dynamic controls.

Dim _dctWebBrowserReferences As New Hashtable

Friend WithEvents _webbrowser As WebBrowser

Private Sub newPage()

Dim myNewTabPage As New TabPage

myNewTabPage.Name = "Page" & Me.TabControl1.TabCount + 1

myNewTabPage.Text = "Page" & Me.TabControl1.TabCount + 1

Dim myNewBrowser As New WebBrowser

myNewBrowser.Name = "WebBrowser" & Me.TabControl1.TabCount + 1

myNewBrowser.Dock = DockStyle.Fill

Dim key As String

key = myNewTabPage.Text

_dctWebBrowserReferences(key) = myNewBrowser

myNewTabPage.Controls.Add(myNewBrowser)

Me.TabControl1.Controls.Add(myNewTabPage)

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

newPage()

End Sub

Private Sub TabControl1_TabIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles TabControl1.TabIndexChanged

Dim myTabPage As TabPage

myTabPage = TabControl1.SelectedTab

Dim key As String

key = myTabPage.Text

Me._webbrowser = CType(Me._dctWebBrowserReferences(key), WebBrowser)

End Sub

"gray" <ke****@freeuk.com> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Jeff,

I think you might be on to something here. Is there any chance you can
expand on your code a bit? I am new to dynamic controls in vb.net 2005.

If I replace webbrowser1.goback with mybrowsercontrol.goback, will this
work too?

G
Jeff Jarrell wrote:
You can always track the references yourself. i.e. when you dynamically
create the tab, put in a hashtable the TabIdentifier as the key and a
reference to the webbrowser control contained on that tab. Then as you
change tabs you can set the object reference of web browser (the
reference
that is wired to the events) to the one from the hashtable.

something like this (fake code)

dim myBrowserControl as webbrowser

form_load
addhandler browser.next, someproc

init_tab
create new tab tab
myhash(tabindex) = webrowsercontrol on this tab

sub TabChange
myBrowserControl = myHash(tabIndex)
end
"msdev" <ms*******@nospam.nospam> wrote in message
news:ON**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I am creating my own webbrowser to learn VB .Net. I am stuck on an
> issue
> with regards to dynamically-created controls, in this case tabs on a
> tabcontrol and webbrowsers created within each new tab.
>
> Using AddHandler in a class, I can get the delegate Sub to display the
> name of the webbrowser that has been clicked (by using
> msgbox(sender.tag),
> where I set the .tag value when creating the control).
> What I need to be able to do is use Back, Forward, Stop, Print buttons
> etc
> on ANY webbrowser currently with focus.
>
> In a nutshell at runtime the user might have 6 tabs in a tabcontrol
> contain a webbrowser each. How do I pass the value of the
> currently-selected webbrowser, dynamically created, to these buttons
> from
> the class where I created the tabs/webbrowsers?
>
> I guess to do something like (quazi code)
>
> webbrowser(x).goback
>
> is what I seek....any ideas? Completely stumped
>
> O.
>
>

Feb 19 '06 #8

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

Similar topics

1
by: Will | last post by:
Hi all. I'm learning VB.Net and am developing a WinForms app. I'm trying to make an app that I will use to scan in one or more than on image. I want to use a tabbed interface to hold each image....
6
by: MikeY | last post by:
Hi Everyone, Does anyone know where I can get my hands on a sample with source code of a simple dynamic button control in C# Windows form. I am looking for a sample that uses a class library...
6
by: Trevor Hartman | last post by:
Hi, I need to refer to my objects dynamically. I have a 7 table cells (sunCell, monCell, tueCell....). I am looping through some data, checking its date and adding it to the correct cell. I...
1
by: Felipe Garcia | last post by:
Does makes difference referencing controls inside EVERY page <%@ Register TagPrefix="PC" Namespace="MyControls" Assembly="Personal.MyControls" %> or referencing controls ONCE inside web.config,...
0
by: louise raisbeck | last post by:
Hi there, I am databinding a datagrid on the onload with the usual !IsPostBack condition. I have to create some dynamic checkboxes, because i dont know how many i will need until the dataset...
2
by: Suzanne | last post by:
Hi all, I'm reposting this message as I'm experiencing this problem more and more frequently : I really hope someone out there can help me as I've been tearing my hair out on this one for a...
6
by: YYZ | last post by:
In my program, a user can open up many different "Loans" -- each one is loaded into a dynamically created usercontrol (ucLoan) -- in order for them to be able to switch between the ones they have...
6
by: J055 | last post by:
Hi I have a FormView, Panel and ObjectDataSource control. I'm trying to change the Panel.Visible property to true based on a value in the ReturnValue object in the ObjectDataSource.Selected...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.