Stupid error's! (original) (raw)
I am writing a simple text editer but the thing is it wont compile when I add support for opening the file from the command line, the code for it was taken from "Beginning C#" by Karli Watson (Wrox Press). I get three errors!
"formmain.cs(73,5): error CS0117: 'Text_Edit.formMain' does not contain a definition for 'fileName'"
"formmain.cs(492,48): error CS0103: The name 'fileName' does not exist in the class or namespace 'Text_Edit.formMain'"
"formmain.cs(492,5): error CS0029: Cannot implicitly convert type '' to 'System.IDisposable'"
Doesnt having 'string fileName' in the arguments of the function define it? (im used to C++), the third one I don't understand at all!
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
namespace Text_Edit
{
///
/// Summary description for Form1.
///
public class formMain : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu menuMain;
private System.Windows.Forms.MenuItem menuFile;
private System.Windows.Forms.MenuItem menuFileNew;
private System.Windows.Forms.MenuItem menuFileOpen;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItem17;
private System.Windows.Forms.MenuItem menuItem22;
private System.Windows.Forms.MenuItem menuItem29;
private System.Windows.Forms.MenuItem menuFileSave;
private System.Windows.Forms.MenuItem menuFileSaveas;
private System.Windows.Forms.MenuItem menuFileSaveall;
private System.Windows.Forms.MenuItem menuFileClose;
private System.Windows.Forms.MenuItem menuFilePagesetup;
private System.Windows.Forms.MenuItem menuFilePrint;
private System.Windows.Forms.MenuItem menuFileExit;
private System.Windows.Forms.MenuItem menuEdit;
private System.Windows.Forms.MenuItem menuEditCut;
private System.Windows.Forms.MenuItem menuEditCopy;
private System.Windows.Forms.MenuItem menuEditPaste;
private System.Windows.Forms.MenuItem menuEditFind;
private System.Windows.Forms.MenuItem menuEditFindnext;
private System.Windows.Forms.MenuItem menuEditReplace;
private System.Windows.Forms.MenuItem menuEditReplaceall;
private System.Windows.Forms.MenuItem menuEditSelectall;
private System.Windows.Forms.MenuItem menuEditTimedate;
private System.Windows.Forms.MenuItem menuTools;
private System.Windows.Forms.MenuItem menuHelp;
private System.Windows.Forms.MenuItem menuHelpHelpindex;
private System.Windows.Forms.MenuItem menuHelpWebsite;
private System.Windows.Forms.MenuItem menuHelpAbout;
private System.Windows.Forms.ToolBar toolbarMain;
private System.Windows.Forms.StatusBar statusbarMain;
private System.Windows.Forms.ImageList imageList;
private System.Windows.Forms.ToolBarButton toolBarButtonNew;
private System.Windows.Forms.ToolBarButton toolBarButtonOpen;
private System.Windows.Forms.ToolBarButton toolBarButtonSave;
private System.Windows.Forms.ToolBarButton toolBarButtonSep1;
private System.Windows.Forms.ToolBarButton toolBarButtonPrintSetup;
private System.Windows.Forms.ToolBarButton toolBarSaveAll;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.RichTextBox richTextBox1;
private System.Windows.Forms.ToolBarButton toolBarButtonPrint;
private System.Windows.Forms.ToolBarButton toolBarButtonSep2;
private System.ComponentModel.IContainer components;
public formMain(string fileName)
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
if (fileName != null)
{
this.fileName = fileName;
OpenFile();
}
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(formMain));
this.menuMain = new System.Windows.Forms.MainMenu();
this.menuFile = new System.Windows.Forms.MenuItem();
this.menuFileNew = new System.Windows.Forms.MenuItem();
this.menuFileOpen = new System.Windows.Forms.MenuItem();
this.menuFileSave = new System.Windows.Forms.MenuItem();
this.menuFileSaveas = new System.Windows.Forms.MenuItem();
this.menuFileSaveall = new System.Windows.Forms.MenuItem();
this.menuFileClose = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuFilePagesetup = new System.Windows.Forms.MenuItem();
this.menuFilePrint = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuFileExit = new System.Windows.Forms.MenuItem();
this.menuEdit = new System.Windows.Forms.MenuItem();
this.menuEditCut = new System.Windows.Forms.MenuItem();
this.menuEditCopy = new System.Windows.Forms.MenuItem();
this.menuEditPaste = new System.Windows.Forms.MenuItem();
this.menuItem17 = new System.Windows.Forms.MenuItem();
this.menuEditFind = new System.Windows.Forms.MenuItem();
this.menuEditFindnext = new System.Windows.Forms.MenuItem();
this.menuEditReplace = new System.Windows.Forms.MenuItem();
this.menuEditReplaceall = new System.Windows.Forms.MenuItem();
this.menuItem22 = new System.Windows.Forms.MenuItem();
this.menuEditSelectall = new System.Windows.Forms.MenuItem();
this.menuEditTimedate = new System.Windows.Forms.MenuItem();
this.menuTools = new System.Windows.Forms.MenuItem();
this.menuHelp = new System.Windows.Forms.MenuItem();
this.menuHelpHelpindex = new System.Windows.Forms.MenuItem();
this.menuHelpWebsite = new System.Windows.Forms.MenuItem();
this.menuItem29 = new System.Windows.Forms.MenuItem();
this.menuHelpAbout = new System.Windows.Forms.MenuItem();
this.toolbarMain = new System.Windows.Forms.ToolBar();
this.statusbarMain = new System.Windows.Forms.StatusBar();
this.imageList = new System.Windows.Forms.ImageList(this.components);
this.toolBarButtonNew = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonOpen = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonSave = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonSep1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonPrintSetup = new System.Windows.Forms.ToolBarButton();
this.toolBarSaveAll = new System.Windows.Forms.ToolBarButton();
this.treeView1 = new System.Windows.Forms.TreeView();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.richTextBox1 = new System.Windows.Forms.RichTextBox();
this.toolBarButtonPrint = new System.Windows.Forms.ToolBarButton();
this.toolBarButtonSep2 = new System.Windows.Forms.ToolBarButton();
this.tabControl1.SuspendLayout();
this.tabPage1.SuspendLayout();
this.SuspendLayout();
//
// menuMain
//
this.menuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFile,
this.menuEdit,
this.menuTools,
this.menuHelp});
//
// menuFile
//
this.menuFile.Index = 0;
this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFileNew,
this.menuFileOpen,
this.menuFileSave,
this.menuFileSaveas,
this.menuFileSaveall,
this.menuFileClose,
this.menuItem8,
this.menuFilePagesetup,
this.menuFilePrint,
this.menuItem11,
this.menuFileExit});
this.menuFile.Text = "&File";
//
// menuFileNew
//
this.menuFileNew.Index = 0;
this.menuFileNew.Text = "&New";
//
// menuFileOpen
//
this.menuFileOpen.Index = 1;
this.menuFileOpen.Text = "&Open";
this.menuFileOpen.Click += new System.EventHandler(this.menuFileOpen_Click);
//
// menuFileSave
//
this.menuFileSave.Index = 2;
this.menuFileSave.Text = "&Save";
this.menuFileSave.Click += new System.EventHandler(this.menuFileSave_Click);
//
// menuFileSaveas
//
this.menuFileSaveas.Index = 3;
this.menuFileSaveas.Text = "Save &As";
//
// menuFileSaveall
//
this.menuFileSaveall.Index = 4;
this.menuFileSaveall.Text = "Sa&ve All";
//
// menuFileClose
//
this.menuFileClose.Index = 5;
this.menuFileClose.Text = "&Close";
//
// menuItem8
//
this.menuItem8.Index = 6;
this.menuItem8.Text = "-";
//
// menuFilePagesetup
//
this.menuFilePagesetup.Index = 7;
this.menuFilePagesetup.Text = "Page Set&up";
//
// menuFilePrint
//
this.menuFilePrint.Index = 8;
this.menuFilePrint.Text = "&Print";
//
// menuItem11
//
this.menuItem11.Index = 9;
this.menuItem11.Text = "-";
//
// menuFileExit
//
this.menuFileExit.Index = 10;
this.menuFileExit.Text = "&Exit";
this.menuFileExit.Click += new System.EventHandler(this.menuFileExit_Click);
//
// menuEdit
//
this.menuEdit.Index = 1;
this.menuEdit.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuEditCut,
this.menuEditCopy,
this.menuEditPaste,
this.menuItem17,
this.menuEditFind,
this.menuEditFindnext,
this.menuEditReplace,
this.menuEditReplaceall,
this.menuItem22,
this.menuEditSelectall,
this.menuEditTimedate});
this.menuEdit.Text = "&Edit";
//
// menuEditCut
//
this.menuEditCut.Index = 0;
this.menuEditCut.Text = "&Cut";
//
// menuEditCopy
//
this.menuEditCopy.Index = 1;
this.menuEditCopy.Text = "&Copy";
//
// menuEditPaste
//
this.menuEditPaste.Index = 2;
this.menuEditPaste.Text = "&Paste";
//
// menuItem17
//
this.menuItem17.Index = 3;
this.menuItem17.Text = "-";
//
// menuEditFind
//
this.menuEditFind.Index = 4;
this.menuEditFind.Text = "&Find";
//
// menuEditFindnext
//
this.menuEditFindnext.Index = 5;
this.menuEditFindnext.Text = "Find &Next";
//
// menuEditReplace
//
this.menuEditReplace.Index = 6;
this.menuEditReplace.Text = "&Replace";
//
// menuEditReplaceall
//
this.menuEditReplaceall.Index = 7;
this.menuEditReplaceall.Text = "Replace &All";
//
// menuItem22
//
this.menuItem22.Index = 8;
this.menuItem22.Text = "-";
//
// menuEditSelectall
//
this.menuEditSelectall.Index = 9;
this.menuEditSelectall.Text = "Select &All";
//
// menuEditTimedate
//
this.menuEditTimedate.Index = 10;
this.menuEditTimedate.Text = "Time/&Date";
//
// menuTools
//
this.menuTools.Index = 2;
this.menuTools.Text = "&Tools";
//
// menuHelp
//
this.menuHelp.Index = 3;
this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuHelpHelpindex,
this.menuHelpWebsite,
this.menuItem29,
this.menuHelpAbout});
this.menuHelp.Text = "&Help";
//
// menuHelpHelpindex
//
this.menuHelpHelpindex.Index = 0;
this.menuHelpHelpindex.Text = "&Help Index";
//
// menuHelpWebsite
//
this.menuHelpWebsite.Index = 1;
this.menuHelpWebsite.Text = "&Web Site";
//
// menuItem29
//
this.menuItem29.Index = 2;
this.menuItem29.Text = "-";
//
// menuHelpAbout
//
this.menuHelpAbout.Index = 3;
this.menuHelpAbout.Text = "&About";
//
// toolbarMain
//
this.toolbarMain.Appearance = System.Windows.Forms.ToolBarAppearance.Flat;
this.toolbarMain.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButtonNew,
this.toolBarButtonOpen,
this.toolBarButtonSave,
this.toolBarSaveAll,
this.toolBarButtonSep1,
this.toolBarButtonPrintSetup,
this.toolBarButtonPrint,
this.toolBarButtonSep2});
this.toolbarMain.ButtonSize = new System.Drawing.Size(40, 40);
this.toolbarMain.Divider = false;
this.toolbarMain.DropDownArrows = true;
this.toolbarMain.ImageList = this.imageList;
this.toolbarMain.Location = new System.Drawing.Point(0, 0);
this.toolbarMain.Name = "toolbarMain";
this.toolbarMain.ShowToolTips = true;
this.toolbarMain.Size = new System.Drawing.Size(704, 48);
this.toolbarMain.TabIndex = 0;
//
// statusbarMain
//
this.statusbarMain.Location = new System.Drawing.Point(0, 507);
this.statusbarMain.Name = "statusbarMain";
this.statusbarMain.Size = new System.Drawing.Size(704, 22);
this.statusbarMain.TabIndex = 1;
this.statusbarMain.Text = "Ready";
//
// imageList
//
this.imageList.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
this.imageList.ImageSize = new System.Drawing.Size(24, 24);
this.imageList.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList.ImageStream")));
this.imageList.TransparentColor = System.Drawing.Color.Fuchsia;
//
// toolBarButtonNew
//
this.toolBarButtonNew.ImageIndex = 0;
this.toolBarButtonNew.Text = "New";
//
// toolBarButtonOpen
//
this.toolBarButtonOpen.ImageIndex = 1;
this.toolBarButtonOpen.Text = "Open";
//
// toolBarButtonSave
//
this.toolBarButtonSave.ImageIndex = 2;
this.toolBarButtonSave.Text = "Save";
//
// toolBarButtonSep1
//
this.toolBarButtonSep1.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// toolBarButtonPrintSetup
//
this.toolBarButtonPrintSetup.ImageIndex = 4;
this.toolBarButtonPrintSetup.Text = "Print Setup";
//
// toolBarSaveAll
//
this.toolBarSaveAll.ImageIndex = 3;
this.toolBarSaveAll.Text = "Save All";
//
// treeView1
//
this.treeView1.Dock = System.Windows.Forms.DockStyle.Left;
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(0, 48);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -1;
this.treeView1.Size = new System.Drawing.Size(160, 459);
this.treeView1.TabIndex = 2;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Dock = System.Windows.Forms.DockStyle.Fill;
this.tabControl1.Location = new System.Drawing.Point(160, 48);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(544, 459);
this.tabControl1.TabIndex = 3;
//
// tabPage1
//
this.tabPage1.Controls.Add(this.richTextBox1);
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Size = new System.Drawing.Size(536, 433);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "New";
//
// richTextBox1
//
this.richTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
this.richTextBox1.Location = new System.Drawing.Point(0, 0);
this.richTextBox1.Name = "richTextBox1";
this.richTextBox1.Size = new System.Drawing.Size(536, 433);
this.richTextBox1.TabIndex = 0;
this.richTextBox1.Text = "";
//
// toolBarButtonPrint
//
this.toolBarButtonPrint.ImageIndex = 5;
this.toolBarButtonPrint.Text = "Print";
//
// toolBarButtonSep2
//
this.toolBarButtonSep2.Style = System.Windows.Forms.ToolBarButtonStyle.Separator;
//
// formMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(704, 529);
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.treeView1);
this.Controls.Add(this.statusbarMain);
this.Controls.Add(this.toolbarMain);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Menu = this.menuMain;
this.Name = "formMain";
this.Text = "Text Edit";
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
this.ResumeLayout(false);
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
string fileName = null;
if (args.Length !=0)
{
fileName = args[0];
}
Application.Run(new formMain(fileName));
}
protected void OpenFile()
{
try
{
using (StreamReader reader = File.OpenText(fileName))
{
richTextBox1.Clear();
richTextBox1.Text = reader.ReadToEnd();
}
}
catch (IOException ex)
{
MessageBox.Show(ex.Message, "Text Edit", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
private void menuFileOpen_Click(object sender, System.EventArgs e)
{
}
private void menuFileExit_Click(object sender, System.EventArgs e)
{
Application.Exit();
}
private void menuFileSave_Click(object sender, System.EventArgs e)
{
}
}
}