• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

ファイル整理用ツールのWinFormサンプル実装


Commit MetaInfo

Revisióndab80b5c530d5405aed2dbb816344cdd906c3769 (tree)
Tiempo2018-12-24 08:54:33
Autoryoshy <yoshy@user...>
Commiteryoshy

Log Message

テスト - ドラッグイメージにテキスト描画を追加

Cambiar Resumen

Diferencia incremental

--- a/FolderCategorizer/Presentation/View/MainForm.cs
+++ b/FolderCategorizer/Presentation/View/MainForm.cs
@@ -89,8 +89,6 @@ namespace FolderCategorizer.Presentation.View
8989
9090 public List<ListViewItem> SelectedFileListViewItems { get; set; } = null;
9191
92- public List<int> SelectedFileListViewItemIndices { get; set; } = null;
93-
9492 public List<TreeNode> SelectedFolderTreeViewNodes { get; set; } = null;
9593
9694 public List<string> ProhibitedDropFolderTopPaths { get; set; } = null;
@@ -3626,15 +3624,12 @@ namespace FolderCategorizer.Presentation.View
36263624
36273625 private void DoDragDropFileList_DraggedFileListEntries_CreateEntries(ListView lv, TreeView tvSrcFolder1, TreeView tvSrcFolder2)
36283626 {
3629- List<int> selectedItemIndeices = new List<int>(lv.SelectedItems.Count);
36303627 List<ListViewItem> selectedItems = new List<ListViewItem>(lv.SelectedItems.Count);
36313628
36323629 List<string> prohibitedFolders = new List<string>();
36333630
3634- //foreach (ListViewItem lvi in lvFileList.SelectedItems)
3635- foreach (int i in lvFileList.SelectedIndices)
3631+ foreach (ListViewItem lvi in lvFileList.SelectedItems)
36363632 {
3637- ListViewItem lvi = lvFileList.Items[i];
36383633 FileListEntry entry = FileListEntry.FromTagOf(lvi);
36393634
36403635 switch (entry.Type)
@@ -3654,7 +3649,6 @@ namespace FolderCategorizer.Presentation.View
36543649 continue;
36553650 }
36563651
3657- selectedItemIndeices.Add(i);
36583652 selectedItems.Add(lvi);
36593653 }
36603654
@@ -3664,7 +3658,6 @@ namespace FolderCategorizer.Presentation.View
36643658 new TreeNode[] { tvSrcFolder1.SelectedNode, tvSrcFolder2.SelectedNode });
36653659
36663660 DraggedFileListEntries = new DraggedFileListEntriesHolder(selectedItems, selectedNodes, prohibitedFolders, GetCurrentRelativePath());
3667- DraggedFileListEntries.SelectedFileListViewItemIndices = selectedItemIndeices;
36683661 }
36693662
36703663 private DragDropEffects DragEnterFileList_DraggedFileListEntries(DraggedFileListEntriesHolder holder, int keyState, DragDropEffects allowedEffect, ListView lv, Point p)
@@ -4664,7 +4657,6 @@ namespace FolderCategorizer.Presentation.View
46644657 DoDragDropFileList_DraggedFileListEntries_CreateEntries(lvFileList, tvSrcFolder1, tvSrcFolder2);
46654658
46664659 Rectangle rcItems = new Rectangle();
4667- //foreach (ListViewItem item in lvFileList.SelectedItems)
46684660 foreach (ListViewItem item in DraggedFileListEntries.SelectedFileListViewItems)
46694661 {
46704662 rcItems = !rcItems.IsEmpty ? Rectangle.Union(rcItems, item.Bounds) : item.Bounds;
@@ -4683,66 +4675,29 @@ namespace FolderCategorizer.Presentation.View
46834675
46844676 using (Graphics g = Graphics.FromImage(image))
46854677 {
4686- g.DrawRectangle(SystemPens.WindowText, rcItems);
4687- //foreach (ListViewItem item in lvFileList.SelectedItems)
4688- //{
4689- // Point ip = item.Position;
4690- // ip.Offset(-rcItems.X, -rcItems.Y);
4691-
4692- // g.DrawString(item.Text, item.Font, SystemBrushes.WindowText, ip);
4693- //}
4694-
4695- // @see https://microsoft.public.win32.programmer.ui.narkive.com/Gc4nQBlx/listview-lvm-createdragimage-weirdness
4696- // @see https://groups.yahoo.com/neo/groups/wtl/conversations/topics/5110
4697- Font restoreFont = lvFileList.Font;
4678+ IntPtr hDC = g.GetHdc();
46984679
4699- IntPtr hTempFont = FontHelper.CreateFont(
4700- (int)-restoreFont.Size, 0, 0, 0,
4701- FontHelper.FW_NORMAL, 0, 0, 0,
4702- FontHelper.DEFAULT_CHARSET, FontHelper.OUT_DEFAULT_PRECIS, FontHelper.CLIP_DEFAULT_PRECIS,
4703- FontHelper.DEFAULT_QUALITY, FontHelper.VARIABLE_PITCH | FontHelper.FF_DONTCARE, "MS Sans Serif");
4704-
4705- Logger.Info($"hTempFont 0x{hTempFont.ToString("x8")}, size {restoreFont.Size}, Name {lvFileList.Font.Name}");
4706-
4707- //Font tempFont = Font.FromHfont(hTempFont);
4708- //lvFileList.Font = tempFont;
4709-
4710- using (Graphics gLV = lvFileList.CreateGraphics())
4680+ foreach (ListViewItem item in DraggedFileListEntries.SelectedFileListViewItems)
47114681 {
4712- IntPtr hLvDC = gLV.GetHdc();
4713- //IntPtr hOldFont = FontHelper.SelectObject(lvFileList.Handle, hTempFont);
4714- IntPtr hOldFont = FontHelper.SelectObject(hLvDC, hTempFont);
4715-
4716- Logger.Info($"hLvDC {hLvDC.ToString("X8")}, hOldFont 0x{hOldFont.ToString("x8")}");
4682+ ListViewHelper.POINTAPI pt;
47174683
4718- IntPtr hDC = g.GetHdc();
4719- FontHelper.SelectObject(hDC, hTempFont);
4720- FontHelper.SetTextColor(hDC, 0x000000FF);
4721- //FontHelper.SetBkMode(hDC, 1);
4684+ IntPtr h = ListViewHelper.CreateDragImage(lvFileList.Handle, item.Index, out pt);
47224685
4723- //foreach (int i in lvFileList.SelectedIndices)
4724- foreach (int i in DraggedFileListEntries.SelectedFileListViewItemIndices)
4725- {
4726- ListViewHelper.POINTAPI pt;
4727-
4728- IntPtr h = ListViewHelper.CreateDragImage(lvFileList.Handle, i, out pt);
4729-
4730- ImageListHelper.ImageList_Draw(h, 0, hDC, pt.x - rcItems.X, pt.y - rcItems.Y,
4731- (uint)(ImageListHelper.ILD_FLAGS.ILD_NORMAL | ImageListHelper.ILD_FLAGS.ILD_SELECTED));
4732-
4733- ImageListHelper.ImageList_Destroy(h);
4734- }
4686+ ImageListHelper.ImageList_Draw(h, 0, hDC, pt.x - rcItems.X, pt.y - rcItems.Y,
4687+ (uint)(ImageListHelper.ILD_FLAGS.ILD_NORMAL)); // | ImageListHelper.ILD_FLAGS.ILD_SELECTED));
47354688
4736- gLV.ReleaseHdc();
4689+ ImageListHelper.ImageList_Destroy(h);
47374690 }
47384691
47394692 g.ReleaseHdc();
47404693
4741- lvFileList.Font = restoreFont;
4742-
4743- //tempFont.Dispose();
4744- FontHelper.DeleteObject(hTempFont);
4694+ foreach (ListViewItem item in DraggedFileListEntries.SelectedFileListViewItems)
4695+ {
4696+ Point ip = item.Position;
4697+ ip.Offset(-rcItems.X + dpiHelper.HDPIValue(16 + 2), -rcItems.Y);
47454698
4699+ g.DrawString(item.Text, item.Font, SystemBrushes.WindowText, ip);
4700+ }
47464701 }
47474702
47484703 ImageList imageList = new ImageList