How To Add A Syntax Highlighter In VB.NET

how to add a syntax highlighter in vb.net this is the easiest and the best way to do it so lets get start

open your visual basic 2008/2010 now make a new project or if you have a project to add this syntax highlighter just open your project anyway i will go with a new project create a new project and name it whatever you want and go to the form and make a new class and paste this code inside the class


Public Class SyntaxRTB

    Inherits System.Windows.Forms.RichTextBox

    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" _
       (ByVal hWnd As IntPtr, ByVal wMsg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As Integer

    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hWnd As Integer) As Integer

    Private _SyntaxHighlight_CaseSensitive As Boolean = False

    Private Words As New DataTable

    'Contains Windows Messages for the SendMessage API call
    Private Enum EditMessages
        LineIndex = 187
        LineFromChar = 201
        GetFirstVisibleLine = 206
        CharFromPos = 215
        PosFromChar = 1062
    End Enum

    Protected Overrides Sub OnTextChanged(ByVal e As System.EventArgs)
        ColorVisibleLines()
    End Sub

    Public Sub ColorRtb()
        Dim FirstVisibleChar As Integer
        Dim i As Integer = 0

        While i < Me.Lines.Length
            FirstVisibleChar = GetCharFromLineIndex(i)
            ColorLineNumber(i, FirstVisibleChar)
            i += 1
        End While
    End Sub

    Public Sub ColorVisibleLines()
        Dim FirstLine As Integer = FirstVisibleLine()
        Dim LastLine As Integer = LastVisibleLine()
        Dim FirstVisibleChar As Integer

        If (FirstLine = 0) And (LastLine = 0) Then
            'If there is no text it will error, so exit the sub
            Exit Sub
        Else
            While FirstLine < LastLine
                FirstVisibleChar = GetCharFromLineIndex(FirstLine)
                ColorLineNumber(FirstLine, FirstVisibleChar)
                FirstLine += 1
            End While
        End If

    End Sub

    Public Sub ColorLineNumber(ByVal LineIndex As Integer, ByVal lStart As Integer)
        Dim i As Integer = 0
        Dim Instance As Integer
        Dim LeadingChar, TrailingChar As String
        Dim SelectionAt As Integer = Me.SelectionStart
        Dim MyRow As DataRow
        Dim Line() As String, MyI As Integer, MyStr As String

        ' Lock the update
        LockWindowUpdate(Me.Handle.ToInt32)

        MyI = lStart

        If CaseSensitive Then
            Line = Split(Me.Lines(LineIndex).ToString, " ")
        Else
            Line = Split(Me.Lines(LineIndex).ToLower, " ")
        End If

        For Each MyStr In Line
            Me.SelectionStart = MyI
            Me.SelectionLength = MyStr.Length

            If Words.Rows.Contains(MyStr) Then
                MyRow = Words.Rows.Find(MyStr)
                If (Not CaseSensitive) Or (CaseSensitive And MyRow("Word") = MyStr) Then
                    Me.SelectionColor = Color.FromName(MyRow("Color"))
                End If
            Else
                Me.SelectionColor = Color.Black
            End If

            MyI += MyStr.Length + 1
        Next

        ' Restore the selectionstart
        Me.SelectionStart = SelectionAt
        Me.SelectionLength = 0
        Me.SelectionColor = Color.Black

        ' Unlock the update
        LockWindowUpdate(0)
    End Sub

    Public Function GetCharFromLineIndex(ByVal LineIndex As Integer) As Integer
        Return SendMessage(Me.Handle, EditMessages.LineIndex, LineIndex, 0)
    End Function

    Public Function FirstVisibleLine() As Integer
        Return SendMessage(Me.Handle, EditMessages.GetFirstVisibleLine, 0, 0)
    End Function

    Public Function LastVisibleLine() As Integer
        Dim LastLine As Integer = FirstVisibleLine() + (Me.Height / Me.Font.Height)

        If LastLine > Me.Lines.Length Or LastLine = 0 Then
            LastLine = Me.Lines.Length
        End If

        Return LastLine
    End Function

    Public Sub New()
        Dim MyRow As DataRow
        Dim arrKeyWords() As String, strKW As String

        Me.AcceptsTab = True

        ''Load all the keywords and the colors to make them 
        Words.Columns.Add("Word")
        Words.PrimaryKey = New DataColumn() {Words.Columns(0)}
        Words.Columns.Add("Color")

        arrKeyWords = New String() {"select", "insert", "delete", _
           "truncate", "from", "where", "into", "inner", "update", _
           "outer", "on", "is", "declare", "set", "use", "values", "as", _
           "order", "by", "drop", "view", "go", "trigger", "cube", _
           "binary", "varbinary", "image", "char", "varchar", "text", _
           "datetime", "smalldatetime", "decimal", "numeric", "float", _
           "real", "bigint", "int", "smallint", "tinyint", "money", _
           "smallmoney", "bit", "cursor", "timestamp", "uniqueidentifier", _
           "sql_variant", "table", "nchar", "nvarchar", "ntext", "left", _
           "right", "like", "and", "all", "in", "null", "join", "not", "or"}

        For Each strKW In arrKeyWords
            MyRow = Words.NewRow()
            MyRow("Word") = strKW
            MyRow("Color") = Color.LightCoral.Name
            Words.Rows.Add(MyRow)
        Next

    End Sub

    Public Property CaseSensitive() As Boolean
        Get
            Return _SyntaxHighlight_CaseSensitive
        End Get
        Set(ByVal Value As Boolean)
            _SyntaxHighlight_CaseSensitive = Value
        End Set
    End Property

