Pages

Total Pageviews

Add This

Showing posts with label TextBox. Show all posts
Showing posts with label TextBox. Show all posts

Tuesday, June 28, 2011

Textbox Tutorial in Visual Basic 2008

It is a complete TextBox tutorial in Visual Basic 2008 but can be used in Visual Basic 2010.

Tuesday, June 21, 2011

Write TextBox to Text File

If you want to save the text written in a TextBox using Visual Basic 2010 in a Button write the code bellow:

        Dim write As New System.IO.StreamWriter("Messages.txt")
        write.Write(TextBox1.Text)
        write.Close()

Monday, June 20, 2011

Read a Text File in TextBox

If you want to create a notepad you have to know how to read already written text file. To do this task use the code bellow:

        Dim read As New System.IO.StreamReader("Test.txt")
        TextBox1.Text = read.ReadToEnd
        read.Close()

Monday, June 6, 2011

Display the content of the TextBox

To display the content of the TextBox to MsgBox create a button and write the code bellow:

 MessageBox.Show(txtInput.Text, "Display")

 

Sunday, May 15, 2011

Calculate the Line Length in TextBox

Calculating the line length in textbox while you write is very easy. You have to put this code into the textbox event textchanged. To do not make mistakes i give you the code with the event.


    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged
        For Each line As String In TextBox1.Lines
            Label1.Text = line.Length
        Next
    End Sub

Open File Title in TextBox

If you want to enter the file title in TextBox using visual basic 2010 in one button write the code bellow:



       Dim dialog As OpenFileDialog = New OpenFileDialog()
        dialog.Title = "Test File Dialog"
        dialog.InitialDirectory = "D:\Users\Admin\Desktop"
        dialog.Filter = "All files (*.*)|*.*|All files (*.*)|*.*"
        dialog.FilterIndex = 2
        dialog.RestoreDirectory = True
        If dialog.ShowDialog() = DialogResult.OK Then
            TextBox1.Text = dialog.FileName
        End If

Friday, May 13, 2011

Clear data from all TextBoxes in the Form

If you want to clear the data from all textboxes in the form just with one click, in one button enter the code bellow:



Dim tbox As Control
For Each tbox In Me.Controls
    If TypeOf tbox Is TextBox Then
        tbox.Text = Nothing
    End If
Next

Sunday, May 8, 2011

Read the Date from DateTimePicker Control


TextBox1.Text = DateTimePicker1.Value.Date

Change Font in TextBox using FontDialog

Write the code bellow:



FontDialog1.ShowDialog()
TextBox1.Font = FontDialog1.Font

Get Text from Clipboard

Write the code bellow:



If My.Computer.Clipboard.ContainsText Then
TextBox1.Text = My.Computer.Clipboard.GetText
End If

Just numbers in TextBox

If you want your TextBox to allow just numbers enter the code bellow:    


Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox2.KeyPress
        If Asc(e.KeyChar) <> 13 AndAlso Asc(e.KeyChar) <> 8 AndAlso Not IsNumeric(e.KeyChar) Then
            MessageBox.Show("Only numbers allowed")
            e.Handled = True
        End If
    End Sub

Replace specific text in TextBox

If you have to textboxes, and TextBox1 is filled with the sentence "I am the smartest man in the world" and you want the word "smartest" to change with the word written  in textbox2 you have to write the code bellow:

        If TextBox1.Text.Contains("smartest") Then
            TextBox1.Text = TextBox1.Text.Replace("smartest", TextBox2.Text)
        End If

Take value from one TextBox to another

If you want to text a value from one textbox to another you have to write the code bellow:

TextBox2.Text = TextBox1.Text