ファイル整理用ツールのWinFormサンプル実装
Revisión | dab80b5c530d5405aed2dbb816344cdd906c3769 (tree) |
---|---|
Tiempo | 2018-12-24 08:54:33 |
Autor | yoshy <yoshy@user...> |
Commiter | yoshy |
テスト - ドラッグイメージにテキスト描画を追加
@@ -89,8 +89,6 @@ namespace FolderCategorizer.Presentation.View | ||
89 | 89 | |
90 | 90 | public List<ListViewItem> SelectedFileListViewItems { get; set; } = null; |
91 | 91 | |
92 | - public List<int> SelectedFileListViewItemIndices { get; set; } = null; | |
93 | - | |
94 | 92 | public List<TreeNode> SelectedFolderTreeViewNodes { get; set; } = null; |
95 | 93 | |
96 | 94 | public List<string> ProhibitedDropFolderTopPaths { get; set; } = null; |
@@ -3626,15 +3624,12 @@ namespace FolderCategorizer.Presentation.View | ||
3626 | 3624 | |
3627 | 3625 | private void DoDragDropFileList_DraggedFileListEntries_CreateEntries(ListView lv, TreeView tvSrcFolder1, TreeView tvSrcFolder2) |
3628 | 3626 | { |
3629 | - List<int> selectedItemIndeices = new List<int>(lv.SelectedItems.Count); | |
3630 | 3627 | List<ListViewItem> selectedItems = new List<ListViewItem>(lv.SelectedItems.Count); |
3631 | 3628 | |
3632 | 3629 | List<string> prohibitedFolders = new List<string>(); |
3633 | 3630 | |
3634 | - //foreach (ListViewItem lvi in lvFileList.SelectedItems) | |
3635 | - foreach (int i in lvFileList.SelectedIndices) | |
3631 | + foreach (ListViewItem lvi in lvFileList.SelectedItems) | |
3636 | 3632 | { |
3637 | - ListViewItem lvi = lvFileList.Items[i]; | |
3638 | 3633 | FileListEntry entry = FileListEntry.FromTagOf(lvi); |
3639 | 3634 | |
3640 | 3635 | switch (entry.Type) |
@@ -3654,7 +3649,6 @@ namespace FolderCategorizer.Presentation.View | ||
3654 | 3649 | continue; |
3655 | 3650 | } |
3656 | 3651 | |
3657 | - selectedItemIndeices.Add(i); | |
3658 | 3652 | selectedItems.Add(lvi); |
3659 | 3653 | } |
3660 | 3654 |
@@ -3664,7 +3658,6 @@ namespace FolderCategorizer.Presentation.View | ||
3664 | 3658 | new TreeNode[] { tvSrcFolder1.SelectedNode, tvSrcFolder2.SelectedNode }); |
3665 | 3659 | |
3666 | 3660 | DraggedFileListEntries = new DraggedFileListEntriesHolder(selectedItems, selectedNodes, prohibitedFolders, GetCurrentRelativePath()); |
3667 | - DraggedFileListEntries.SelectedFileListViewItemIndices = selectedItemIndeices; | |
3668 | 3661 | } |
3669 | 3662 | |
3670 | 3663 | private DragDropEffects DragEnterFileList_DraggedFileListEntries(DraggedFileListEntriesHolder holder, int keyState, DragDropEffects allowedEffect, ListView lv, Point p) |
@@ -4664,7 +4657,6 @@ namespace FolderCategorizer.Presentation.View | ||
4664 | 4657 | DoDragDropFileList_DraggedFileListEntries_CreateEntries(lvFileList, tvSrcFolder1, tvSrcFolder2); |
4665 | 4658 | |
4666 | 4659 | Rectangle rcItems = new Rectangle(); |
4667 | - //foreach (ListViewItem item in lvFileList.SelectedItems) | |
4668 | 4660 | foreach (ListViewItem item in DraggedFileListEntries.SelectedFileListViewItems) |
4669 | 4661 | { |
4670 | 4662 | rcItems = !rcItems.IsEmpty ? Rectangle.Union(rcItems, item.Bounds) : item.Bounds; |
@@ -4683,66 +4675,29 @@ namespace FolderCategorizer.Presentation.View | ||
4683 | 4675 | |
4684 | 4676 | using (Graphics g = Graphics.FromImage(image)) |
4685 | 4677 | { |
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(); | |
4698 | 4679 | |
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) | |
4711 | 4681 | { |
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; | |
4717 | 4683 | |
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); | |
4722 | 4685 | |
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)); | |
4735 | 4688 | |
4736 | - gLV.ReleaseHdc(); | |
4689 | + ImageListHelper.ImageList_Destroy(h); | |
4737 | 4690 | } |
4738 | 4691 | |
4739 | 4692 | g.ReleaseHdc(); |
4740 | 4693 | |
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); | |
4745 | 4698 | |
4699 | + g.DrawString(item.Text, item.Font, SystemBrushes.WindowText, ip); | |
4700 | + } | |
4746 | 4701 | } |
4747 | 4702 | |
4748 | 4703 | ImageList imageList = new ImageList |