C#入门小程序ZHP.doc_第1页
C#入门小程序ZHP.doc_第2页
C#入门小程序ZHP.doc_第3页
C#入门小程序ZHP.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论