NOW, it's time to be able to add a "Save As" menu item. Here's how you do it:
A) goto your "Toolbox" at the left scroll down and find the "SAVEFILEDIALOG". drag it onto to the space at the bottom fo your form, the one that already has your menustrip and your OpenFileDialog. No need to rename this control, just leave it as SaveFileDialog1
B) In your form, if you click once on the FILE menu header, you will see the whole list of menu items you've got
C) at the bottom, you will see a thing that says "Type Here" that's where you type in "SAVE AS".
D) Very carefully drag that item up above the EXIT and below the SAVE -- not that it really matters, but wouldn't it just bug the crap out of you if we left it there?
E) doubleclick on that menu item to get into its code, and then add this code block:
'this just gives a title to the dialog box
SaveFileDialog1.Title = "Save a Text File As......."
'this says what kind of file will be saved
SaveFileDialog1.Filter = "Text Files*.txt"
'this establishes that we are naming this thing the way it
'was until we decide to name it something else
SaveFileDialog1.FileName = theFileName
'this opens the SaveDialog, so you can save the file with its new name
SaveFileDialog1.ShowDialog( )
'when you change the name of the file,
'this changes the value of the variable
'that way, the StreamWriter writes to the new file
'not the original
theFileName = SaveFileDialog1.FileName
Cheers,
Mr. L
PS There's something missing at the end of this code. Try to guess what you might need to

No comments:
Post a Comment