Tuesday, June 18, 2013

Create your own download manager by VB.net


Imports System.Net

Public Class Form1
    
Public WithEvents Download As New WebClient
    
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        FolderBrowserDialog1.ShowDialog()
        LbSaveAddress.Text = FolderBrowserDialog1.SelectedPath
        Download = New WebClient
        Download.DownloadFileAsync(New Uri(txtURL.Text), LbSaveAddress.Text + "\" + txtSaveFileName.Text)

    End Sub

    Private Sub Download_DownloadProgressChanged(ByVal sender As Object, ByVal e As System.Net.DownloadProgressChangedEventArgs) Handles Download.DownloadProgressChanged
        Button1.Text = "Downloading"
        ProgressBar1.Value = e.ProgressPercentage
        Label2.Text = e.ProgressPercentage & "%"
    End Sub

    Private Sub txtURL_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles txtURL.MouseDown
        txtSaveFileName.Text = "Default.exe"
    End Sub
End Class


Monday, June 17, 2013

Create Easy Print by VB.net




Public Class FrmEasyPrint

    Private Sub cmdFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdFont.Click
        Dim font_dialog As New FontDialog
        If font_dialog.ShowDialog() = DialogResult.OK Then
            TextBox1.Font = font_dialog.Font
        End If
    End Sub

    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
        If PrintDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
            PrintDocument1.Print()
        End If
    End Sub

    Private Sub cmdPrintPreview_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrintPreview.Click
        PrintPreviewDialog1.Document = PrintDocument1
        PrintPreviewDialog1.ShowDialog()
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim FontText As Font
        FontText = TextBox1.Font
        e.Graphics.DrawString(TextBox1.Text, FontText, New SolidBrush(Color.Black), 10, 10)
    End Sub
End Class

Create your own Email sending by VB.net



Imports System.Net.Mail
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim EmailMessage As New MailMessage()
        Try
            EmailMessage.From = New MailAddress(txtFrom.Text)
            EmailMessage.To.Add(txtTo.Text)
            EmailMessage.Subject = txtSub.Text
            EmailMessage.Body = txtMessage.Text
            Dim SMTP As New SmtpClient("smtp.gmail.com")
            SMTP.Port = 587
            SMTP.EnableSsl = True
            SMTP.Credentials = New System.Net.NetworkCredential(txtFrom.Text, "YourEmailPassword")
            SMTP.Send(EmailMessage)
            MsgBox("Message has been send to," & txtTo.Text & " Successfully!")
        Catch ex As Exception
            MsgBox("Sending Fail")
        End Try
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        txtFrom.Text = "YourEmail"
    End Sub
End Class

Create Notepad by VB.net



Public Class Form1

    Private Sub NewToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NewToolStripMenuItem.Click
        RichTextBox1.Clear()
    End Sub

    Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
        Try
            Dim dlg As OpenFileDialog = New OpenFileDialog
            dlg.Title = "Open"
            dlg.Filter = "Rich Text Files (*.rtf)|*.rtf"
            If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
                RichTextBox1.LoadFile(dlg.FileName)
            End If
        Catch ex As Exception
            MsgBox("Open File Error")
        End Try
    End Sub

    Private Sub SaveToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SaveToolStripMenuItem.Click
        Try
            Dim dlg As SaveFileDialog = New SaveFileDialog
            dlg.Title = "Save"
            dlg.Filter = "Rich Text Files (*.rtf)|*.rtf"
            If dlg.ShowDialog() = Windows.Forms.DialogResult.OK Then
                RichTextBox1.SaveFile(dlg.FileName, RichTextBoxStreamType.RichText)
            End If
        Catch ex As Exception
            MsgBox("Error to save file!")
        End Try
    End Sub

    Private Sub UndoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UndoToolStripMenuItem.Click
        RichTextBox1.Undo()
    End Sub

    Private Sub RedoToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RedoToolStripMenuItem.Click
        RichTextBox1.Redo()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CutToolStripMenuItem.Click
        RichTextBox1.Cut()
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CopyToolStripMenuItem.Click
        RichTextBox1.Copy()
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PasteToolStripMenuItem.Click
        RichTextBox1.Paste()
    End Sub

    Private Sub ClearToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearToolStripMenuItem.Click
        RichTextBox1.Clear()
    End Sub

    Private Sub SelectAllToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SelectAllToolStripMenuItem.Click
        RichTextBox1.SelectAll()
    End Sub

    Private Sub FontToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FontToolStripMenuItem.Click
        Try
            Dim dlg As FontDialog = New FontDialog
            dlg.Font = RichTextBox1.Font
            If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                RichTextBox1.Font = dlg.Font
            End If
        Catch ex As Exception
            MsgBox("Erro Font")
        End Try
    End Sub

    Private Sub ColourToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ColourToolStripMenuItem.Click
        Try
            Dim dlg As ColorDialog = New ColorDialog
            dlg.Color = RichTextBox1.ForeColor
            If dlg.ShowDialog = Windows.Forms.DialogResult.OK Then
                RichTextBox1.ForeColor = dlg.Color
            End If
        Catch ex As Exception
            MsgBox("Erro Color")
        End Try
    End Sub
End Class

Event sharing IT experiences


Register: https://www.facebook.com/events/144561725733472/?ref=2
Website: http://www.cita.asia/en/

Monday, June 3, 2013

Create Void Recorder with vb.net



Public Class Form1
    Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstyCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hwndCallback As Integer) As Integer
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1000
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Label3.Text = "0.0"
        Button1.Enabled = False
        Button2.Enabled = True
        mciSendString("open new Type waveaudio Alias recsound", "", 0, 0)
        mciSendString("record recsound", "", 0, 0)
        Timer1.Enabled = True
        Label1.Text = "កំពុងថតសម្លេង...!"
        Label1.Visible = True
        Label2.Text = "File Location: "
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Button1.Enabled = True
        Button2.Enabled = False

        Label1.Text = "ការថតថម្លេងបានបញ្ចប់"
        SaveFileDialog1.Title = "Save File Audio"
        SaveFileDialog1.FileName = ""
        SaveFileDialog1.Filter = "File MP3|*.mp3|File Wave|*.wav"
        SaveFileDialog1.FilterIndex = 2
        SaveFileDialog1.OverwritePrompt = True
        SaveFileDialog1.ShowDialog()

        mciSendString("save recsound " & SaveFileDialog1.FileName & "", "", 0, 0)
        mciSendString("close recsound", "", 0, 0)
        Timer1.Enabled = False
        MsgBox("File Created: " & SaveFileDialog1.FileName & "", MsgBoxStyle.OkOnly, "Success")
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label3.Text += 0.01
    End Sub

    Private Sub AxWindowsMediaPlayer1_ClickEvent(ByVal sender As Object, ByVal e As AxWMPLib._WMPOCXEvents_ClickEvent) Handles AxWindowsMediaPlayer1.ClickEvent
        AxWindowsMediaPlayer1.URL = SaveFileDialog1.FileName
        AxWindowsMediaPlayer1.Ctlcontrols.play()
        Label2.Text += SaveFileDialog1.FileName
        Label1.Text = "កំពុងតែចាក់ស្តាប់"
    End Sub
