i want to add a google chrome control to my application because internet explorer control isnt very good.It shows the web pages wrong etc.Some help please
Asked
Active
Viewed 1.3k times
0
-
2Possible duplicate of [Replacing .NET WebBrowser control with a better browser, like Chrome?](https://stackoverflow.com/questions/790542/replacing-net-webbrowser-control-with-a-better-browser-like-chrome) – Andrew Morton Feb 12 '19 at 15:54
-
cef sharp is for c# right?i use visual basic – Stelios Liakopoulos Feb 12 '19 at 18:19
-
You can have both VB.NET and C# projects in the same solution. To use the C# part in the VB.NET project, add a reference to the dll generated by the C# project into the VB.NET project. And I noticed you seemed to end the last time you asked the same question with "ok i will try it and see if it works." If you had given details of what problems you had encountered, we would have something new to answer and we could help you work towards a solution. – Andrew Morton Feb 12 '19 at 18:35
-
I wouldn't just say that IE isnt very good, it is an outdated browser and there needs to be more community support for such integrations to help modernize VB. There's so much potential for VB to be more universal. Thanks for posting :) – Alex Roberts May 03 '22 at 22:39
2 Answers
0
if you want replace internet explorer with chrome in your winforms you must have to include third party tool (library). now a days there many some of that are
- Selenium
- CefSharp
- DotNet Browser
- OpenWebKitSharp
given list are only some browser . you could also google it out "winform replace webbrowser with chrome".
Thanks

Steve B
- 36,818
- 21
- 101
- 174

