分享
 
 
 

我写的一段"记事本"的程序,请高手指教.

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

不知C#是不是这么用的,我写的有没有体现C#的OOP思想.

程序没有写完,也很不完善,只是请各位指点一下.谢谢!!

____________________________________________________

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using System.Data;

using System.IO;

namespace notePad

{

/// <summary>

/// Form1 的摘要说明。

/// </summary>

public class notePad : System.Windows.Forms.Form

{

private System.Windows.Forms.RichTextBox richTextBox1;

private System.Windows.Forms.MainMenu mainMenu1;

private System.Windows.Forms.MenuItem menuItem8;

private System.Windows.Forms.MenuItem menuItem10;

private System.Windows.Forms.MenuItem menuItemFile;

private System.Windows.Forms.MenuItem menuItemEdit;

private System.Windows.Forms.MenuItem menuItemOption;

private System.Windows.Forms.MenuItem menuItemHelp;

private System.Windows.Forms.MenuItem menuItemNew;

private System.Windows.Forms.MenuItem menuItemOpen;

private System.Windows.Forms.MenuItem menuItemPrint;

private System.Windows.Forms.MenuItem menuItemExit;

private System.Windows.Forms.MenuItem menuItemFont;

private System.Windows.Forms.MenuItem menuItemWordWrap;

private System.Windows.Forms.MenuItem menuItemAbout;

private System.Windows.Forms.ToolBar toolBarOnly;

private System.Windows.Forms.ToolBarButton toolBarButtonNew;

private System.Windows.Forms.ToolBarButton toolBarButtonOpen;

private System.Windows.Forms.StatusBar statusBarOnly;

private System.Windows.Forms.StatusBarPanel statusBarPanelTime;

private System.Windows.Forms.OpenFileDialog openFileDialog1;

private System.Windows.Forms.ImageList imageList1;

private System.Windows.Forms.FontDialog fontDialog1;

private System.Windows.Forms.Timer timer1;

private System.ComponentModel.IContainer components;

private System.Windows.Forms.SaveFileDialog saveFileDialog1;

private System.Windows.Forms.MenuItem menuItemSave;

private System.Windows.Forms.MenuItem menuItemSaveAs;

private System.Windows.Forms.StatusBarPanel statusBarPanelFileName;

private string oemText = "";

public notePad()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

//

// TODO: 在 InitializeComponent 调用后添加任何构造函数代码

//

}

/// <summary>

/// 清理所有正在使用的资源。

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

/// </summary>

private void InitializeComponent()

{

this.components = new System.ComponentModel.Container();

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(notePad));

this.richTextBox1 = new System.Windows.Forms.RichTextBox();

this.mainMenu1 = new System.Windows.Forms.MainMenu();

this.menuItemFile = new System.Windows.Forms.MenuItem();

this.menuItemNew = new System.Windows.Forms.MenuItem();

this.menuItemOpen = new System.Windows.Forms.MenuItem();

this.menuItemSave = new System.Windows.Forms.MenuItem();

this.menuItemSaveAs = new System.Windows.Forms.MenuItem();

this.menuItem8 = new System.Windows.Forms.MenuItem();

this.menuItemPrint = new System.Windows.Forms.MenuItem();

this.menuItem10 = new System.Windows.Forms.MenuItem();

this.menuItemExit = new System.Windows.Forms.MenuItem();

this.menuItemEdit = new System.Windows.Forms.MenuItem();

this.menuItemOption = new System.Windows.Forms.MenuItem();

this.menuItemFont = new System.Windows.Forms.MenuItem();

this.menuItemWordWrap = new System.Windows.Forms.MenuItem();

this.menuItemHelp = new System.Windows.Forms.MenuItem();

this.menuItemAbout = new System.Windows.Forms.MenuItem();

this.toolBarOnly = new System.Windows.Forms.ToolBar();

this.toolBarButtonNew = new System.Windows.Forms.ToolBarButton();

this.toolBarButtonOpen = new System.Windows.Forms.ToolBarButton();

this.imageList1 = new System.Windows.Forms.ImageList(this.components);

this.statusBarOnly = new System.Windows.Forms.StatusBar();

this.statusBarPanelTime = new System.Windows.Forms.StatusBarPanel();

this.statusBarPanelFileName = new System.Windows.Forms.StatusBarPanel();

this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();

this.fontDialog1 = new System.Windows.Forms.FontDialog();

this.timer1 = new System.Windows.Forms.Timer(this.components);

this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();

((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTime)).BeginInit();

((System.ComponentModel.ISupportInitialize)(this.statusBarPanelFileName)).BeginInit();

this.SuspendLayout();

//

// richTextBox1

//

this.richTextBox1.AutoWordSelection = true;

this.richTextBox1.Location = new System.Drawing.Point(1, 30);

this.richTextBox1.Name = "richTextBox1";

this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedBoth;

this.richTextBox1.Size = new System.Drawing.Size(556, 298);

this.richTextBox1.TabIndex = 0;

this.richTextBox1.Text = "";

this.richTextBox1.WordWrap = false;

//

// mainMenu1

//

this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuItemFile,

this.menuItemEdit,

this.menuItemOption,

this.menuItemHelp});

