文件属性修改器(C#)

博主在长时间未编程后,为满足工作需求,利用3个晚上的时间编写了一个文件属性修改器,旨在锻炼技能并增强功能。程序中融入了窗体事件捕获、绘图和资源管理等技术。
摘要由CSDN通过智能技术生成

         好长时间没有学习编程了,但心中一直挂念着程序,怀念过去曾经的时光。 
         最近工作需要,需要修改一些文件的属性,看到网上有一个,研究一番,觉得还是自己写一个,一来练练手过过瘾,二来也增加一些功能,于是花费了3个晚上写了这个文件属性修改器,(汗,用这么长时间)。
         程序中用到了以前不曾使用的三项技术:窗体之间事件捕获、画图和资源管理。
         下面是程序代码,资源管理文件无法上传。

 

// Form1

using  System;
using  System.Collections.Generic;
using  System.ComponentModel;
using  System.Data;
using  System.Drawing;
using  System.Text;
using  System.Windows.Forms;
using  System.IO;
using  System.Resources;
using  System.Reflection;

namespace  FileAttrib
{
    
///   <summary>
    
///  设置文件属性
    
///   </summary>
     public   partial   class  Form1 : Form
    {
        
private  Form2 form2;

        
// button4被单击的次数,用来判断当前应显示哪个文件的属性
         int  buttonClickCount  =   0 ;
        
private  ResourceManager getLocalResource  =   new  ResourceManager( " FileAttrib.Properties.Resources " , Assembly.GetEntryAssembly());

        
public  Form1()
        {
            
// 设置图标
             this .Icon  = (Icon )getLocalResource.GetObject( " propertiesORoptions " );
            InitializeComponent();
        }

        
private   void  button3_Click( object  sender, EventArgs e)
        {
            Application.Exit();
        }

        
///   <summary>
        
///  选择文件
        
///   </summary>
        
///   <param name="sender"></param>
        
///   <param name="e"></param>
         private   void  button1_Click( object  sender, EventArgs e)
        {
            
int  fileNameCount = 0 ;
            
string [] fileNames;

            
if  ( this .openFileDialog1.ShowDialog()  ==  DialogResult.OK)
            {
                fileNames 
=   this .openFileDialog1.FileNames;
                fileNameCount 
=  fileNames.Length;

                
if  (fileNameCount  ==   1 )
                {
                    
this .textBox1.Text  =  fileNames[ 0 ];
                    button4.Visible 
=   false ;

                    
// 取文件属性
                    loadFileAttrib(fileNames[ 0 ]);
                }
                
else
                {
                    
// 选择文件多于一个时,打开第二个窗口,以放置文件
                     if  (form2  ==   null   ||  form2.IsDisposed)
                    {
                        form2 
=   new  Form2();
                        form2.Width 
=   base .Width;
                        form2.Left 
=   base .Left;
                        form2.Top 
=   base .Top  -  form2.Height;
                        
// form2成为form1的附属窗体
                         this .AddOwnedForm(form2);
                        form2.Show();
                    }

                    
// form2移动、修改大小的事件通知,这样两个窗口的相对位置可以保持不动
                    form2.moveHaveRaise  +=   new  Form2.formMoveHandler( this .Form2_Move);
                    
                    
// form2的ListViewItem选择的事件通知
                    form2.itemSelectChange  +=   new  Form2.formMoveHandler( this .itemSelect_Change);                    
                }

                
// 将选择的文件放到form2中
                 if  (form2  !=   null )
                {
                    form2.addListViewItems 
=  fileNames;
                }
            }
        }

        
///   <summary>
        
///  修改文件属性
        
///   </summary>
        
///   <param name="sender"></param>
        
///   <param name="e"></param>
         private   void  button2_Click( object  sender, EventArgs e)
        {
            
char [] ss  =  {  ' | '  };
            
int  fileNumber  =  textBox1.Text.Split(ss).Length;
            
if  (fileNumber  ==   1 )
            {
                writeFileAttrib(textBox1.Text);
            }
            
else
            {
                
if  (MessageBox.Show( " 你选择了 " + fileNumber.ToString() + " 个文件,这些文件的属性都将被修改,确定吗? " , " 修改确认 " ,M
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值