Skip to content

Instantly share code, notes, and snippets.

@AungWinnHtut
Created August 3, 2016 06:47
Show Gist options
  • Save AungWinnHtut/54e58b84cc37c1df5098b747da3c603d to your computer and use it in GitHub Desktop.
Save AungWinnHtut/54e58b84cc37c1df5098b747da3c603d to your computer and use it in GitHub Desktop.
Imports System.IO
Imports System.String
Imports System.Net
Imports CefSharp
Imports CefSharp.WinForms
Public Class Form1
Dim sReader As String
Dim sPath As String
Dim browser As ChromiumWebBrowser
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
sPath = Directory.GetCurrentDirectory().ToString()
Dim fileContents As String
If (File.Exists("settings.ini")) Then
fileContents = My.Computer.FileSystem.ReadAllText("settings.ini")
If (fileContents = "") Then
funAskSettings()
Else
End If
Else
funAskSettings()
End If
sReader = My.Computer.FileSystem.ReadAllText("settings.ini")
Me.Text = sReader
funCheckInternet()
End Sub
Public Function IsConnectionAvailable() As Boolean
Dim objUrl As New System.Uri("http://google.com")
Dim objWebReq As System.Net.WebRequest
objWebReq = System.Net.WebRequest.Create(objUrl)
Dim objresp As System.Net.WebResponse
Try
objresp = objWebReq.GetResponse
objresp.Close()
objresp = Nothing
Return True
Catch ex As Exception
objresp = Nothing
objWebReq = Nothing
Return False
End Try
End Function
Public Sub funCheckInternet()
' MessageBox.Show(sPath)
If IsConnectionAvailable() = True Then
' MessageBox.Show("internet is OK")
'WebBrowser1.Navigate(sPath + "\ok.html")
WebBrowser1.Navigate("http://google.com")
Else
'MessageBox.Show("No internet connection")
WebBrowser1.Navigate(sPath + "\error.html")
End If
End Sub
Public Sub funAskSettings()
OpenFileDialog1.InitialDirectory = "c:\"
OpenFileDialog1.Filter = "Exe Files (*.exe)|*.exe|All Files (*.*)|*.*"
If OpenFileDialog1.ShowDialog() <> Windows.Forms.DialogResult.Cancel Then
My.Computer.FileSystem.WriteAllText("settings.ini", OpenFileDialog1.FileName, False)
Else
funAskSettings()
End If
End Sub
Private Sub btnChkInternet_Click(sender As Object, e As EventArgs) Handles btnChkInternet.Click
funCheckInternet()
End Sub
Private Sub btnDownload_Click(sender As Object, e As EventArgs) Handles btnDownload.Click
'My.Computer.Network.DownloadFile("https://drive.google.com/open?id=0B5BlreKt_b80UlFQN09NbjVKakk",
'sPath + "\test.pdf")
Dim myWebClient As New WebClient()
Dim myStringWebResource As String = "http://www.orimi.com/pdf-test.pdf"
myWebClient.DownloadFile(myStringWebResource, sPath + "\test.pdf")
End Sub
Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
If File.Exists(sPath + "/test.pdf") And File.Exists(sReader) Then
Shell(sReader + " /p " + sPath + "/test.pdf")
End If
End Sub
End Class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment