全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
C#入门小程序集锦一(2则)这个集锦来源于我开始接触C#时所分析过的一些小程序和一些自己设计的小程序,我是从.NET Framework v2.0 SDK开始的,所以一开始的程序各个.NET版本都能够运行。Test_01:Form的运用using System;using System.Drawing;using System.Windows.Forms;namespace test_01 class test public static void CreateMyForm() Form form1 = new Form(); Button button1 = new Button (); Button button2 = new Button (); button1.Text = OK; button1.Location = new Point (10, 10); / Set the text of button2 to Cancel. button2.Text = Cancel; / Set the position of the button based on the location of button1. button2.Location = new Point (button1.Left, button1.Height + button1.Top + 10); / Set the caption bar text of the form. form1.Text = My Dialog Box; / Display a help button on the form. form1.HelpButton = true; / Define the border style of the form to a dialog box. form1.FormBorderStyle = FormBorderStyle.FixedDialog; / Set the MaximizeBox to false to remove the maximize box. form1.MaximizeBox = false; / Set the MinimizeBox to false to remove the minimize box. form1.MinimizeBox = false; / Set the accept button of the form to button1. form1.AcceptButton = button1; / Set the cancel button of the form to button2. form1.CancelButton = button2; / Set the start position of the form to the center of the screen. form1.StartPosition = FormStartPosition.CenterScreen; / Add button1 to the form. form1.Controls.Add(button1); / Add button2 to the form. form1.Controls.Add(button2); / Display the form as a modal dialog box. form1.ShowDialog();static void Main(string args) CreateMyForm();Test_02:OpenFileDialog的运用using System;using System.Drawing;using System.Windows.Forms;using System.IO;namespace test_01 class test /System.Windows.Forms.OpenFileDialog openFileDialog1;public Form CreateMyForm() Form form1 = new Form(); Button button1 = new Button (); Button button2 = new Button (); button1.Text = OK; button1.Location = new Point (10, 10); button2.Text = Cancel; button2.Location = new Point (button1.Left, button1.Height + button1.Top + 10); form1.Text = My Dialog Box; form1.HelpButton = true; form1.FormBorderStyle = FormBorderStyle.FixedDialog; form1.MaximizeBox = false; form1.MinimizeBox = false; form1.AcceptButton = button1; /OpenFileDialog设置 /this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog(); /this.openFileDialog1.Filter = MP3文件|*.mp3; /this.openFileDialog1.Multiselect = true; /添加button1的Click事件 button1.Click += new EventHandler(this.Testing_Click); form1.CancelButton = button2; form1.StartPosition = FormStartPosition.CenterScreen; form1.Controls.Add(button1); form1.Controls.Add(button2); form1.ShowDialog(); return (form1);/button1事件触发void Testing_Click(Object sender,EventArgs e)/*Button clickedButton1 = (Button)sender;clickedButton1.Text = 已改变;/属性Enabled确定按钮是否可以与用户作出交互clickedButton1.Enabled = false;*/OpenFileDialog的应用/*Stream myStream; OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.InitialDirectory = D: ; openFileDialog1.Filter = txt files (*.txt)|*.txt|All files (*.*)|*.* ; openFileDialog1.FilterIndex = 1 ; openFileDialog1.RestoreDirectory = true ; if(openFileDialog1.ShowDialog() = DialogResult.OK) if(myStream = openFileDialog1.OpenFile()!= null) / Insert code to read the stream here. myStream.Close(); */OpenFileDialog MyFilePath = new OpenFileDialog();MyFilePath.Filter = txt files (*.txt)|*.txt|All files (*.*)|*.* ;/MyFilePath.Filter = Excel文件|*.xls;MyFilePath.FilterIndex = 1;MyFilePath.RestoreDire
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 土地换荒地协议书
- 2026-2031中国硅片行业发展趋势及投资前景分析报告
- 2026-2031中国光电鼠标市场全景评估研究报告
- 2025安全生产考试题库(含答案)
- 医院心肺复苏术理论知识比赛试题及答案
- 2025年机关事业单位工勤技能考试职业道德题库附答案
- 药品质量管理制度职责及岗位操作规程培训试卷及答案
- 2025公司企业防洪防汛应急预案演练脚本方案
- 2025年新闻记者职业资格考试题库含答案
- 电子工业版(第3版)教学设计-2023-2024学年中职中职专业课电子信息类71 电子与信息大类
- 彝族简介教学课件
- 中医经络养生课件
- 2025年电力工程造价从业人员专业能力评价考试(电力工程造价管理)历年参考题库含答案详解(5卷)
- 中国居民营养慢病报告解读
- 2025年医疗卫生基础知识考试试题及答案
- 出血急救教学
- 幽门螺旋杆菌感染的护理
- 2025年桌面云项目立项申请报告
- 给药错误原因分析及整改措施
- 《中国城市科技创新发展报告(2025)》
- 地铁自动化监测系统设计与优化研究
评论
0/150
提交评论