Hi, how can I pass data between user controls?
form1 contains Usercontrol1 and form2 contains usercontrol2.
Both usercontrols have the size of their respective forms.
With usercontrol1 I extract a link with the webbrowser object that I would like to transfer to usercontrol2.
I was thinking of creating public functions in Usercontrol1 which I can access from Usercontrol2.
But this is easy to say in theory and little in practice. At least as far as my "experience" is concerned ...
For example, this code is in usercontrol2, create a qr image. But the problem lies in the fact that the link I need to transform into qr is extracted from usercontrol1, so I need to "communicate" between the usercontrols.
Or for example In usercontrol1 I have a sub that extracts with a webclient the page title of a site and I want this string to be added to the listbox in Usercontrol2. Would it be feasible?
Some doubts..
Should I use functions to return the value of what happens inside the subs? If so, what should I do?
Also .. would it be possible to communicate data between usercontrols even when one of them is closed?
For example, if usercontrol1 pulls 100 titles to theoretically be inserted as new items in the listbox in usercontrol2, but the latter hasn't been opened yet, should I actually leave usercontrol2 always open on display ??
Thank you in advance
Mattia
form1 contains Usercontrol1 and form2 contains usercontrol2.
Both usercontrols have the size of their respective forms.
With usercontrol1 I extract a link with the webbrowser object that I would like to transfer to usercontrol2.
I was thinking of creating public functions in Usercontrol1 which I can access from Usercontrol2.
But this is easy to say in theory and little in practice. At least as far as my "experience" is concerned ...
For example, this code is in usercontrol2, create a qr image. But the problem lies in the fact that the link I need to transform into qr is extracted from usercontrol1, so I need to "communicate" between the usercontrols.
Code:
Sub getqr
Dim sitoGoogleQrCode As String = "http://chart.googleapis.com/chart?chs={WIDTH}x{HEIGHT}&cht=qr&chl={TESTO}"
sitoGoogleQrCode = sitoGoogleQrCode.Replace("{WIDTH}", PictureBox1.Width.ToString()).Replace("{HEIGHT}", PictureBox1.Height.ToString()).Replace("{TESTO}", WebUtility.UrlEncode(usercontrol1.link to extract..))
Dim client As WebClient = New WebClient()
Dim bytes As Byte() = client.DownloadData(sitoGoogleQrCode)
client.Dispose()
Dim memStream As MemoryStream = New MemoryStream(bytes)
Dim bmpQrCode As Bitmap = New Bitmap(memStream)
PictureBox1.Image = bmpQrCode
End Sub
Some doubts..
Should I use functions to return the value of what happens inside the subs? If so, what should I do?
Also .. would it be possible to communicate data between usercontrols even when one of them is closed?
For example, if usercontrol1 pulls 100 titles to theoretically be inserted as new items in the listbox in usercontrol2, but the latter hasn't been opened yet, should I actually leave usercontrol2 always open on display ??
Thank you in advance
Mattia