前田稔(Maeda Minoru)の超初心者のプログラム入門
![]()
![]()
| ID | メソッド | 説明 |
|---|---|---|
| Clipbord(&C) | ItemSave | 複数個の選択中のアイテムをクリップボードに保存 |
| サブフォルダ(&S) | SubFolder | 一個の選択中のフォルダを ListView に表示 |
| 別名で貼り付け(&P) | Paste | 複数個の選択中のアイテムを別名で貼り付け |
| エディタで編集(&E) | Editor | 複数個の選択中のファイルをエディタで起動 |
| 選択→ゴミ箱(&D) | Dust | 複数個の選択中のアイテムをゴミ箱に移動 |
| ReadonlyOnOff(&R) | ReadOnOff | 一個の選択中のアイテムの ReadOnly を On⇔Off |
private void SubFolder(object sender, EventArgs e)
{
ListViewItem itemx = new ListViewItem();
itemx = listView1.SelectedItems[0];
Sel_Dir = Sel_Dir + "\\" + itemx.Text;
SetList(Sel_Dir);
}
|
private void Paste(object sender, EventArgs e)
{
string str,strout;
if (Clip_Set()==false) MessageBox.Show("アイテムを選択して下さい");
System.Collections.Specialized.StringCollection files = Clipboard.GetFileDropList();
foreach(string fileName in files)
{
str = fileName;
strout= Sel_Dir + "\\" + "コピー ~ " + Path.GetFileName(str);
if (File.Exists(str)) File_Copy(str,strout,true);
}
ViewReset();
}
|
using System.Diagnostics; //Process の起動
public string ED_Path = @"C:\WINDOWS\System32\notepad.exe";
private void Editor(object sender, EventArgs e)
{
string str;
if (Clip_Set()==false) MessageBox.Show("アイテムを選択して下さい");
System.Collections.Specialized.StringCollection files = Clipboard.GetFileDropList();
foreach(string fileName in files)
{
str = fileName;
if (File.Exists(str)) //ファイル
{ Process.Start(ED_Path, str); }
}
}
|
private void Dust(object sender, EventArgs e)
{
if (Clip_Set()==false)
{ MessageBox.Show("アイテムを選択して下さい");
return;
}
DustBox(sender, e);
}
|
private void ReadOnOff(object sender, EventArgs e)
{
string pass;
ListViewItem itemx = new ListViewItem();
itemx = listView1.SelectedItems[0];
pass = Sel_Dir + "\\" + itemx.Text;
ReadOnly_OnOff(pass);
}
|
private void ReadOnly_OnOff(string path)
{
FileAttributes fas = File.GetAttributes(path);
if ((fas & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
{
MessageBox.Show("読み取り専用→書き込み許可", path);
fas = FileAttributes.Normal;
}
else
{
MessageBox.Show("書き込み許可→読み取り専用", path);
fas = fas | FileAttributes.ReadOnly;
}
File.SetAttributes(path, fas);
}
|
![]()
private void OyaFolder(object sender, EventArgs e)
{ int i;
i = Sel_Dir.Length;
if (i<2) return;
Sel_Dir = Sel_Dir.Substring(0, i-1);
i = Sel_Dir.LastIndexOf('\\');
if (i<0) return;
Sel_Dir = Sel_Dir.Substring(0, i+1);
Console.WriteLine(Sel_Dir);
ViewReset();
}
|
private void NewFolder(object sender, EventArgs e)
{
string str;
str = Sel_Dir + "\\" + "New Folder";
Console.WriteLine(str);
FileSystem.CreateDirectory(str);
ViewReset();
}
|
![]()
this.listView1.LabelEdit = true;
this.listView1.BeforeLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.ListView1_BeforeLabelEdit);
this.listView1.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.ListView1_AfterLabelEdit);
|
private void ListView1_BeforeLabelEdit(object sender, LabelEditEventArgs e)
{
ListViewItem itemx = new ListViewItem();
itemx = listView1.SelectedItems[0];
Buf = itemx.Text;
}
|
private void ListView1_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
if (e.Label != null) //ラベルが変更されたとき
{
ListView lv = (ListView)sender;
foreach(ListViewItem lvi in lv.Items)
{
if (lvi.Index != e.Item && lvi.Text == e.Label)
{
MessageBox.Show("同名のアイテムがすでにあります。");
e.CancelEdit = true; //編集をキャンセルして元に戻す
return;
}
}
string Before = Sel_Dir + "\\" + Buf;
string After = Sel_Dir + "\\" + e.Label;
Console.WriteLine(Before + "→" + After);
if (System.IO.Directory.Exists(Before)) //ディレクトリ名の変更
{ System.IO.Directory.Move(Before,After); }
else //ファイル名の変更
{ System.IO.File.Move(Before,After); }
}
}
|
![]()
[Next Chapter ↓] File Handler Version 1.0
[Previous Chapter ↑] 表示メニューを実装