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
}
}