public
class
ToolBar : System.Windows.Forms.Control System.Windows.Forms 的成员 摘要: 表示一个 Windows 工具栏。
我们先从 工具箱中拽一个ToolBar 控件
在ToolBar 属性中有一个 Buttons 中我们添加
这么多成员
这里每个成员的属性中有一个ImageIndex 如果想用它的话
我们还得再添加一个 控件
ImageList
在这里面 我们添加一些图标
然后,在ToolBar 中 的 ImageList 选择 刚才拽的 ImageList的名称
这样 就可以了
到此 界面的 已经搞好了
具体的样子是这样的
我们再从工具蓝中 拽连个控件, OpenFileDialog, SaveFileDialog和 richTextBox
双击 ToolBar 控件 进入 事件 代码
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{//响应工具栏按钮单击事件
if(e.Button==this.toolBarButton1)
{//新建文件
this.richTextBox1.Text="";
}
if(e.Button==this.toolBarButton2)
{//打开文件
this.openFileDialog1.ShowDialog();
string StrFileName=this.openFileDialog1.FileName;
if(StrFileName.Trim()=="")
return;
try
{
this.richTextBox1.LoadFile(StrFileName,RichTextBoxStreamType.PlainText);
}
catch(Exception Error)
{
MessageBox.Show("文件格式无效,可先新建一个文档,保存后再打开测试!","信息提示",MessageBoxButtons.OK,
MessageBoxIcon.Information);
}
}
if(e.Button==this.toolBarButton5)
{//剪切文本
this.richTextBox1.Cut();
}
if(e.Button==this.toolBarButton6)
{//复制文本
this.richTextBox1.Copy();
}
if(e.Button==this.toolBarButton7)
{//粘贴文本
this.richTextBox1.Paste();
}
}
方法 LoadFile 的解释
public void LoadFile ( System.IO.Stream data , System.Windows.Forms.RichTextBoxStreamType fileType )
System.Windows.Forms.RichTextBox 的成员
摘要:
将现有数据流的内容加载到 System.Windows.Forms.RichTextBox 控件中。
参数:
data: 要加载到 System.Windows.Forms.RichTextBox 控件中的数据流。
fileType: System.Windows.Forms.RichTextBoxStreamType 值之一。
异常:
System.ArgumentException: fileType 参数中指定了无效的文件类型。
System.IO.IOException: 将文件加载到控件时出错。
FileName-----------
public string FileName [ get, set ]
System.Windows.Forms.FileDialog 的成员
摘要:
获取或设置一个包含在文件对话框中选定的文件名的字符串。
public void Cut ( )
System.Windows.Forms.TextBoxBase 的成员
摘要:
将文本框中的当前选定内容移动到剪贴板中。
public void Copy ( )
System.Windows.Forms.TextBoxBase 的成员
摘要:
将文本框中的当前选定内容复制到剪贴板。
public void Paste ( System.Windows.Forms.DataFormats.Format clipFormat )
System.Windows.Forms.RichTextBox 的成员
摘要:
粘贴指定剪贴板格式的剪贴板内容。
搞定, 一个简单的记事本就这样写好了