diff options
author | Nikita Voronchev <nikita.voronchev@ru.axxonsoft.com> | 2020-01-28 18:38:27 +0300 |
---|---|---|
committer | Alexander Köplinger <alex.koeplinger@outlook.com> | 2020-01-28 18:38:27 +0300 |
commit | e2b632e4a707e2b62a2b3c95f21a208266a14925 (patch) | |
tree | d86b530f8a7b3a815741c84569742e69c41c66e4 /mcs | |
parent | 1bfd3173624ffc875f4e91ca2efc8853f8f6caf0 (diff) |
[WinForms] Incorrect Tree Nodes drawing at the `OwnerDrawText` mode (#18605)
Assume we have the following form `MyForm`:
```
using System;
using System.Drawing;
using System.Windows.Forms;
namespace test_TreeView
{
public class MyForm : Form
{
TreeView treeView = new TreeView()
public MyForm()
{
treeView.Nodes.Add("root node");
treeView.Nodes[0].Nodes.Add("first child node");
treeView.BackColor = Color.Gray;
treeView.LineColor = Color.Yellow;
treeView.DrawMode = TreeViewDrawMode.OwnerDrawText;
treeView.DrawNode += treeView_DrawNode;
Controls.Add(treeView);
}
private void treeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
var brush = new SolidBrush(Color.FromArgb(100, 255, 0, 0));
e.Graphics.FillRectangle(brush, e.Bounds);
}
}
}
```
The displayed result is
![image](https://user-images.githubusercontent.com/12382656/73263417-92872980-41e1-11ea-8f7c-7cecbb376b60.png)
One can see couple drawing issues:
* White rectangles under each `TreeNode`.
* The area of custom drawing (red rectangles) is shifted with respect to this white rectangles.
Current PR proposes the fix of this issues.
Co-authored-by: monojenkins <jo.shields+jenkins@xamarin.com>
Diffstat (limited to 'mcs')
3 files changed, 17 insertions, 18 deletions
diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs index d85c52dff6e..53f489d751b 100644 --- a/mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs +++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/Control.cs @@ -1406,8 +1406,7 @@ namespace System.Windows.Forms if (background_image == null) { if (!tbstyle_flat) { Rectangle paintRect = pevent.ClipRectangle; - Brush pen = ThemeEngine.Current.ResPool.GetSolidBrush(BackColor); - pevent.Graphics.FillRectangle(pen, paintRect); + pevent.Graphics.FillRectangle(BackColorBrush, paintRect); } return; } @@ -1417,8 +1416,8 @@ namespace System.Windows.Forms void DrawBackgroundImage (Graphics g) { Rectangle drawing_rectangle = new Rectangle (); - g.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), ClientRectangle); - + g.FillRectangle (BackColorBrush, ClientRectangle); + switch (backgroundimage_layout) { case ImageLayout.Tile: @@ -3469,6 +3468,8 @@ namespace System.Windows.Forms } } + protected SolidBrush BackColorBrush => ThemeEngine.Current.ResPool.GetSolidBrush (BackColor); + #endregion // Protected Instance Properties #region Public Static Methods diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/ControlPaint.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/ControlPaint.cs index 4004c1ec8ec..5a933f1dc10 100644 --- a/mcs/class/System.Windows.Forms/System.Windows.Forms/ControlPaint.cs +++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/ControlPaint.cs @@ -370,11 +370,11 @@ namespace System.Windows.Forms { ThemeEngine.Current.CPDrawContainerGrabHandle (graphics, bounds); } - public static void DrawFocusRectangle( Graphics graphics, Rectangle rectangle) { + public static void DrawFocusRectangle(Graphics graphics, Rectangle rectangle) { DrawFocusRectangle(graphics, rectangle, SystemColors.Control, SystemColors.ControlText); } - public static void DrawFocusRectangle( Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) { + public static void DrawFocusRectangle(Graphics graphics, Rectangle rectangle, Color foreColor, Color backColor) { ThemeEngine.Current.CPDrawFocusRectangle (graphics, rectangle, foreColor, backColor); } diff --git a/mcs/class/System.Windows.Forms/System.Windows.Forms/TreeView.cs b/mcs/class/System.Windows.Forms/System.Windows.Forms/TreeView.cs index 74d77f5f80f..a66f82ccc36 100644 --- a/mcs/class/System.Windows.Forms/System.Windows.Forms/TreeView.cs +++ b/mcs/class/System.Windows.Forms/System.Windows.Forms/TreeView.cs @@ -1419,7 +1419,7 @@ namespace System.Windows.Forms { private void Draw (Rectangle clip, Graphics dc) { - dc.FillRectangle (ThemeEngine.Current.ResPool.GetSolidBrush (BackColor), clip); + dc.FillRectangle (BackColorBrush, clip); if (dash == null) CreateDashPen (); @@ -1670,7 +1670,6 @@ namespace System.Windows.Forms { { if (!full_row_select || show_lines) DrawSelectionAndFocus(node, dc, node.Bounds); - Font font = node.NodeFont; if (node.NodeFont == null) @@ -1691,7 +1690,7 @@ namespace System.Windows.Forms { int middle = y + (ActualItemHeight / 2); if (full_row_select && !show_lines) { - Rectangle r = new Rectangle (1, y, ViewportRectangle.Width - 2, ActualItemHeight); + var r = new Rectangle (1, y, ViewportRectangle.Width - 2, ActualItemHeight); DrawSelectionAndFocus (node, dc, r); } @@ -1716,26 +1715,25 @@ namespace System.Windows.Forms { } if (draw_mode != TreeViewDrawMode.Normal) { - dc.FillRectangle (Brushes.White, node.Bounds); - TreeNodeStates tree_node_state = TreeNodeStates.Default;; + dc.FillRectangle (BackColorBrush, node.Bounds); + + var tree_node_state = TreeNodeStates.Default;; if (node.IsSelected) tree_node_state = TreeNodeStates.Selected; if (node.Checked) tree_node_state |= TreeNodeStates.Checked; if (node == focused_node) tree_node_state |= TreeNodeStates.Focused; - Rectangle node_bounds = node.Bounds; - if (draw_mode == TreeViewDrawMode.OwnerDrawText) { - node_bounds.X += 3; - node_bounds.Y += 1; - } else { + + var node_bounds = node.Bounds; + if (draw_mode != TreeViewDrawMode.OwnerDrawText) { node_bounds.X = 0; node_bounds.Width = Width; } - DrawTreeNodeEventArgs e = new DrawTreeNodeEventArgs (dc, node, node_bounds, tree_node_state); + var e = new DrawTreeNodeEventArgs (dc, node, node_bounds, tree_node_state); - OnDrawNode (e); + OnDrawNode (e); if (!e.DrawDefault) return; } |