Programming Environment: Visual Studio 2010
Programming Language: VB.NET
I have a tabbed web-browser that I add dynamically, I Dim the the web-browser every-time the user clicks the New Tab button, like this: browser = New WebBrowser() and give it a name based on the tab count, e.g. browser2, if there are 2 tab pages. So my question is - about time - that how would I get the Url of the WebBrowser, I have tried Dim UrlString As String = CType(tabMain.SelectedTab.Controls.Item(browser.Name), WebBrowser).Url.ToString But, correct me if I am wrong, I found that WebBrowser isn't classed as a Control, and the reason why I think this is because:
This gives me an exception: Object reference not set to an instance of an object.
So I tried looping through the controls in the tabMain.SelectedTab and found that the WebBrowser(browser) isn't included in the collection. The code I used to loop was:
For Each ctrl As Control In Me.tabMain.SelectedTab.Controls
MsgBox(ctrl.Name)
Next
Tried looping through all the Parent controls, but no sign of the WebBrowser showing up. Hope this is enough information =P
Thanks in advance.
UPDATE: Figured out the problem, really stupid, and my theory was bullshit too =P. Just ignore =] lol
try this.
Dim UrlString As String = CType(tabMain.Controls.Item(0), WebBrowser).Url.ToString
I assume tabMain is the name of the TabControl. If this is true and each tab has a WebBrowser Control in it then it should work.
Related
I've been working with the DotNetBar objects and controls to redesign my web browser's UI and functionality in VB.NET. (I've been using Visual Studio 2012 just in case that's pertinent or helpful.) I wanted to use the SuperTabControl for my tab control because it allows the placement of buttons inside the tab bar much like the new tab buttons found in major web browsers such as Google Chrome, Mozilla Firefox, Internet Explorer and many others. I went to code this button to create a new SuperTabItem and that was not difficult;
SuperTabControl1.Tabs.Add(New SuperTabItem)
The problem i have is trying to create a new SuperTabItem that contains the same content as another Windows Form in my project. I've been abel to do this successfully with the normal windows TabControl and the DotNetBar TabControl but the SuperTabControl will not render the objects in the SuperTabControlPanel. This is the code that I've been trying to use;
Dim t As BaseItem = SuperTabControl1.CreateTab("New Tab")
Dim panel As SuperTabControlPanel = DirectCast(t.ContainerControl, SuperTabControlPanel)
Dim newtab As New Tab
newtab.Show()
newtab.TopLevel = False
newtab.Dock = DockStyle.Fill
panel.Controls.Add(newtab)
SuperTabControl1.Tabs.Add(t)
This code displays no errors in the code editor but will interrupt my program when the button is clicked and will then stop debugging. I would appreciate any help towards fixing this problem and getting my new tab button to function correctly.
Try This
Dim t As SuperTabItem= SuperTabControl1.CreateTab("New Tab")
I'm playing around in VB.NET currently and I'm trying to make it so that the value from my Richtextbox1 goes into my webbrowsers search bar (It's navigating to http://google.com currently..)!
The 'class' of the search bar is "gbqfif".. I was trying things like:
RichTextBox1.Text = WebBrowser1.Document.GetElementById("gbqfif")
Then basically I would invoke a click on the button itself, just trying to get the richtextbox value working first!
If anyone could help, I'd love it! (I searched SOF first before posting)
EDIT: Getting this error alot:
Error 1 'GetElementByClass' is not a member of 'System.Windows.Forms.HtmlDocument'.
You are doing the complete opposite. Your code assigns a text from the webbrowser to the RichTextBox. Change the code to
WebBrowser1.Document.GetElementById("gbqfif").InnerText = RichTextBox1.Text
When you visit Google, IE says something like Google - Microsoft Internet Explorer. However, if you changed the address to, say, Stack Overflow, it would say something like Stack Overflow - Microsoft Internet Explorer.
So, how can I make a dynamic title bar that changes with a variable?
You set the Form.Text, using the current instance (which you access using Me):
Dim SomeVariable As String
SomeVariable = "Site 1 - My Application"
Me.Text = SomeVariable
For future reference, you can figure a lot of this out by clicking on the object you want to change things on in the Designer and then looking at the Properties window. In this case, you'd click on your main window and then looking at Properties, where you'd find the "Text" property. Changing it in the Properties window would change it in the Designer immediately when you type new text and hit the Enter key or move to another property.
I need to copy an image from a webbrowser control to my clipboard, because the image changes on every reload, and I tried to get the "src"-attribute and changing my picturebox.imagelocation to that, but the image on the picturebox differed from the picture on the webbrowser control.
I'm trying to automate a web service, and it requires a captcha to be filled out, and it changes every time the page is loaded, that's why I need to get the one that is currently displayed.
Assuming you are using Windows Forms (need to change the way to get document if you use WPF) and the user did not block clipboard access in IE zone settings
Dim doc As IHTMLDocument2 = DirectCast(webBrowser1.Document.DomDocument, IHTMLDocument2)
Dim body As IHTMLElement2 = DirectCast(doc.body, IHTMLElement2)
Dim imgRange As IHTMLControlRange = DirectCast(body.createControlRange(), IHTMLControlRange)
Dim image As IHTMLControlElement = DirectCast(DirectCast(doc, IHTMLDocument3).getElementById(sImgID), IHTMLControlElement)
imgRange.add(image)
imgRange.execCommand("Copy", False, Nothing)
Pseudo code:
For each element by tag 'img'. Get the 'src' attribute. Fire up an instance of HttpWebRequest or use WebClient.DownloadFile for the source.
You will need to do some trickery determining where the source is in relation to the url. For instance the src could be '/img/pony.jpg', in which case you'll need to get the url's root from the WebBrowser control to make it 'http://mylittle.com/img/pony.jpg'.
A few more details.
I need to programmatically (Winforms, VB.NET) check if a site is in the Allowed Sites list of the IE Pop-Up Blocker (IE 7 and 8 and Windows XP, Vista and 7) and if not, add it. The application is fully trusted and I don't want to disable the Pop-Up blocker entirely.
To clarify some things, this is for a web-automation application with several users across 3 countries. I want to avoid receiving tons of emails and explaining each time how to add the website to the Allowed Sites manually.
Also, some of the users have Google Toolbar installed, which also has a Popup Blocker creating trouble to my app. Can this also be done programmatically?
Ok, I got the first part. It's just a registry value.
Imports Microsoft.Win32
And the actual code:
Dim siteString As String = "mysite.com"
Dim emptyArray() As Byte = New Byte() {} 'Works as a Zero-Length Binary Value'
Dim subKey As String = "Software\Microsoft\Internet Explorer\New Windows\Allow"
Dim rkKey As RegistryKey = Registry.CurrentUser.OpenSubKey(subKey)
Dim value As Object = rkKey.GetValue(siteString)
If value Is Nothing Then 'Check if the value is already there'
rkKey.SetValue(siteString, emptyArray, RegistryValueKind.Binary)
End If
It also works with multiple versions of IE and Windows.
Does anyone have any idea about the Google toolbar Popup blocker?
ps. Sorry about closing the single quotes, but it simply makes it look nicer.