hello Wonder if anyone can help. I am in the process of putting together a Tabbed NotePad and When I try to do the Save File I get the following Errors :
The name 'FileSystem' does not exist in the current context
The name 'OpenMode' does not exist in the current context
This is the code I am trying to use to save information from a Richtext Box.
SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
SaveFileDialog1.Filter = "Rich Text Files|*.rtf|Text Files|*.txt";
SaveFileDialog1.ShowDialog();
FileSystem.FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output);
FileSystem.PrintLine(1, ((RichTextBox)tabControl1.SelectedTab.Controls.item(0)).Text);
FileSystem.FileClose(1);
What am I doing wrong.. Below is the code for the whole program
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string strTitle = "NotePad";
public void SaveFile(string FileName)
{
}
private void Form1_Load(object sender, EventArgs e)
{
//This is the main Form Load routine
this.Text = strTitle;
NewTab(); // This runs the routine to create a new text tab when the program starts up
}
private RichTextBox GetRichTextBox()
{
RichTextBox rtb = null;
TabPage tp = tabControl1.SelectedTab;
if (tp != null) //If a tab is selected
{
rtb = tp.Controls[0] as RichTextBox;
}
return rtb;
}
public void NewTab()
{
if (tabControl1.TabPages.Count != 100) // Count the amount of Tabs
{
this.Text = "Untitled - " + strTitle;
// This Subroutine will create a new Tab and RichTextBox
TabPage tp = new TabPage("untitled.txt");
tp.Tag = "Untitled";
RichTextBox rtb = new RichTextBox();
rtb.Dock = DockStyle.Fill;
tp.Controls.Add(rtb);
tabControl1.TabPages.Add(tp);
}
else
{
MessageBox.Show("You have reached the limit on tabs.");
}
}
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
NewTab();
}
private void newToolStripButton_Click(object sender, EventArgs e)
{
NewTab();
}
private void cutToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Cut();
}
private void copyToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Copy();
}
private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Paste();
}
private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().SelectAll();
}
private void undoToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Undo();
}
private void cutToolStripButton_Click(object sender, EventArgs e)
{
GetRichTextBox().Cut();
}
private void copyToolStripButton_Click(object sender, EventArgs e)
{
GetRichTextBox().Copy();
}
private void pasteToolStripButton_Click(object sender, EventArgs e)
{
GetRichTextBox().Paste();
}
private void closeTabToolStripMenuItem_Click(object sender, EventArgs e)
{
int index = tabControl1.TabIndex;
tabControl1.TabPages.RemoveAt(index);
}
private void redoToolStripMenuItem_Click(object sender, EventArgs e)
{
GetRichTextBox().Redo();
}
private void openToolStripButton_Click(object sender, EventArgs e)
{
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
SaveFileDialog SaveFileDialog1 = new SaveFileDialog();
SaveFileDialog1.Filter = "Rich Text Files|*.rtf|Text Files|*.txt";
SaveFileDialog1.ShowDialog();
FileSystem.FileOpen(1, SaveFileDialog1.FileName, OpenMode.Output);
FileSystem.PrintLine(1, ((RichTextBox)tabControl1.SelectedTab.Controls.item(0)).Text);
FileSystem.FileClose(1);
}
private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
}
}
}
Loading
FroglegPosted Feb 9, 2012, 7:15 PM
In the blank menu, I forgot to put code in to stop if no saved setting
should be
private void bttnLastSave1_Click(object sender, EventArgs e)
{
if (string.IsNullOrEmpty(Properties.Settings.Default.lastSave1))
{
return;
}
enableSave(true);// enable save buttons
NewTab(false, Properties.Settings.Default.lastSave1);//create new tabpage and richtextbox
rtb.LoadFile(Properties.Settings.Default.lastSave1);
}
If you need help with printing - start a new post
My name 0Posted Feb 9, 2012, 3:53 PM
My name 0Posted Feb 9, 2012, 3:44 PM
Just out of interest what is the reason for this
If I click on a blank menu option under file then I get this error.
Empty Path name is not legal.
FroglegPosted Feb 9, 2012, 3:52 AM
See what you think
My name 0Posted Feb 8, 2012, 4:06 PM
I have attached the code
FroglegPosted Feb 8, 2012, 4:29 AM
The save file will be the name of the richtextbox
ie
rtb.SaveFile("myfile.rtf");
So whatever you call your richtextbox, just add .SaveFile("myfile.rtf");
If you have more trouble - upload your whole project so I can run through it - I don't tend to read long code questions for the reason
A: It's easier to read in the ide(code window)
B: I can debug your code
As a side note
I would suggest investing in a tutorial book to help you with the basics of C# programming
My name 0Posted Feb 8, 2012, 3:14 AM
FroglegPosted Feb 8, 2012, 2:24 AM
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
textBox1.Text = openFileDialog1.FileName;
}
if (saveFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//do whatever
}
Richtextbox has a load feature:
richTextBox1.LoadFile(openFileDialog1.FileName);
and save feature:
RichTextBox1.SaveFile(saveFileDialog1.FileName);