仿 Window 做的属性窗体

using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;

namespace DIYWordpad
{
    public partial class FormAttributes : Form
    {
        private readonly FileInfo currentFile;

        public FormAttributes(FileInfo fi)
        {
            #region
            InitializeComponent();
            currentFile = fi;
            this.Text = string.Format("{0} 属性", currentFile.Name);
            labelName.Text = currentFile.Name;
            labelPath.Text = string.Format("位置:     {0}", currentFile.DirectoryName);
            labelSize.Text = string.Format("大小:     {0:#,##0.00} KB", currentFile.Length / 1024M);
            labelCreate.Text = string.Format("创建时间: {0:F}", currentFile.CreationTime);
            labelWrite.Text = string.Format("修改时间: {0:F}", currentFile.LastWriteTime);
            labelAccess.Text = string.Format("访问时间: {0:F}", currentFile.LastAccessTime);
            cbReadOnly.Checked = currentFile.IsReadOnly;
            cbHidden.Checked = ((currentFile.Attributes & FileAttributes.Hidden) != 0); // 取交集。
            #endregion
        }

        #region OKButton
        private void btnOK_Click(object sender, EventArgs e)
        {
            currentFile.Refresh();
            if (currentFile.Exists)
            {
                if (cbReadOnly.Checked && cbHidden.Checked)
                    currentFile.Attributes = FileAttributes.ReadOnly | FileAttributes.Hidden;
                else if (cbReadOnly.Checked)
                    currentFile.Attributes = FileAttributes.ReadOnly;
                else if (cbHidden.Checked)
                    currentFile.Attributes = FileAttributes.Hidden;
                else
                    currentFile.Attributes = FileAttributes.Normal;
            }
            else
                MessageBox.Show(this, string.Format("当前文件 {0} 不存在。", currentFile.FullName), "写字板", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            this.Close();
        }
        #endregion

        #region FindButton
        private void btnFind_Click(object sender, EventArgs e)
        {
            currentFile.Refresh();
            if (currentFile.Exists)
            {
                System.Diagnostics.Process.Start(currentFile.DirectoryName);
                System.Threading.Thread.Sleep(200);
                SendKeys.SendWait(currentFile.Name);
            }
            else
                MessageBox.Show(this, string.Format("当前文件 {0} 不存在。", currentFile.FullName), "写字板", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            this.Close();
        }
        #endregion

        #region OnPaint
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            Pen newPen = SystemPens.ControlDark;
            g.DrawIcon(this.Icon, 20, 14);
            g.DrawLine(newPen, 16, 52, 304, 52);
            g.DrawLine(newPen, 16, 106, 304, 106);
            g.DrawLine(newPen, 16, 186, 304, 186);
            e.Dispose();
        }
        #endregion

        #region CancelButton
        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        #endregion
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值