End Class

Sunday, June 2, 2013

Create you own shutdown management control system


Public Class Form2
    Dim i, j As Integer
    Dim TM As Date
    Private Declare Function LockWorkStation Lib "user32.dll" () As Long
    Private Declare Function ShutDownDialog Lib "shell32.all" Alias "#60" (ByVal any As Long)

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Me.Text = "Shutdown Manager - " + TimeOfDay
        Me.Label3.Text = "ពេលវេលាបច្ចុប្បន្ន៖ " + TimeOfDay
    End Sub

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer2.Interval = 10000
        Timer1.Enabled = True

        For Me.i = 0 To 23 Step 1
            cboHourse.Items.Add(i)
        Next

        For Me.j = 0 To 60 Step 1
            cboMinutes.Items.Add(j)
        Next
    End Sub

    Private Sub cmdStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdStart.Click
        cmdStart.Text = "កំពុងដំណើរការ"
        If Val(cboHourse.Text) > 0 Or Val(cboMinutes.Text) > 0 Then
            TM = Now.AddMinutes(Val(cboHourse.Text) * 60 + Val(cboMinutes.Text))
            Timer2.Enabled = True
            lblStatuse.Text = "កំណត់ពេលវេលាគឺ៖ " + TM

        Else
            lblStatuse.Text = "សូមបញ្ចូលពេលវេលាជាមុន"
        End If
    End Sub

    Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
        If Now > TM Then
            If RdoLogOff.Checked = True Then
                Shell("shutdown -l")
            End If

            If RdoRestart.Checked = True Then
                Shell("shutdown -r")
            End If

            If RdoShutDown.Checked = True Then
                Shell("shutdown -s")
            End If

            If RdoLockPC.Checked = True Then
                LockWorkStation()
            End If

            If RdoHybernate.Checked = True Then
                Shell("shutdown -h")
            End If

            Timer1.Enabled = False
            Timer2.Enabled = False
        End If
    End Sub

    Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
        cmdStart.Text = "Start"
        Timer2.Enabled = False
        lblStatuse.Text = "ប្រព័ន្ធអាចចាប់ផ្តើមជាថ្មីបាន!"
    End Sub

    Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
        End
    End Sub
End Class

Saturday, June 1, 2013

Create Stop Watch with Vb.net

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If Button1.Text = "ចាប់ផ្តើម" Then
            Timer1.Enabled = True
            Button1.Text = "ផ្អាក"
            Button3.Enabled = False
        Else
            Button1.Text = "ផ្អាក"
            Timer1.Enabled = False
            Button1.Text = "ចាប់ផ្តើម"
            Button3.Enabled = True
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Timer1.Interval = 1
        Button1.Text = "ចាប់ផ្តើម"
        Button3.Text = "សារដើម"
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Timer1.Enabled = False
        Label1.Text = "0.0"
    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = Label1.Text + 0.01
    End Sub
End Class