Friday, April 30, 2010

Textbox - Select All (Ctrl+A) and Scroll Visual Basic {VB.net}

Hi all today i will be showing u all how to select all text in a textbox and also how to make a ur text scroll in the textbox

Here are all the codes:

Alright so first of all, u insert one textbox in your form and then u go into the events and choose Keypress event of the textbox and in the code u type in:

Codes:

Public Class Form1

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = Convert.ToChar(1) Then
DirectCast(sender, TextBox).SelectAll()
e.Handled = True
End If
End Sub

End Class
_________________________________________________________________________
Here is the video tutorial:

Run Program on Windows Startup Tutorial Visual Basic {VB.net}

Hi all, today i will be teaching u all how to add and read value from registry in vb.net (visual basic 2008)

Codes:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim regKey As Microsoft.Win32.RegistryKey
Dim KeyName As String = "Test"
Dim KeyValue As String = "C:\test\test.exe"
regKey=Microsoft.Win32.Registry.LocalMachine.OpenSubKey("Software\Microsoft\Window\CurrentVersion\Run", True)
If regKey.GetValue(KeyName) = Nothing Then
MsgBox("No value found")
regKey.SetValue(KeyName, KeyValue, Microsoft.Win32.RegistryValueKind.String)
MsgBox("keyValue " & KeyName & " has been created")
Else
MsgBox("This Program already exists", vbInformation, "Information")
End If
End Sub

End Class

_________________________________________________________________________

Here is the video tutorial:

Thursday, April 29, 2010

Email Validation Entered Into Textbox Tutorial Visual Basic {VB.net}

Hi all once again, today i will be teaching u all how to validate the email entered into a text box or label to be in correct email format. We will be using Regex to make email validation.

{Note: Remember to rename the "Name" of the textbox1 to "email" or it won't work and please check all the names of the labels from the video tutorial or alter it according to your project.}

Codes:

'General Declarations
Imports System.Text.RegularExpressions
____________________________________________________________________

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim FoundMatch As Boolean
Try
FoundMatch = Regex.IsMatch(email.Text, "\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z", RegexOptions.IgnoreCase)
Catch ex As ArgumentException 'Syntax error in the regular expression
End Try
If Not FoundMatch Then
Label2.Text=("Not a Valid Email Address")
Else
Label2.Text("Valid Email Address")
End If
End Sub

End Class
_________________________________________________________________________

Here is the video tutorial:

Visual Basic Send Email - Smtp Tutorial - {VB.net}

Hello and welcome to another quick VB.net tutorial, today in this tutorial i will be showing u all how to make a VB.net program that sends an email using SMTP client.



Codes:

Imports System.Net.Mail
____________________________________________________________________
Public Class Form1

Private Sub btn_submit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_submit.Click
If TB_Name.Text = "" Or TB_Subject.Text = "" Or TB_Cmt.Text = "" Then
MsgBox("Name, Subject and Comment are required fields", vbCritical, "Error") 'This code here test if there is no text in the textbox and if there is no text, it will give an error msgbox and wont progress through the rest of the steps until the user inputs some data in all textboxes.

Else

Try
Dim Mail As New MailMessage 'This code declares a new MailMessage
Mail.From = New MailAddress("mrvbdude2@gmail") 'This is u, who is sending the message to someone else on gmail.
Mail.To.Add("mrvbdude2@gmail.com") 'This is the person u are sending the message to, u should use gmail address here..!
Mail.Subject = TB_Subject.Text & " - " & TB_Name.Text 'Subject of the MailMessage
Mail.Body = TB_Cmt.Text 'Body of the MailMessage
Dim smtp As New SmtpClient("smtp.gmail.com") 'Declares new SMTPCLIENT
smtp.Port = 587 ' SMTP port no.
smtp.EnableSsl = True
smtp.Credentials = New System.Net.NetworkCredential("YOUR GMAIL USERNAME ID HERE", "YOUR GMAIL PASSWORD HERE") 'ur gmail login information
smtp.Send(Mail) 'sends the message u created
MsgBox("Sent Successfully", vbInformation, "Thank you") 'confirmation - message has been send successfully
Catch ex As Exception 'Just incase program runs into error
MsgBox("There was an error, the program will close now!!", vbCritical, "Fatal error")
End Try
End If
End Sub

End Class
_________________________________________________________________________
Here is the video tutorial:

Wednesday, April 28, 2010

How to make form move Borderless (No Title Bar) Visual Basic {VB.net}

Hi all, Today i will be showing u all how to make your vb.net form move without any borders (title bar), so lets begin..!

Codes:

Public Class Form1

#Region " Global Variables "
Dim Point As New System.Drawing.Point()
Dim X, Y As Integer
#End Region

#Region " GUI "
Private Sub Form_MouseMove(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseMove
If e.Button = MouseButtons.Left Then
Point = Control.MousePosition
Point.X = Point.X - (X)
Point.Y = Point.Y - (Y)
Me.Location = Point
End If
End Sub

Private Sub Form_MouseDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles MyBase.MouseDown
X = Control.MousePosition.X - Me.Location.X
Y = Control.MousePosition.Y - Me.Location.Y
End Sub
#End Region

End Class
_________________________________________________________________________
2. Minimize Box: Add one PictureBox component and choose get the image of minimize button from internet and choose that image. Now double click that image and type in the following code.

Minimize Box:
WindowState = FormWindowState.Minimized

--------------------------------------------------
Close box:
me.close
_________________________________________________________________________

Here is the video tutorial:

Thursday, April 22, 2010

Listbox Tutorial - Add, Remove Item, Save, Reload List Visual Basic {VB.net}

Listbox Tutorial - Source Code

Codes:

Public Class Form1

Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
lb1.Items.Add(tb1.Text)
lb1.SelectedIndex = lb1.SelectedIndex + 1
End Sub

Private Sub cmdRem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRem.Click
lb1.Items.Remove(lb1.SelectedItem)
End Sub

Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
IO.Directory.CreateDirectory("C:\Test")
Dim w As New IO.StreamWriter("C:\Test\test.txt")
Dim i As Integer
For i = 0 To lb1.Items.Count - 1
w.WriteLine(lb1.Items.Item(i))
Next
w.Close()
End Sub

Private Sub cmdLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoad.Click
Dim r As New IO.StreamReader("C:\Test\test.txt")
While (r.Peek() > -1)
lb1.Items.Add(r.ReadLine)
End While
r.Close()
End Sub

End Class
_________________________________________________________________________

Here is the video tutorial: