アイコン付きのドライブ文字のリストを表示するウィンドウ形式のコントロールはありますか?ドライブの選択ボックス(アイコンはウィンドウ形式)
2
A
答えて
3
いいえ、しかし、私はあなたがそれが起こることができると確信していますTreeViewで、あまりにもトリッキーであってはいけない、またはListViewを使用することができますリストをしたい場合。ドライブを取得する
コードは次のようになります
//Get all Drives
DriveInfo[] ListAllDrives = DriveInfo.GetDrives();
あなたはこのような何かを行うことができますのListViewItemまたはTreeViewNodesのアイコンを決定するには:
foreach (DriveInfo Drive in ListAllDrives)
{
//Create ListViewItem, give name etc.
ListViewItem NewItem = new ListViewItem();
NewItem.Text = Drive.Name;
//Check type and get icon required.
if (Drive.DriveType.Removable)
{
//Set Icon as Removable Icon
}
//else if (Drive Type is other... etc. etc.)
}
0
お支払いをご希望の場合は、http://viewpack.qarchive.org/をご確認ください。
私はフリーコントロールについて認識していません。
0
やっときました私自身のコントロールを思いついた。
次のように私はドライブを搭載したリストビューを埋める:
GetFileIconはSHGetFileInfoを呼び出して自分の方法であるlistView1.SmallImageList = new ImageList();
var drives = DriveInfo.GetDrives()
.Where(x => x.DriveType == DriveType.Removable)
.Select(x => x.Name.Replace("\\",""));
foreach (var driveName in drives)
{
listView1.SmallImageList.Images.Add(driveName, GetFileIcon(driveName));
listView1.Items.Add(driveName, driveName);
}
:フォームthis siteで、次のように見えるよう
IntPtr hImgSmall; //the handle to the system image list
SHFILEINFO shinfo = new SHFILEINFO();
//Use this to get the small Icon
hImgSmall = Win32.SHGetFileInfo(fileName, 0, ref shinfo,
(uint)Marshal.SizeOf(shinfo),
Win32.SHGFI_ICON |
Win32.SHGFI_SMALLICON);
return System.Drawing.Icon.FromHandle(shinfo.hIcon);
のWin32クラスがコピーされます。
[StructLayout(LayoutKind.Sequential)]
public struct SHFILEINFO
{
public IntPtr hIcon;
public IntPtr iIcon;
public uint dwAttributes;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)]
public string szDisplayName;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 80)]
public string szTypeName;
};
class Win32
{
public const uint SHGFI_ICON = 0x100;
public const uint SHGFI_LARGEICON = 0x0; // 'Large icon
public const uint SHGFI_SMALLICON = 0x1; // 'Small icon
[DllImport("shell32.dll")]
public static extern IntPtr SHGetFileInfo(string pszPath,
uint dwFileAttributes,
ref SHFILEINFO psfi,
uint cbSizeFileInfo,
uint uFlags);
}
私はそれが誰かを助けることを願っています。
関連する問題
- 1. 角度スキーマ形式空のオプションを持つレンダリング選択ボックス:value = "?"
- 2. MySql - UTC形式のタイムスタンプ列を選択
- 3. フォーム選択ボックス
- 4. エキスパンド選択ボックス
- 5. カスタムスタイルの選択ボックス
- 6. 選択ボックスのノーマルコーナー -
- 7. jQueryの:ボックス選択
- 8. 別の選択ボックス
- 9. カスタムスタイルの選択ボックス
- 10. 選択ボックスのi18n
- 11. Struts複数選択ボックスの選択
- 12. チェーン選択ボックスは3
- 13. Rails AJAX選択ボックス
- 14. Jcropデフォルト選択ボックス
- 15. 動的選択ボックス
- 16. 選択ボックスのオプションに
- 17. jqueryの代替選択ボックス
- 18. jQueryのリフレッシュ選択ボックス
- 19. 下のリンクボタンを選択ボックス
- 20. openerpの動的選択ボックス
- 21. 選択ボックスへの入力
- 22. Facebookページの選択ボックス
- 23. セル内のJqGrid選択ボックス
- 24. 選択ボックス:日のPHP
- 25. メニュー選択のアイコン/アンドロイド
- 26. BlueGriffonエディタの出力形式の選択方法は?
- 27. 削除&選択ボックスのオプションを追加し、他の選択は
- 28. TJclCompressArchive(プロジェクトJedi)。圧縮形式の選択方法は?
- 29. 選択する設定の保存形式は何ですか?
- 30. IE入力選択ボックス
shell32.dllを使用しているときに注意してください。変更する可能性があります(あなたはMicrosoftのようなものを知っています!)、ここでアイコンの使用に関する質問をしました。http://stackoverflow.com/questions/949196/読み込み中のアイコンがshell32-dll-win32-handle-not-valid-or-the-wrong-typeの場合 – ThePower
これはVistaで動作し、XPでは動作しません –