//

// menuItemFile

//

this.menuItemFile.Index = 0;

this.menuItemFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuItemNew,

this.menuItemOpen,

this.menuItemSave,

this.menuItemSaveAs,

this.menuItem8,

this.menuItemPrint,

this.menuItem10,

this.menuItemExit});

this.menuItemFile.Text = "&File";

//

// menuItemNew

//

this.menuItemNew.Index = 0;

this.menuItemNew.Text = "&New";

//

// menuItemOpen

//

this.menuItemOpen.Index = 1;

this.menuItemOpen.Text = "&Open";

this.menuItemOpen.Click += new System.EventHandler(this.menuItemOpen_Click);

//

// menuItemSave

//

this.menuItemSave.Index = 2;

this.menuItemSave.Text = "&Save";

//

// menuItemSaveAs

//

this.menuItemSaveAs.Index = 3;

this.menuItemSaveAs.Text = "Save &As...";

this.menuItemSaveAs.Click += new System.EventHandler(this.menuItemSaveAs_Click);

//

// menuItem8

//

this.menuItem8.Index = 4;

this.menuItem8.Text = "-";

//

// menuItemPrint

//

this.menuItemPrint.Index = 5;

this.menuItemPrint.Text = "&Print";

//

// menuItem10

//

this.menuItem10.Index = 6;

this.menuItem10.Text = "-";

//

// menuItemExit

//

this.menuItemExit.Index = 7;

this.menuItemExit.Text = "E&xit";

this.menuItemExit.Click += new System.EventHandler(this.menuItemExit_Click);

//

// menuItemEdit

//

this.menuItemEdit.Index = 1;

this.menuItemEdit.Text = "&Edit";

//

// menuItemOption

//

this.menuItemOption.Index = 2;

this.menuItemOption.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuItemFont,

this.menuItemWordWrap});

this.menuItemOption.Text = "&Option";

//

// menuItemFont

//

this.menuItemFont.Index = 0;

this.menuItemFont.Text = "&Font";

this.menuItemFont.Click += new System.EventHandler(this.menuItemFont_Click);

//

// menuItemWordWrap

//

this.menuItemWordWrap.Index = 1;

this.menuItemWordWrap.Text = "&WordWrap";

this.menuItemWordWrap.Click += new System.EventHandler(this.menuItemWordWrap_Click);

//

// menuItemHelp

//

this.menuItemHelp.Index = 3;

this.menuItemHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuItemAbout});

this.menuItemHelp.Text = "&Help";

//

// menuItemAbout

//

this.menuItemAbout.Index = 0;

this.menuItemAbout.Text = "&About";

//

// toolBarOnly

//

this.toolBarOnly.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {

this.toolBarButtonNew,

this.toolBarButtonOpen});

this.toolBarOnly.ButtonSize = new System.Drawing.Size(24, 24);

this.toolBarOnly.DropDownArrows = true;

this.toolBarOnly.ImageList = this.imageList1;

this.toolBarOnly.Name = "toolBarOnly";

this.toolBarOnly.ShowToolTips = true;

this.toolBarOnly.Size = new System.Drawing.Size(560, 27);

this.toolBarOnly.TabIndex = 1;

this.toolBarOnly.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBarOnly_ButtonClick);

this.toolBarOnly.MouseEnter += new System.EventHandler(this.toolBarOnly_MouseEnter);

//

// toolBarButtonNew

//

this.toolBarButtonNew.ImageIndex = 0;

this.toolBarButtonNew.Text = "New";

this.toolBarButtonNew.ToolTipText = "Creat a New text";

//

// toolBarButtonOpen

//

this.toolBarButtonOpen.ImageIndex = 2;

this.toolBarButtonOpen.Text = "Open";

this.toolBarButtonOpen.ToolTipText = "Open a text";

//

// imageList1

//

this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;

this.imageList1.ImageSize = new System.Drawing.Size(16, 16);

