how can i save text in a textbox?
if i want to save Rich Text Box i use following code
// Create an SaveFileDialog object:
SaveFileDialog saveFile1 = new SaveFileDialog();
// Initialize the SaveFileDialog to look for text files:
saveFile1.Filter = "Text Files|*.txt";
// Check if the user selected a file from the SaveFileDialog:
if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
// Load the contents of the file into a RichTextBox control:
richTextBox1.LoadFile(saveFile1.FileName,
RichTextBoxStreamType.PlainText);1.how to save text in text boxes?2.how to save text text box, combo box ?3 how can save combobox,textbox with their text in panel?
[664 byte] By [
Febin] at [2007-12-23]
1.how to save text in text boxes?
A1) how exactly do you mean? you wish to save the text from textboxes to a file or do you mean read a file and set the content to the textbox?
If you want to save from textbox to file
| |
Dim theStreamWriter as new StreamWriter(filename) theStreamWriter.Write(Me.theTextBox.Text) theStreamWriter.Close()
|
2.how to save text text box, combo box ?
Same method as above except for a combo box you have to loop through each item and write to file:
| |
Dim theStreamWriter as new StreamWriter(filename) for each curItem as string in Me.theComboBox.Items theStreamWriter.WriteLine(curItem) next theStreamWriter.Close()
|
Now looking at this code:
if i want to save Rich Text Box i use following code
// Create an SaveFileDialog object:SaveFileDialog saveFile1 = new SaveFileDialog();
// Initialize the SaveFileDialog to look for text files:
saveFile1.Filter = "Text Files|*.txt";
// Check if the user selected a file from the SaveFileDialog:
if(saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
// Load the contents of the file into a RichTextBox control:
richTextBox1.LoadFile(saveFile1.FileName,
RichTextBoxStreamType.PlainText);
You are not saving anything but loading....
If you want to save the text from the RichTextBox:
| |
if saveFile.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Me.theRichTextBox.SaveFile(saveFile.FileName) end if
|
does this help?
1. Save Text in Textboxes (save text in a textbox to a file)
My.Computer.Filesystem.WriteAllText( "foo.txt", Textbox1.text, False)
2. Save All Items In a Combobox Items to a file.
Dim STotal as string = ""
For Each s as string in Combobox1.Items
STotal = STotal & s & vbCRLF
Next
My.Computer.Filesystem.WriteAllText( "foo.txt", STotal, False)
3. Select all the currently selected text from Textboxes and Comboboxes in a panel to a file
Dim s As String
For Each c As Control In Me.Panel1.Controls
If TypeOf (c) Is TextBox Or TypeOf (c) Is ComboBox Then
s = s & c.Text & vbCr
End If
Next
My.Computer.Filesystem.WriteAllText( "foo.txt", s, False)