c#考试资料自整理Word文档格式.docx
- 文档编号:17215599
- 上传时间:2022-11-29
- 格式:DOCX
- 页数:31
- 大小:156.85KB
c#考试资料自整理Word文档格式.docx
《c#考试资料自整理Word文档格式.docx》由会员分享,可在线阅读,更多相关《c#考试资料自整理Word文档格式.docx(31页珍藏版)》请在冰豆网上搜索。
//文件内容调入编辑器
privatevoid保存ToolStripMenuItem_Click(objectsender,EventArgse)
if(s_FileName.Length!
=0)
richTextBox1.SaveFile(s_FileName,RichTextBoxStreamType.PlainText);
//文件名存在编辑器内容存盘
else//调用“另存”事件
另存为ToolStripMenuItem_Click(sender,e);
privatevoid另存为ToolStripMenuItem_Click(objectsender,EventArgse)
SaveFileDialogsaveFileDialog1=newSaveFileDialog();
saveFileDialog1.Filter="
saveFileDialog1.FilterIndex=1;
if(saveFileDialog1.ShowDialog()==DialogResult.OK)
richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
//编辑器内容存盘
privatevoid退出ToolStripMenuItem_Click(objectsender,EventArgse)
Close();
privatevoid剪切ToolStripMenuItem_Click(objectsender,EventArgse)
richTextBox1.Cut();
privatevoid复制ToolStripMenuItem_Click(objectsender,EventArgse)
richTextBox1.Copy();
privatevoid粘贴ToolStripMenuItem_Click(objectsender,EventArgse)
richTextBox1.Paste();
privatevoid撤销ToolStripMenuItem_Click(objectsender,EventArgse)
richTextBox1.Undo();
privatevoid恢复ToolStripMenuItem_Click(objectsender,EventArgse)
richTextBox1.Redo();
privatevoid字体ToolStripMenuItem_Click(objectsender,EventArgse)
FontDialogfontDialog1=newFontDialog();
fontDialog1.ShowColor=true;
//打开字体对话框
if(fontDialog1.ShowDialog()==DialogResult.OK);
{//改变当前选定的文字字体
richTextBox1.SelectionFont=fontDialog1.Font;
//改变当前选定的文字颜色
richTextBox1.SelectionColor=fontDialog1.Color;
privatevoid颜色ToolStripMenuItem_Click(objectsender,EventArgse)
ColorDialogcolorDialog1=newColorDialog();
colorDialog1.FullOpen=true;
//显示“自定义颜色”
colorDialog1.AnyColor=true;
//选择任何颜色
//获取当前文字颜色
colorDialog1.Color=richTextBox1.ForeColor;
//打开颜色对话框
if(colorDialog1.ShowDialog()==DialogResult.OK);
richTextBox1.SelectionColor=colorDialog1.Color;
publicintstart;
privatevoid查找ToolStripMenuItem_Click(objectsender,EventArgse)
stringstr1;
//存放要查找的文本
str1=textBox1.Text;
//获取要查找的文本
start=richTextBox1.Find(str1,start,RichTextBoxFinds.MatchCase);
if(start==-1)
MessageBox.Show("
已经查找到文件末尾"
"
"
);
start=0;
else
start=start+str1.Length;
richTextBox1.Focus();
//设置焦点
privatevoidbutton1_Click(objectsender,EventArgse)
查找ToolStripMenuItem_Click(sender,e);
2、创建MDI应用程序建立多个子窗体,建立菜单实现
MDI窗体的建立
1、主窗体
◆建立Windows应用程序
◆设置MDI主窗体属性
◆MDI主窗体IsMdiContainer=true
◆添加菜单
2、建立MDI子窗体
◆项目/添加Windows窗体/Windows窗体
◆改变name属性为Child
◆text属性为Child
◆添加菜单控件
◆添加PictureBox控件
privatevoid新建ToolStripMenuItem_Click(objectsender,EventArgse)
Childc=newChild();
//建立子窗体对象
c.MdiParent=this;
//设置为当前窗体
c.Show();
privatevoid层叠ToolStripMenuItem_Click(objectsender,EventArgse)
this.LayoutMdi(MdiLayout.Cascade);
//层叠显示窗体
privatevoid垂直ToolStripMenuItem_Click(objectsender,EventArgse)
this.LayoutMdi(MdiLayout.TileVertical);
//垂直显示窗体
privatevoid水平ToolStripMenuItem_Click(objectsender,EventArgse)
this.LayoutMdi(MdiLayout.TileHorizontal);
//水平显示窗体
privatevoid关闭ToolStripMenuItem1_Click(objectsender,EventArgse)
this.ActiveMdiChild.Close();
//关闭子窗体
//退出系统
privatevoid打开ToolStripMenuItem_Click(objectsender,EventArgse)
OpenFileDialogpict1=newOpenFileDialog();
//打开文件对话框
//获取当前文件名筛选器字符串
pict1.Filter="
BmpFile(*.*)|*.*"
//判断文件是否打开
if(pict1.ShowDialog()==DialogResult.OK&
&
pictureBox1.Image==null)
Bitmapimage1=newBitmap(pict1.FileName);
//建立位图对象
pictureBox1.Image=image1;
//装载图像对象
else{
if(pictureBox2.Image==null)
Bitmapimage2=newBitmap(pict1.FileName);
pictureBox2.Image=image2;
else{
if(pictureBox3.Image==null)
Bitmapimage3=newBitmap(pict1.FileName);
pictureBox3.Image=image3;
if(pictureBox4.Image==null)
Bitmapimage4=newBitmap(pict1.FileName);
pictureBox4.Image=image4;
}
privatevoid画圆ToolStripMenuItem_Click(objectsender,EventArgse)
Graphicsg=pictureBox1.CreateGraphics();
Penpen1=newPen(Color.Red,1);
//画笔的颜色为红色
g.DrawEllipse(pen1,0,0,40,40);
//画以pen1为画笔的,以(0,0)为左上角坐标,40为宽度,40为高度的圆
privatevoid画实心圆ToolStripMenuItem_Click(objectsender,EventArgse)
Brushbrush1=newSolidBrush(Color.Green);
//填充的颜色为绿色
g.FillEllipse(brush1,30,30,40,40);
//画以brush1为画刷的,以(30,30)为左上角坐标,40为宽度,40为高度的实心圆
privatevoid画直线ToolStripMenuItem_Click(objectsender,EventArgse)
Penpen1=newPen(Color.Black,1);
//画笔的颜色为黑色
g.DrawLine(pen1,0,0,40,40);
//画以pen1为画笔的以(0,0)为起始点,(40,40)为终点的直线
privatevoid画矩形ToolStripMenuItem_Click(objectsender,EventArgse)
Penpen1=newPen(Color.Yellow,1);
//画笔的颜色为黄色
g.DrawRectangle(pen1,0,0,40,40);
//画以pen1为画笔的以左上角坐标(0,0)和宽度为40,高度为40的矩形
privatevoid画曲线ToolStripMenuItem_Click(objectsender,EventArgse)
//创建Graphics类对象g
Penpen1=newPen(Color.Blue,2);
//画笔的颜色为蓝色,画笔宽度为2
Rectanglerec=newRectangle(0,0,20,20);
//指定圆弧的外轮廓矩形区域
g.DrawArc(pen1,rec,23,99);
//画以pen1为画笔,rec为外轮廓矩形,以23°
为起始度数,扫过99°
的弧线
3、鼠标事件
设置窗体属性:
FormBorderStyle设为为None
设置标签控件:
lable1.Text=”点击这里移动窗体”
Booleandragging;
PointpointMOveTo;
privatevoidlabel1_MouseDown(objectsender,MouseEventArgse)
if(e.Button==MouseButtons.Left)
dragging=true;
dragging=false;
if(e.Button==MouseButtons.Right)
Application.Exit();
privatevoidlabel1_MouseMove(objectsender,MouseEventArgse)
if(dragging)
pointMOveTo=this.PointToScreen(newPoint(e.X,e.Y));
this.Location=pointMOveTo;
privatevoidlabel1_MouseUp(objectsender,MouseEventArgse)
privatevoidlabel1_MouseEnter(objectsender,EventArgse)
label1.Cursor=Cursors.Hand;
this.BackColor=Color.CadetBlue;
label1.BackColor=Color.CadetBlue;
privatevoidForm1_MouseEnter(objectsender,EventArgse)
privatevoidForm1_MouseLeave(objectsender,EventArgse)
this.BackColor=Color.Gainsboro;
label1.BackColor=Color.Gainsboro;
privatevoidForm1_MouseMove(objectsender,MouseEventArgse)
label1.Text="
(X:
"
+e.X+"
Y:
"
+e.Y+"
)"
4、键盘事件:
当按下键盘上的某一键时,显示该键的KeyData、KeyValue、KeyChar以及KeyCode值。
privatevoidtextBox1_KeyDown(objectsender,KeyEventArgse)
label2.Text="
Alt:
+(e.Alt?
True"
:
False"
)+'
\n'
+"
Shift:
+(e.Shift?
Ctrl:
+(e.Control?
KeyCode:
+e.KeyCode+'
KeyValue:
+e.KeyValue+'
KeyData:
+e.KeyData+"
\n"
privatevoidtextBox1_KeyPress(objectsender,KeyPressEventArgse)
你按下了"
+e.KeyChar+"
键"
5、使用定时器控件
publicForm1()
timer1.Start();
if(timer1.Enabled)
timer1.Stop();
button1.Text="
开始"
暂停"
privatevoidtimer1_Tick(objectsender,EventArgse)
label1.Text=DateTime.Now.Year.ToString()+"
-"
+DateTime.Now.Month.ToString()+"
+DateTime.Now.Day.ToString()+"
+DateTime.Now.Hour.ToString()+"
:
+DateTime.Now.Minute.ToString()+"
+DateTime.Now.Second.ToString();
privatevoidbutton2_Click(objectsender,EventArgse)
if(textBox1.Text=="
请输入时间长度(秒)"
if(timer2.Enabled)
textBox1.Text="
button2.Text="
timer2.Stop();
停止"
timer2.Start();
privatevoidtimer2_Tick(objectsender,EventArgse)
textBox1.Text=(System.Convert.ToInt32(textBox1.Text)-1).ToString();
0"
1、立体圆柱形
privatevoidForm1_Paint(objectsender,PaintEventArgse)
Graphicsg=e.Graphics;
for(inti=1;
i<
80;
i=i+1)
g.FillPie(newSolidBrush(Color.Red),newRectangle(60,80-i,200,100),0,360);
2、立体扇形
g.FillPie(newSolidBrush(Color.Red),newRectangle(60,80-i,200,100),0,30);
g.FillPie(newSolidBrush(Color.Blue),newRectangle(60,80-i,200,100),30,330);
3、正弦波
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- c# 考试 资料 整理
![提示](https://static.bdocx.com/images/bang_tan.gif)