Monday, 9 January 2012

ProgressBar with Timer Control


Insert Timer Control into the project. Its default name is Timer1.

Private Sub btnTimer_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnTimer.Click
        If btnTimer.Text = "START" Then
            Timer1.Start()
            btnTimer.Text = "STOP"
        Else
            Timer1.Stop()
            btnTimer.Text = "START"
        End If
    End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        ProgressBar1.Value += 1
        If ProgressBar1.Value = ProgressBar1.Maximum Then
            Timer1.Stop()
            btnTimer.Text = "START"
        End If
    End Sub


Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ProgressBar1.Value = 0
    End Sub


Sunday, 8 January 2012

Cut / Copy Selected Text from Richtextbox And Paste into RichtextBox


Private Sub btnCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCut.Click
        If RichTextBox1.SelectedText <> "" Then
            'Copy the information to the clipboard
            Clipboard.SetText(RichTextBox1.SelectedText)
'Replace SelectedText with Null Value
            RichTextBox1.SelectedText = ""
        Else
            'If no text was selected, print out an error message box
            MsgBox("No text is selected to Cut")
        End If
    End Sub

Private Sub btnCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCopy.Click
        'Checks to see if the user selected anything
        If RichTextBox1.SelectedText <> "" Then
            'Copy the information to the clipboard
            Clipboard.SetText(RichTextBox1.SelectedText)
        Else
            'If no text was selected, print out an error message box
            MsgBox("No text is selected to copy")
        End If
    End Sub

Private Sub btnPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPaste.Click
        'Get the data stored in the clipboard
        Dim iData As IDataObject = Clipboard.GetDataObject()
        'Check to see if the data is in a text format
        If iData.GetDataPresent(DataFormats.Text) Then
            'If it's text, then paste it into the textbox
            RichTextBox1.SelectedText = CType(iData.GetData(DataFormats.Text), String)
        Else
            'If it's not text, print a warning message
            MsgBox("Data in the clipboard is not availble for entry into a textbox")
        End If
    End Sub


Private Sub Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Clear.Click
        Clipboard.Clear()
        MsgBox("Data in the clipboard is Cleared")
    End Sub