End Class
now debug and stop debugging and see the toolbox you will see something like this



add the tool "syntaxRTB" in to your form and you can replace it with richtextbox or textbox just rename it now debug and paste some codes inside the tool and it will work for sure .

preview - 


hope this helped you

How To Make A Custom Button In VB.NET

we all know how to make custom buttons using images or DLLs but this tutorial is totally different in this tutorial i will be teaching you how to make a custom button without using images or dlls .

so lets get started 

as usual open your visual basic 2008 or  visual basic 2010 and create a new windows application and name it whatever you want and go to the form and add a button and thats it with the GUI and go to code and lets add the custom button function

i am going to use a function , i call it "shimscustombuttonfunction"
 Public Sub shimscustombuttonfunction(ByVal aControl As Control, ByVal Color1 As Color, ByVal Color2 As Color, _
        Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical)

        Dim bmp As New Bitmap(aControl.Width, aControl.Height)
        Dim g As Graphics = Graphics.FromImage(bmp)
        Dim Rect1 As New RectangleF(0, 0, aControl.Width, aControl.Height)

        Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color1, Color2, mode)
        g.FillRectangle(lineGBrush, Rect1)

        aControl.BackgroundImage = bmp
        g.Dispose()
    End Sub
now lets add two events for the button , go to the form and double click button and add this code . i am using green because thats my favourite color and you can just add any color to it simply change the (button1,color.lightgreen,color.green) and your done .

Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
        shimscustombuttonfunction(Button1, Color.LightGreen, Color.Green)
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
        Button1.BackgroundImage = Nothing
    End Sub
so finally the custom button will work like this


i have just added two events mouse enter and mouse leave and you can add many more events like mouse click,mouse down,mouse up,mouse hover and mouse move

here is the full source code
'Author : Mohamed Shimran
'Blog : http://ultimateprogrammingtutorials.blogspot.com
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Public Sub shimscustombuttonfunction(ByVal aControl As Control, ByVal Color1 As Color, ByVal Color2 As Color, _
        Optional ByVal mode As System.Drawing.Drawing2D.LinearGradientMode = Drawing2D.LinearGradientMode.Vertical)

        Dim bmp As New Bitmap(aControl.Width, aControl.Height)
        Dim g As Graphics = Graphics.FromImage(bmp)
        Dim Rect1 As New RectangleF(0, 0, aControl.Width, aControl.Height)

        Dim lineGBrush As New System.Drawing.Drawing2D.LinearGradientBrush(Rect1, Color1, Color2, mode)
        g.FillRectangle(lineGBrush, Rect1)

        aControl.BackgroundImage = bmp
        g.Dispose()
    End Sub


    Private Sub Button1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseEnter
        shimscustombuttonfunction(Button1, Color.LightGreen, Color.Green)
    End Sub

    Private Sub Button1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.MouseLeave
        Button1.BackgroundImage = Nothing
    End Sub