this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));

this.imageList1.TransparentColor = System.Drawing.Color.Transparent;

//

// statusBarOnly

//

this.statusBarOnly.AllowDrop = true;

this.statusBarOnly.Location = new System.Drawing.Point(0, 324);

this.statusBarOnly.Name = "statusBarOnly";

this.statusBarOnly.Panels.AddRange(new System.Windows.Forms.StatusBarPanel[] {

this.statusBarPanelTime,

this.statusBarPanelFileName});

this.statusBarOnly.ShowPanels = true;

this.statusBarOnly.Size = new System.Drawing.Size(560, 13);

this.statusBarOnly.TabIndex = 2;

//

// statusBarPanelTime

//

this.statusBarPanelTime.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None;

this.statusBarPanelTime.Width = 50;

//

// statusBarPanelFileName

//

this.statusBarPanelFileName.Text = "Need a name";

this.statusBarPanelFileName.Width = 200;

//

// timer1

//

this.timer1.Enabled = true;

this.timer1.Interval = 1000;

this.timer1.Tick += new System.EventHandler(this.timer1_Tick);

//

// saveFileDialog1

//

this.saveFileDialog1.FileName = "doc1";

//

// notePad

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(560, 337);

this.Controls.AddRange(new System.Windows.Forms.Control[] {

this.statusBarOnly,

this.toolBarOnly,

this.richTextBox1});

this.Menu = this.mainMenu1;

this.Name = "notePad";

this.Text = "My NotePad";

this.Closing += new System.ComponentModel.CancelEventHandler(this.notePad_Closing);

this.SizeChanged += new System.EventHandler(this.notePad_SizeChanged);

((System.ComponentModel.ISupportInitialize)(this.statusBarPanelTime)).EndInit();

((System.ComponentModel.ISupportInitialize)(this.statusBarPanelFileName)).EndInit();

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// 应用程序的主入口点。

/// </summary>

[STAThread]

static void Main()

{

Application.Run(new notePad());

}

private void notePad_SizeChanged(object sender, System.EventArgs e)

{

richTextBox1.Width = this.Width - 12;

richTextBox1.Height = this.Height - 100;

}

private void menuItemWordWrap_Click(object sender, System.EventArgs e)

{

if(menuItemWordWrap.Checked == true)

{

richTextBox1.WordWrap = false;

menuItemWordWrap.Checked = false;

}

else

{

richTextBox1.WordWrap = true;

menuItemWordWrap.Checked = true;

}

}

private void menuItemOpen_Click(object sender, System.EventArgs e)

{

openFileDialog1.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";

openFileDialog1.ShowDialog();

if(openFileDialog1.FileName.Length > 0)

{

StreamReader fileReader = new StreamReader(openFileDialog1.FileName,System.Text.Encoding.GetEncoding("gb2312"));

richTextBox1.Text = fileReader.ReadToEnd();

oemText = fileReader.ReadToEnd();

statusBarPanelFileName.Text = openFileDialog1.FileName;

fileReader.Close();

}

}

private void toolBarOnly_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)

{

switch(toolBarOnly.Buttons.IndexOf(e.Button))

{

case 0:

//

break;

case 1:

this.menuItemOpen_Click(this,null);

break;

}

}

private void menuItemFont_Click(object sender, System.EventArgs e)

{

fontDialog1.ShowDialog();

richTextBox1.Font = fontDialog1.Font;

}

private void timer1_Tick(object sender, System.EventArgs e)

{

statusBarPanelTime.Text = DateTime.Now.ToString("hh:mm:ss");

}

private void toolBarOnly_MouseEnter(object sender, System.EventArgs e)

{

// toolBarOnly.Buttons.IndexOf.

}

private void menuItemExit_Click(object sender, System.EventArgs e)

{

this.Close();

}

private void menuItemSaveAs_Click(object sender, System.EventArgs e)

{

saveFileDialog1.Filter = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";

saveFileDialog1.ShowDialog();

if(saveFileDialog1.FileName.Length > 0)

{

richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);

statusBarPanelFileName.Text = saveFileDialog1.FileName;

}

}

private void notePad_Closing(object sender, System.ComponentModel.CancelEventArgs e)

{

if(oemText != richTextBox1.Text)

{

DialogResult msgReturn;

msgReturn = MessageBox.Show("The text already changed , Are you saved change .","Exit",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);

switch (msgReturn)

{

case DialogResult.Yes:

menuItemSaveAs_Click(this,null);

break;

case DialogResult.No:

//do nothing;

return;

}

}

}

}

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有