SRL Archive - C#/Visual Basic Help and Tutorials

SandBrowser, a basic Web Browsing Application!


Sandstorm

2009-09-05 21:04:42

Features:

Forward and Back.
Home page.
Search engines work (pressing enter instead of search won't fuck it up).
The url bar now displays the URL of the current page, instead of what you typed, and will change if you click a link.
Custom buttons :D.
Favorites!

Bugs:

Full screen youtube and the like don't accept the escape key.

Source:

Form One (the actual browser):

Public Class Form1
Dim Homepage As Uri
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
My.Settings.F2 = False
My.Settings.F3 = False
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Homepage = My.Settings.Homepage
My.Settings.F2 = False
My.Settings.F3 = False
If Not Homepage = Nothing Then
WebBrowser1.Navigate(Homepage)
If Not My.Settings.HPURL = Nothing Then
TextBox1.Text = My.Settings.HPURL.ToString
End If
Else
WebBrowser1.Navigate("www.google.com")
TextBox1.Text = "www.google.com".ToString
End If
Me.Text = "SandBrowser - " & WebBrowser1.DocumentTitle
TextBox1.AcceptsReturn = True
If Not (My.Settings.URL.Count = Nothing) Then
For i = 1 To (My.Settings.URL.Count - 1)
tlsFaves.DropDownItems.Add(My.Settings.URL.Item(i), Nothing, AddressOf Clicked)
Next
End If
End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Me.Text = "SandBrowser - " & WebBrowser1.DocumentTitle
TextBox1.Text = WebBrowser1.Url.ToString
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Back_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
If WebBrowser1.CanGoBack Then
WebBrowser1.GoBack()
End If
End Sub
Private Sub Forward_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Back.Click
If WebBrowser1.CanGoForward Then
WebBrowser1.GoForward()
End If
End Sub

Private Sub GoToYourHomepageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles GoToYourHomepageToolStripMenuItem.Click
If Not My.Settings.Homepage = Nothing Then
WebBrowser1.Navigate(My.Settings.Homepage)
Else
WebBrowser1.GoHome()
End If
End Sub

Private Sub UseCurrentPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UseCurrentPageToolStripMenuItem.Click
Homepage = WebBrowser1.Url
My.Settings.Homepage = Homepage
My.Settings.HPURL = WebBrowser1.Url
End Sub

Private Sub Home_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Home.Click
GoToYourHomepageToolStripMenuItem.PerformClick()
End Sub

Private Sub Forward_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Forward.Click
If WebBrowser1.CanGoForward Then
WebBrowser1.GoForward()
End If
End Sub

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If Not TextBox1.Text = "" Then
If e.KeyChar = Chr(13) Then
Button1.PerformClick()
End If
End If
End Sub

Private Sub UseACustomPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UseACustomPageToolStripMenuItem.Click
Dim SecondForm As New Form2
If My.Settings.F2 Then
SecondForm.Focus()
Else
SecondForm.Show()
My.Settings.F2 = True
End If
End Sub

Private Sub ViewCreditsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ViewCreditsToolStripMenuItem.Click
Dim ThirdForm As New Credits
If My.Settings.F3 Then
ThirdForm.Focus()
Else
ThirdForm.Show()
My.Settings.F3 = True
End If
End Sub


Sub Clicked(ByVal site As System.Object, ByVal e As System.EventArgs)
WebBrowser1.Navigate(site.ToString)
TextBox1.Text = site.ToString
End Sub

Private Sub BookmarkThisPageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BookmarkThisPageToolStripMenuItem.Click
tlsFaves.DropDownItems.Add(WebBrowser1.Url.ToString, Nothing, AddressOf Clicked)
My.Settings.URL.Add(WebBrowser1.Url.ToString)
End Sub
End Class

Form two (Custom home page set up):

Public Class Form2
Private Sub F2ChangeHP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles F2ChangeHP.Click
If InStr(HPURL.Text, "http://") = 0 Then
If InStr(HPURL.Text, "www.") = 0 Then
HPURL.Text = "http://www." & HPURL.Text
Else
HPURL.Text = "http://" & HPURL.Text
End If
End If
Dim HP As New Uri(HPURL.Text)
If HPURL.Text <> "" Then
My.Settings.Homepage = HP
My.Settings.HPURL = HP
HPURL.Text = ""
Me.Hide()
End If
End Sub
End Class

Form three (credits):

Public Class Form3

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

Post any opinions, ideas, help, whatever you think I could do to improve it. Just starting to learn Visual Basic, so yea :P.

Download link, file is to big to attach:

http://www.megaupload.com/?d=0P0YNUCF

~Sandstorm

ShowerThoughts

2009-09-05 21:31:02

Simple, but good for vb, I can't even give it a look. :p

Sandstorm

2009-09-05 22:00:46

Yea, I'm hoping to add in favorites, home page, and the like, but I have to figure out saving and loading from files first :P.

~Sandstorm

ShowerThoughts

2009-09-05 22:15:22

Use XML or Ini file's they are easy enough for that kind of job.

Neehosoft

2009-09-05 22:19:35

From: Sandstorm
Yea, I'm hoping to add in favorites, home page, and the like, but I have to figure out saving and loading from files first :P.

~Sandstorm

I could help with that, was version of VB are you using?

Sandstorm

2009-09-05 22:30:59

Microsoft Visual Basic 2008 EE. First one I found xD.

~Sandstorm

Neehosoft

2009-09-05 22:41:51

From: Sandstorm
Microsoft Visual Basic 2008 EE. First one I found xD.

~Sandstorm


What types of file(s) do you wish to load?

ShowerThoughts

2009-09-05 22:48:41

From: Neehosoft
What types of file(s) do you wish to load?


From: Sandstorm
Yea, I'm hoping to add in favorites, home page, and the like, but I have to figure out saving and loading from files first :P.

~Sandstorm


Figure out what one is the best :D.

Neehosoft

2009-09-05 22:52:40

From: Hermen
Figure out what one is the best :D.


ooh lol. Well then you should probably store it all in a file under a user folder with a some xml files that store the variables "homepage" and favorites in a nice list. When i used to have a vb web browser i even made a customized themeing option that loaded from the xml

Sandstorm

2009-09-05 22:58:59

I was thinking of just doing this (scar example):


Procedure Savehome;
Begin
Writeini(path, 'home', 'page', URL);
End;

Procedure Loadhome;
Begin
Homepage := Readini(path, 'home', 'page');
end;

Sort of like that. Not sure how I'd do it in VB though (the saving and loading, variable assignment is a snap).

And do the same thing for the favorites - teach me to save and load files and I can do the rest fine, if rather messily xD.

~Sandstorm

Nadeem

2009-09-05 23:52:06

In VB you can use the My.Settings feature and have the values written into the assembly form inside the exe. Checkout: http://msdn.microsoft.com/en-us/library/ms379611%28VS.80%29.aspx



~NS

Sandstorm

2009-09-06 00:52:05

Thanks, but that doesn't help much. I've found like five tutorials on it, but they all assume knowledge of the coding, and so it looks like a big jumble to me :(.

~Sandstorm

ShowerThoughts

2009-09-06 00:58:55

From: Sandstorm
Thanks, but that doesn't help much. I've found like five tutorials on it, but they all assume knowledge of the coding, and so it looks like a big jumble to me :(.

~Sandstorm


Don't give up! :)
I just don't code Visual Basic :(.

Sandstorm

2009-09-06 01:07:51

Yea, I'm still looking around, but the future looks bleak at this point in time :(.

~Sandstorm

TViYH

2009-09-06 01:34:04

Button1_Click(Me, EventArgs.Empty)

Do this instead: Button1.PerformClick

Also, you don't need that. Just set the Form's AcceptButton to Button1.

Also, give the controls names that you can remember, such as btnGo, txtURL, etc.

Rick

2009-09-06 01:51:24

From: Sandstorm
Yea, I'm still looking around, but the future looks bleak at this point in time :(.

~Sandstorm


Don't give up!
The My.Settings feature is actually pretty easy to use once you understand it. I'll make an easy to follow tutorial for you.

Sandstorm

2009-09-06 02:46:28

@TViYH - Cool, that's what I originally tried to do, but couldn't find it :P.

@R!ch!e - Wow, thanks! And yea, most things are easy - once you understand them.

~Sandstorm

Rick

2009-09-06 03:15:16

Sandstorm, hopefully this will give you a basic idea on how to use My.Settings :)

http://www.villavu.com/forum/showthread.php?p=627542#post627542

Sandstorm

2009-09-06 03:47:21

Perfect! So much easier to understand. Home page is working now. Just gotta figure out the favorites, and I'll release this next one.

~Sandstorm

Sandstorm

2009-09-06 08:29:53

Home page now works - try to crash it through the use of the custom home page please! I need to know if anything has to be added to make it crash-proof.

Fixed that damn forward button :P.

Fixed search engines such as google and youtube not working. You'd press enter and it would just refresh the page.

Fixed the url area - it'll now change the url based on the page.

Tell me what you think, and any bugs!

~Sandstorm

cycrosism

2009-09-06 10:03:44

Visual Basic? No thnx no one uses that

Neehosoft

2009-09-06 10:10:54

From: cycrosism
Visual Basic? No thnx no one uses that


dont hate vb just becuase your ubuntu?

Rick

2009-09-06 19:08:22

From: cycrosism
Visual Basic? No thnx no one uses that


Why bother posting or even looking in the VB section if "no one" uses it?

Sandstorm, it looks much better now. Just a quick thing I noticed, when you use the home page button you should make it update the Address Bar, as it remains as the previously visited URL.

Sandstorm

2009-09-06 19:29:36

From: r!ch!e
Why bother posting or even looking in the VB section if "no one" uses it?

Sandstorm, it looks much better now. Just a quick thing I noticed, when you use the home page button you should make it update the Address Bar, as it remains as the previously visited URL.


I put that in the page load trigger?

Added custom buttons and changed the background.

After four or five hours of pondering, testing, fixing, testing some more, and tweaking bugs, I introduce to you:

Favorites! As yet they can't be removed, but this is being worked on.

~Sandstorm

cycrosism

2009-09-09 08:30:06

No I am just saying in the programming industry no one uses visual basic. This has nothing to do with the fact I use ubuntu.

Sandstorm

2009-09-09 09:21:12

From: cycrosism
No I am just saying in the programming industry no one uses visual basic. This has nothing to do with the fact I use ubuntu.


*Insert point here*

~Sandstorm

TViYH

2009-09-10 01:43:47

From: cycrosism
No I am just saying in the programming industry no one uses visual basic. This has nothing to do with the fact I use ubuntu.


Actually, VERY many programmers in the programming industry use VB.NET.

By the way, since when are YOU in the programming industry to know that "no one uses it"?

Freddy1990

2009-09-10 15:12:53

You should try to build your own browser control and you'll have my wow :) Use a socket to get the page, process the html code and display it (hf writing a javascript engine, lol)

Sandstorm

2009-09-10 23:26:12

I'll look into it, I guess o.o.

~Sandstorm

Freddy1990

2009-09-11 01:10:10

From: Sandstorm
I'll look into it, I guess o.o.

~Sandstorm


Heh, I was kidding, it'd take months to develop a stable browser, let alone a good one…

Sandstorm

2009-09-11 02:05:35

From: Freddy1990
Heh, I was kidding, it'd take months to develop a stable browser, let alone a good one…


I have months o.o.

~Sandstorm

Bobarkinator

2009-09-11 07:09:46

Homemade javascript engine = win

Freddy1990

2009-09-19 19:25:49

From: Bobarkinator
Homemade javascript engine = win


Homemade javascript engine = epic fail
Gl beating speeds of Firefox' engine and such…

Bionicle

2009-09-19 19:27:37

From: Freddy1990
Homemade javascript engine = epic fail
Gl beating speeds of Firefox' engine and such…


You want speed? try google crome. Its uber fast, but fails with java. so runescape is out of the question xD

Bobarkinator

2009-09-20 03:54:27

From: Freddy1990
Homemade javascript engine = epic fail
Gl beating speeds of Firefox' engine and such…


Lol, I wouldn't try to compete with speeds. Just feel accomplished for writing your own JS engine.

rogeruk

2009-09-20 14:58:36

Google Chrome sux lol.

Looking good!

fronty

2009-09-27 12:35:38

From: TViYH
Actually, VERY many programmers in the programming industry use VB.NET.

By the way, since when are YOU in the programming industry to know that "no one uses it"?


Visual Basic and Visual Basic.NET are very different things. Many companies use VB.NET, but many are still tied to VB6 because rewriting big commercial software is so expensive.