End Class

happy coding !!!!!

How To Enable/Disable IE Proxy By Using VBS


Today you gonna learn a easy method to enable/disable IE proxy by using a vbs script so lets get started just open notepad and paste this code

How To Make A Text Editor In C#

Hello,

Ive made a little program like notepad in C#. It's called XText.



XText uses a Richtextbox with and uses the standard functions to complete actions like undo, redo, etc.
But it also uses things like Search and Justify. These functions are not standard built in the Richtextbox so you need the program them by yourself.
Now take a look at the source code and see how it all works.

You can download the source code in the description of the video.

How To Make WaterFX Effect In VB.NET

Hey, today I'm gonna show you a code for a WaterFX.
Ok, to start it off. Create a New Project
Then, Create a new Class.
Enter the codes below into your Class.


How To Create A Updater In VB.NET


Needed:
1x a ProgressBar
2x a Label

start a new form:

How To Make Twitter Login Form In VB.NET


[VB.NET] Twitter Login Form


It is hard figuring out how to make a login app for a website when there is no “ID” attribute on the HTML code. Unlike facebook, which has an “ID” it is easy because it tells you right of the bat. Twitter on the other hand has no ID attribute for the username password or submit button. So I made this tut on how to login to twitter using TAGNAME instead.


Let’s start of by making a new project. Since this is just an example we will name it “TwitterLoginEX”. Once your new project is loaded go to the toolbox and add the following:


2 textboxes
1 button
1 webbrowser

Rename textbox 1 to “USERBOX” and textbox 2 to “PASSBOX” so it will be easier to remember which is which.

Now double click on the form to enter the form load event and put this code:

WebBrowser1.Navigate("https://mobile.twitter.com/session/new")
WebBrowser1.ScriptErrorsSuppressed = True


How To Make A File Searcher And Display Results In A Listbox

Today I will teach you how to display files from your computer in a listbox. The code is very simple and is for beginners so lets get started! First open visual basic 2008 / 2010.
1. Create / open a project.

2. Add a Button and give it the text: "Search".

3. Also add a Textbox and a Listbox.

4. Now double click on the Button and type or copy the following code:
For Each File In My.Computer.FileSystem.GetFiles(My.Computer.FileSystem.SpecialDirectories.Desktop,
FileIO.SearchOption.SearchAllSubDirectories, Nothing)
              Dim foundFile As String =
              My.Computer.FileSystem.GetFileInfo(File).Name
              If foundFile.Contains(TextBox1.Text) Then
                      ListBox1.Items.Add(foundFile)
              End If
      Next

How To Make A Stopwatch In VB.NET

Today i am going to teach you how to make a stopwatch in visual basic 2008/ visual basic 2010 the features are start, stop, mark and reset this is not a advanced stopwatch, but this has the basic features of a stopwatch probably this is for beginners so lets get started with opening your visual basic 2008 / visual basic 2010

1 . Create a new project
2 . Add a label, 4 buttons, 1 listbox and a timer
3 . Go to timer properties and change timer interval to 1 
4 . I recommend you to arrange your tools like this

5 . Time for coding double click form and add all these codes
Public Class Form1

    'Author : Mohamed Shimran
    'Blog : http://www.ultimateprogrammingtutorials.blogspot.com

    Dim StopWatch As New Diagnostics.Stopwatch
    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Dim elapsed As TimeSpan = Me.StopWatch.Elapsed
        Label1.Text = String.Format("{0:00}:{1:00}:{2:00}:{3:00}", Math.Floor(elapsed.TotalHours), elapsed.Minutes, elapsed.Seconds, elapsed.Milliseconds)
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Timer1.Start()
        Me.StopWatch.Start()
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Timer1.Stop()
        Me.StopWatch.Stop()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Me.StopWatch.Reset()
        Label1.Text = "00:00:00:000"
        ListBox1.Items.Clear()
    End Sub

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
      ListBox1.Items.Add(Label1.Text)
    End Sub
End Class  
6 . Now debug the program and the program would work like this


Hope you enjoyed the tutorial.