Pathan Rameej
- 1
- 3
-
selenium,cefsharp and openWebKitshapt is for c#.I asked for visual basic.Also the doNet Browser is paid.So i would prefer something free – Stelios Liakopoulos Feb 13 '19 at 11:40
-
selenium can also be utilized on vb.net winform if you want other help dont hesitate and tell me in brief. – Pathan Rameej Feb 14 '19 at 13:10
-
0
my friend please refere to code given below.
Imports Microsoft.Win32
Imports System
Imports System.Collections
Imports System.ComponentModel
Imports System.Drawing
Imports System.Runtime.CompilerServices
Imports System.Windows.Forms
Imports mshtml
Imports System.Net
Imports System.IO
Imports System.Text
Imports System.Drawing.Imaging
Imports OpenQA.Selenium.Chrome.ChromeDriver
Imports OpenQA.Selenium
Imports OpenQA.Selenium.Interactions
Imports OpenQA.Selenium.Interactions.Actions
Imports OpenQA.Selenium.Support.UI
Imports OpenQA.Selenium.Chrome
Imports OpenQA.Selenium.Support.Events
Imports System.Text.RegularExpressions
Public Class CLOGIN
Public MASTERID As String = ""
Public MASTERPASSWORD As String = ""
Dim webbrowse As New WebBrowser()
Private _DOCUMENTREADY As Integer
Private ERRORSFOUND As Boolean
Private RequestID As String
Private READYSTATE As Boolean
Public mconfig As New MasterConfig()
Public GSTCAPTCHA As New CommonCaptcha()
Private CaptchaCookie = ""
Private WEBSTATEINC As Boolean = True
Public wbr As New Chrome.ChromeDriver(mconfig.MASTERSERVICE, mconfig.MASTEROPTION)
Public WithEvents driver As New EventFiringWebDriver(wbr)
Private Sub CLOGIN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler driver.Navigated, AddressOf OnNavigated
RECALL()
End Sub
Public Function CropImage(ByVal source As Bitmap, ByVal section As Rectangle) As Bitmap
Dim bmp As New Bitmap(section.Width, section.Height)
Dim g As Graphics = Graphics.FromImage(bmp)
g.DrawImage(source, 0, 0, section, GraphicsUnit.Pixel)
Return bmp
End Function
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
End Sub
Public Sub RECALL()
INITLABEL:
wbr.Url = "https://example.com/services/do_login"
wbr.Navigate()
System.Threading.Thread.Sleep(2500)
Application.DoEvents()
If Not wbr.Url.Contains("/do_login") Then
GoTo INITLABEL
End If
Dim origialheight = Me.MdiParent.Height
Dim dblheight = origialheight * 0.75
Dim proportedration = origialheight - dblheight
Dim maxwidth = Me.MdiParent.Width
Me.MdiParent.WindowState = FormWindowState.Normal
Me.MdiParent.Location = New Point(0, dblheight + 1)
Me.MdiParent.Size = New Size(maxwidth, proportedration) 'dblheight
wbr.Manage().Window().Size = New System.Drawing.Size(maxwidth, dblheight) 'dblheight
wbr.Manage().Window().Position = New Point(0, 0)
Dim action As New Actions(wbr)
Dim wait As New WebDriverWait(wbr, System.TimeSpan.FromSeconds(5))
wait.Until(ExpectedConditions.ElementExists(By.Id("username")))
wbr.FindElement(By.XPath("//*[@id='username']")).SendKeys(MASTERID) 'txtuserid.Text
wbr.FindElement(By.XPath("//*[@id='user_pass']")).SendKeys(MASTERPASSWORD)
Threading.Thread.Sleep(3000)
Application.DoEvents()
Dim master = ""
wbr.FindElement(By.XPath("//*[@id='captcha']")).SendKeys(OpenQA.Selenium.Keys.Tab)
End Sub
Private Sub btnlogout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogout.Click
End Sub
Private Sub lblshowpass_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblshowpass.CheckedChanged
If lblshowpass.Checked Then
txtpassword.PasswordChar = ""
Else
txtpassword.PasswordChar = "*"
End If
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click, Button5.Click
wbr.FindElement(By.XPath("//*[@id='captcha']")).SendKeys(TextBox2.Text)
wbr.FindElement(By.XPath("//*[@type='submit']")).Submit()
WaitUntilDocumentIsReady(TimeSpan.FromSeconds(5))
System.Threading.Thread.Sleep(1500)
Application.DoEvents()
If wbr.Url.Contains("/login") Then
Dim wait As New WebDriverWait(wbr, System.TimeSpan.FromSeconds(3)) 'you can play with the time integer to wait for longer than 15 seconds.`
Try
Dim myLink = wbr.FindElementByXPath("//*[@data-ng-if='loginform.captcha.$error.invalid_captcha']")
If Not myLink Is Nothing Then 'wbr.PageSource.Contains("Enter valid Letters shown") Then
MsgBox("Invalid Captcha Code", MsgBoxStyle.Critical, "Application Error")
wbr.FindElement(By.XPath("//*[@id='user_pass']")).SendKeys(txtpassword.Text)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
Catch ex As Exception
End Try
Try
If wbr.PageSource.Contains("class=""alert alert-danger""") Then
MsgBox("Invalid User ID or Password", MsgBoxStyle.Critical, "Application Error")
wbr.Dispose()
Application.Exit()
End If
Catch ex As Exception
End Try
Else
wbr.Manage().Window().Maximize()
Me.MdiParent.WindowState = FormWindowState.Minimized
End If
End Sub
Public Sub ReCaptcha(ByVal wbr As ChromeDriver)
End Sub
Public Sub OnNavigated(ByVal sender As Object, ByVal e As Support.Events.WebDriverNavigationEventArgs) Handles driver.Navigated
If wbr.Url.Contains("/do_login") Then
Dim wait As New WebDriverWait(wbr, System.TimeSpan.FromSeconds(3))
Try
Dim myLink = wbr.FindElementByXPath("//*[@data-ng-if='loginform.captcha.$error.invalid_captcha']")
If Not myLink Is Nothing Then 'wbr.PageSource.Contains("Enter valid Letters shown") Then
MsgBox("Invalid Captcha Code", MsgBoxStyle.Critical, "Application Error")
wbr.FindElement(By.XPath("//*[@id='user_pass']")).SendKeys(txtpassword.Text)
Me.TextBox1.Text = ""
Me.TextBox1.Focus()
End If
Catch ex As Exception
End Try
Try
If wbr.PageSource.Contains("class=""alert alert-danger""") Then
MsgBox("Invalid User ID or Password", MsgBoxStyle.Critical, "Application Error")
wbr.Dispose()
Application.Exit()
End If
Catch ex As Exception
End Try
Else
End If
End Sub
Public Sub truncateUnfinish(ByVal string1 As String)
If Not IsNumeric(string1) Then
Return
End If
Dim answer = Regex.Replace(string1, "\D", "")
If string1.Length > 6 Then
TextBox2.Text = answer.Substring(0, 6)
End If
End Sub
Function AllCaps(ByVal stringToCheck As String) As Boolean
AllCaps = StrComp(stringToCheck, UCase(stringToCheck), vbBinaryCompare) = 0
End Function
End Class
Thanks.

Pathan Rameej
- 1
- 3