3 using System
.Collections
;
4 using System
.ComponentModel
;
5 using System
.Windows
.Forms
;
9 namespace NotePadExample
11 public class Notepad
: System
.Windows
.Forms
.Form
13 private System
.Windows
.Forms
.MainMenu mainMenu1
;
14 private System
.Windows
.Forms
.MenuItem menuItemFile
;
15 private System
.Windows
.Forms
.MenuItem menuItemNew
;
16 private System
.Windows
.Forms
.MenuItem menuItemOpen
;
17 private System
.Windows
.Forms
.MenuItem menuItemSave
;
18 private System
.Windows
.Forms
.MenuItem menuItemExit
;
19 private System
.Windows
.Forms
.MenuItem menuItemEdit
;
20 private System
.Windows
.Forms
.MenuItem menuItemCut
;
21 private System
.Windows
.Forms
.MenuItem menuItemCopy
;
22 private System
.Windows
.Forms
.MenuItem menuItemPaste
;
23 private System
.Windows
.Forms
.MenuItem menuItemSelectAll
;
24 private System
.Windows
.Forms
.MenuItem menuItemHelp
;
25 private System
.Windows
.Forms
.MenuItem menuItemAbout
;
26 private System
.Windows
.Forms
.TextBox textBox1
;
27 private System
.Windows
.Forms
.MenuItem menuItemSep2
;
28 private System
.Windows
.Forms
.SaveFileDialog saveFileDialog1
;
29 private System
.Windows
.Forms
.MenuItem menuItemSep1
;
30 private System
.Windows
.Forms
.OpenFileDialog openFileDialog1
;
31 private System
.Windows
.Forms
.MenuItem menuItemBlank
;
32 private System
.Windows
.Forms
.MenuItem menuItemGeneral
;
34 private System
.ComponentModel
.Container components
= null;
38 InitializeComponent();
41 protected override void Dispose( bool disposing
)
45 if (components
!= null)
50 base.Dispose( disposing
);
53 private void InitializeComponent()
55 this.mainMenu1
= new System
.Windows
.Forms
.MainMenu();
56 this.menuItemFile
= new System
.Windows
.Forms
.MenuItem();
57 this.menuItemNew
= new System
.Windows
.Forms
.MenuItem();
58 this.menuItemOpen
= new System
.Windows
.Forms
.MenuItem();
59 this.menuItemSep1
= new System
.Windows
.Forms
.MenuItem();
60 this.menuItemSave
= new System
.Windows
.Forms
.MenuItem();
61 this.menuItemSep2
= new System
.Windows
.Forms
.MenuItem();
62 this.menuItemExit
= new System
.Windows
.Forms
.MenuItem();
63 this.menuItemEdit
= new System
.Windows
.Forms
.MenuItem();
64 this.menuItemCut
= new System
.Windows
.Forms
.MenuItem();
65 this.menuItemCopy
= new System
.Windows
.Forms
.MenuItem();
66 this.menuItemPaste
= new System
.Windows
.Forms
.MenuItem();
67 this.menuItemSelectAll
= new System
.Windows
.Forms
.MenuItem();
68 this.menuItemHelp
= new System
.Windows
.Forms
.MenuItem();
69 this.menuItemAbout
= new System
.Windows
.Forms
.MenuItem();
70 this.menuItemBlank
= new System
.Windows
.Forms
.MenuItem();
71 this.openFileDialog1
= new System
.Windows
.Forms
.OpenFileDialog();
72 this.saveFileDialog1
= new System
.Windows
.Forms
.SaveFileDialog();
73 this.textBox1
= new System
.Windows
.Forms
.TextBox();
74 this.menuItemGeneral
= new System
.Windows
.Forms
.MenuItem();
77 this.mainMenu1
.MenuItems
.AddRange(new System
.Windows
.Forms
.MenuItem
[] {
83 this.menuItemFile
.Index
= 0;
84 this.menuItemFile
.MenuItems
.AddRange(new System
.Windows
.Forms
.MenuItem
[] {
92 this.menuItemFile
.Text
= "File";
94 this.menuItemNew
.Index
= 0;
95 this.menuItemNew
.Text
= "&New";
96 this.menuItemNew
.Click
+= new System
.EventHandler(this.menuItemNew_Click
);
98 this.menuItemOpen
.Index
= 1;
99 this.menuItemOpen
.Text
= "&Open";
100 this.menuItemOpen
.Click
+= new System
.EventHandler(this.menuItemOpen_Click
);
102 this.menuItemSep1
.Index
= 2;
103 this.menuItemSep1
.Text
= "-";
105 this.menuItemSave
.Index
= 3;
106 this.menuItemSave
.Text
= "&Save";
107 this.menuItemSave
.Click
+= new System
.EventHandler(this.menuItemSave_Click
);
109 this.menuItemSep2
.Index
= 4;
110 this.menuItemSep2
.Text
= "-";
112 this.menuItemExit
.Index
= 5;
113 this.menuItemExit
.Text
= "Exit";
114 this.menuItemExit
.Click
+= new System
.EventHandler(this.menuItemExit_Click_1
);
116 this.menuItemEdit
.Index
= 1;
117 this.menuItemEdit
.MenuItems
.AddRange(new System
.Windows
.Forms
.MenuItem
[] {
121 this.menuItemSelectAll
}
123 this.menuItemEdit
.Text
= "Edit";
125 this.menuItemCut
.Index
= 0;
126 this.menuItemCut
.Text
= "&Cut";
127 this.menuItemCut
.Click
+= new System
.EventHandler(this.menuItemCut_Click
);
129 this.menuItemCopy
.Index
= 1;
130 this.menuItemCopy
.Text
= "&Copy";
131 this.menuItemCopy
.Click
+= new System
.EventHandler(this.menuItemCopy_Click
);
133 this.menuItemPaste
.Index
= 2;
134 this.menuItemPaste
.Text
= "Paste";
135 this.menuItemPaste
.Click
+= new System
.EventHandler(this.menuItemPaste_Click
);
137 this.menuItemSelectAll
.Index
= 3;
138 this.menuItemSelectAll
.Text
= "&Select All";
139 this.menuItemSelectAll
.Click
+= new System
.EventHandler(this.menuItemSelectAll_Click
);
141 this.menuItemHelp
.Index
= 2;
142 this.menuItemHelp
.MenuItems
.AddRange(new System
.Windows
.Forms
.MenuItem
[] {
144 this.menuItemGeneral
}
146 this.menuItemHelp
.Text
= "Help";
148 this.menuItemAbout
.Index
= 0;
149 this.menuItemAbout
.Text
= "About";
150 this.menuItemAbout
.Click
+= new System
.EventHandler(this.menuItemAbout_Click
);
152 this.menuItemBlank
.Index
= 3;
153 this.menuItemBlank
.Text
= "";
155 this.saveFileDialog1
.FileName
= "doc1";
157 this.textBox1
.Dock
= System
.Windows
.Forms
.DockStyle
.Fill
;
158 this.textBox1
.Multiline
= true;
159 this.textBox1
.Name
= "textBox1";
160 this.textBox1
.ScrollBars
= System
.Windows
.Forms
.ScrollBars
.Vertical
;
161 this.textBox1
.Size
= new System
.Drawing
.Size(544, 321);
162 this.textBox1
.TabIndex
= 0;
163 this.textBox1
.Text
= "";
164 this.textBox1
.TextChanged
+= new
165 System
.EventHandler(this.textBox1_TextChanged_1
);
167 this.menuItemGeneral
.Index
= 1;
168 this.menuItemGeneral
.Text
= "General";
169 this.menuItemGeneral
.Click
+= new System
.EventHandler(this.menuItemGeneral_Click
);
171 this.AutoScaleBaseSize
= new System
.Drawing
.Size(5, 13);
172 this.ClientSize
= new System
.Drawing
.Size(544, 321);
173 this.Controls
.AddRange(new System
.Windows
.Forms
.Control
[] {
176 this.ImeMode
= System
.Windows
.Forms
.ImeMode
.Off
;
177 this.Menu
= this.mainMenu1
;
178 this.Name
= "Notepad";
179 this.Text
= "Notepad MWF Example";
180 this.Load
+= new System
.EventHandler(this.Form1_Load
);
181 this.ResumeLayout(false);
185 public static void Main()
187 Application
.Run(new Notepad());
190 private void Form1_Load(object sender
, System
.EventArgs e
)
195 private void menuItemOpen_Click(object sender
, System
.EventArgs e
)
197 openFileDialog1
.ShowDialog();
198 StreamReader sr
= new StreamReader(openFileDialog1
.FileName
);
199 textBox1
.Text
= sr
.ReadToEnd();
203 private void menuItemCut_Click(object sender
, System
.EventArgs e
)
205 Clipboard
.SetDataObject(textBox1
.SelectedText
);
206 textBox1
.SelectedText
="";
210 private void menuItemPaste_Click(object sender
, System
.EventArgs e
)
215 private void textBox1_TextChanged(object sender
, System
.EventArgs e
)
220 private void menuItemAbout_Click(object sender
, System
.EventArgs e
)
222 Form helpnew
= new Form();
227 private void textBox1_TextChanged_1(object sender
, System
.EventArgs e
)
232 private void menuItemExit_Click(object sender
, System
.EventArgs e
)
237 private void menuItemExit_Click_1(object sender
, System
.EventArgs e
)
242 private void menuItemCopy_Click(object sender
, System
.EventArgs e
)
247 private void menuItemSelectAll_Click(object sender
, System
.EventArgs e
)
249 textBox1
.SelectAll();
252 private void menuItemNew_Click(object sender
, System
.EventArgs e
)
257 private void menuItemSave_Click(object sender
, System
.EventArgs e
)
259 saveFileDialog1
.FileName
= "*.txt";
260 //saveFileDialog1.FilterIndex ="*.txt";
261 saveFileDialog1
.ShowDialog();
262 //MessageBox.Show (saveFileDialog1.FileName);
263 StreamWriter sw
= new StreamWriter(saveFileDialog1
.FileName
);
264 sw
.Write (textBox1
.Text
);
268 private void menuItemGeneral_Click(object sender
, System
.EventArgs e
)
270 Form gen
= new Form ();