登录
首页 » C#源码 » C#演示如何正确关闭程序

C#演示如何正确关闭程序

于 2023-04-28 发布 文件大小:40.82 kB
0 158
下载积分: 2 下载次数: 1

代码说明:

C#演示如何正确关闭程序,这是一个Wpf窗体实例,演示WPF窗口如何才是正确的关闭方法。   其实下边这句话最重要:   正确关闭程序的方法:App.Current.Shutdown();   具体的代码写法如下:   //文件名称:Window1.xaml.cs   private void button1_Click(object sender, RoutedEventArgs e)   {//正确关闭程序    App.Current.Shutdown();   }

下载说明:请别用迅雷下载,失败请重下,重下不扣分!

发表评论

0 个回复

  • C# 根据文件名提取文件类型图标
    C# 根据文件名提取文件类型图标,设定好文件目录后,本例中是读取C:Windows下的所有文件,并根据文件类型自动显示图标,如测试图所示,将文件类型的图标添加到listView中,下面是具体的实现代码:   this.imageList1.Images.Clear();   this.listView1.Items.Clear();    string MyFolder = @"C:Windows";   DirectoryInfo MyDir = new DirectoryInfo(MyFolder);   ListViewItem MyItem;   this.listView1.BeginUpdate();   foreach (FileInfo MyFile in MyDir.GetFiles())   {    Icon MyIcon = SystemIcons.WinLogo;    MyItem = new ListViewItem(MyFile.Name, 1);    MyIcon = Icon.ExtractAssociatedIcon(MyFile.FullName);    if (!this.imageList1.Images.ContainsKey(MyFile.Extension))    {    MyIcon =Icon.ExtractAssociatedIcon(MyFile.FullName);    this.imageList1.Images.Add(MyFile.Extension, MyIcon);    }    MyItem.ImageKey = MyFile.Extension;    this.listView1.Items.Add(MyItem);   }
    2023-07-30 19:25:04下载
    积分:1
  • 7Zip
    This file is part of SevenZipSharp.    SevenZipSharp is free software: you can redistribute it and/or modify    it under the terms of the GNU Lesser General Public License as published by    the Free Software Foundation, either version 3 of the License, or    (at your option) any later version.    SevenZipSharp is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public License    along with SevenZipSharp.  If not, see .
    2022-07-20 00:09:31下载
    积分:1
  • C# 在LINQ to DataSet中对分组操作执行子查询
    C# 在LINQ to DataSet中对分组操作执行子查询,相关代码:   private void button1_Click(object sender, EventArgs e)   {//在LINQ to DataSet中对分组操作执行子查询    SqlConnection MyConnection = new SqlConnection();    MyConnection.ConnectionString = @"Data Source =.SQLEXPRESS;Initial Catalog=Northwind;Integrated Security=True";    MyConnection.Open();    SqlCommand MyCommand = new SqlCommand("Select * From Orders ", MyConnection);    DataSet MySet = new DataSet();    SqlDataAdapter MyAdapter = new SqlDataAdapter(MyCommand);    MyAdapter.Fill(MySet);    DataTable MyQueryTable = MySet.Tables[0];    var MyQuery = from MyOrder in MyQueryTable.AsEnumerable()    orderby MyOrder.Field("ShipCity")    group MyOrder by MyOrder.Field("ShipCity") into g    select new    {    MyCity = g.Key,    MyMaxFreight = (from MyData in g select MyData.Field("Freight")).Max()   
    2022-01-27 20:20:32下载
    积分:1
  • C#读取数据库内容并在dataGridView中显示
    C#从数据库中读取内容并显示在dataGridView中,这似乎是一个很实用的功能,在数据库应用的时候,我们都要通过dataGridView来显示数据,这个例子可帮助初学者很好的掌握此功能的具体实现,一些代码片段分享如下:   private void button1_Click(object sender, EventArgs e)   {    //实例化SqlConnection变量conn,连接数据库    conn = new SqlConnection("server=.;database=db_15;uid=sa;pwd=");    //实例化SqlDataAdapter对象    SqlDataAdapter sda = new SqlDataAdapter("select * from tb_emp", conn);    DataSet ds = new DataSet(); //实例化DataSet对象    sda.Fill(ds);//使用SqlDataAdapter对象的Fill方法填充DataSet    dataGridView1.DataSource = ds.Tables[0];//设置dataGridView1控件的数据源    dataGridView1.RowHeadersVisible = false;//禁止显示行标题    //使用for循环设置控件的列宽    for (int i = 0; i < dataGridView1.ColumnCount; i++)    {    dataGridView1.Columns[i].Width = 84;    }    button1.Enabled = false;//禁用按钮    dataGridView1.Columns[0].ReadOnly = true;//将控件设置为只读   }   private DataTable dbconn(string strSql)//建立一个DataTable类型的方法   {    this.adapter = new SqlDataAdapter(strSql, conn);//实例化SqlDataAdapter对
    2022-07-24 21:44:03下载
    积分:1
  • C# LINQ操作相关函数集代
    C# LINQ操作相关函数集代码,这个函数集成在一个C#的实例程序中,包括了以下常用的LINQ操作函数,比如:获取LINQ返回序列的第一个元素、获取LINQ返回序列的最后一个元素、获取LINQ返回序列指定位置的元素、获取LINQ返回序列的单个特定元素、获取LINQ返回序列的非重复元素、将两个序列的元素合并为一个序列、获取序列中符合条件的元素个数、合并元素索引将元素投影到新表、将元素子级过滤结果投影到新表等。
    2022-08-18 19:41:06下载
    积分:1
  • C# 演示内连接查询的实现方法
    C# 演示内连接查询的实现方法,本演示将连接SQLSERVER数据库,查询结束将显示内联接查询结果,主要操作的是学生成绩表,学生信息表。
    2023-07-15 12:30:03下载
    积分:1
  • C# SelectionStart SelectionEnd时间段选择日历范例
    C# Calendar 时间段选择日历范例,可选择时间区间,调用 了C#中的SelectionStart SelectionEnd日期函数实现的功能,这个程序演示了两种功能:   1、获取控件当前的日期和时间   textBox1.Text = monthCalendar1.TodayDate.ToString();   2、时间起始段的选择:   通过SelectionStart属性获取用户选择的起始日期   textBox2.Text = monthCalendar1.SelectionStart.ToString();   通过SelectionEnd属性获取用户选择的结束日期   textBox3.Text = monthCalendar1.SelectionEnd.ToString();
    2022-08-15 10:37:28下载
    积分:1
  • C# 显示选择的DataGridView单元格行数据
    C# 显示选择的DataGridView单元格行数据附实现源码,连接数据库后,单击上部的“显示选择的单元格行”功能,即可显示出该行数据,具体的实现代码如下:   private void toolStripButton1_Click(object sender, EventArgs e)   {//显示选择的单元格行(获取DataGridView控件中选定的单元格行)   Int32 MyCount =customersDataGridView.Rows.GetRowCount(DataGridViewElementStates.Selected);   if (MyCount > 0)   {    System.Text.StringBuilder MyInfo = new System.Text.StringBuilder();    for (int i = 0; i < MyCount; i++)    {    MyInfo.Append("被选择的行号是: ");    MyInfo.Append(customersDataGridView.SelectedRows[i].Index.ToString());    MyInfo.Append(Environment.NewLine);    }    MyInfo.Append("一共选择了: " + MyCount.ToString()+"行。");    MessageBox.Show(MyInfo.ToString(), "信息提示",MessageBoxButtons.OK);   }   }
    2022-12-31 00:55:04下载
    积分:1
  • C# FTP客户端模块 上传下载文件显示进度
    C# FTP客户端模块 上传下载文件显示进度,本示例可通过HTTP、FTP下载文件,可通过FTP上传文件,请设定好服务器IP地址再测试,进度条在窗口的最上方。   percent = (float)totalDownloadedByte / (float)totalBytes * 100;   label1.Text = "当前补丁下载进度" + percent.ToString() + "%";   Application.DoEvents(); //必须加注这句代码,否则label1将因为循环执行太快而来不及显示信息   reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);//用户,密码   reqFTP.Method = WebRequestMethods.Ftp.UploadFile;//向服务器发出下载请求命令   reqFTP.ContentLength = finfo.Length;//为request指定上传文件的大小
    2022-03-23 13:46:25下载
    积分:1
  • C#读取文件内容显示在DataGridView表格中
    Visual C#在DataGridView单元格中显示文本文件的内容,可以理解为,从外部读取文件内容,将其显示在DataGridView   单元格中,可以看出,本代码中使用了DataTable对象、OleDb.OleDbDataAdapter对象,外部文件的格式暂定为txt,其它格式需要相关解析组件支持,实现本功能并不难,以下几行代码就可大致实现:   string MyPath = System.IO.Directory.GetCurrentDirectory();   string MyConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+MyPath+";Extended Properties="text;HDR=yes;FMT=delimited";";   string MySQL = "select * from 季度订单.txt";   DataTable MyTable = new DataTable();   System.Data.OleDb.OleDbDataAdapter MyAdapter = new System.Data.OleDb.OleDbDataAdapter(MySQL, MyConnectionString);   MyAdapter.Fill(MyTable);   this.dataGridView1.DataSource = MyTable;   运行界面效果请参见下图,完整源码请在本页下载。
    2022-03-20 07:42:37下载
    积分:1
  • 696516资源总数
  • 106914会员总数
  • 0今日下载