|
1 | 1 | using System;
|
| 2 | +using System.IO; |
2 | 3 | using System.Drawing;
|
3 | 4 | using System.Drawing.Drawing2D;
|
4 | 5 | using System.ComponentModel.Design;
|
@@ -276,6 +277,115 @@ protected override void WndProc(ref Message message)
|
276 | 277 | }
|
277 | 278 |
|
278 | 279 | }
|
| 280 | + |
| 281 | + public class TreeViewEx : TreeView |
| 282 | + { |
| 283 | + private static Int32 SIZE1 = ScaleHelper.Scale(1); |
| 284 | + private static Int32 SIZE2 = ScaleHelper.Scale(2); |
| 285 | + private static Int32 SIZE3 = ScaleHelper.Scale(3); |
| 286 | + |
| 287 | + public TreeViewEx() : base() |
| 288 | + { |
| 289 | + this.DrawMode = TreeViewDrawMode.OwnerDrawAll; |
| 290 | + this.DrawNode += OnDrawNode; |
| 291 | + this.DragOver += OnDragOver; |
| 292 | + this.ShowPlusMinus = true; |
| 293 | + } |
| 294 | + |
| 295 | + protected override CreateParams CreateParams |
| 296 | + { |
| 297 | + get |
| 298 | + { |
| 299 | + CreateParams cp = base.CreateParams; |
| 300 | + cp.ExStyle |= 0x02000000; // WS_CLIPCHILDREN |
| 301 | + return cp; |
| 302 | + } |
| 303 | + } |
| 304 | + |
| 305 | + private void OnDragOver(Object sender, DragEventArgs e) |
| 306 | + { |
| 307 | + Point point = this.PointToClient(new Point(e.X, e.Y)); |
| 308 | + TreeViewHitTestInfo hit = this.HitTest(point); |
| 309 | + if (hit.Node != null) this.SelectedNode = hit.Node; |
| 310 | + } |
| 311 | + |
| 312 | + private void OnDrawNode(Object sender, DrawTreeNodeEventArgs e) |
| 313 | + { |
| 314 | + e.DrawDefault = false; |
| 315 | + Rectangle bounds = e.Node.Bounds; |
| 316 | + Color backHl = PluginBase.MainForm.GetThemeColor("TreeView.Highlight", SystemColors.Highlight); |
| 317 | + Color foreHl = PluginBase.MainForm.GetThemeColor("TreeView.HighlightText", SystemColors.HighlightText); |
| 318 | + SolidBrush brushFore = new SolidBrush(e.Node.TreeView.LineColor); |
| 319 | + SolidBrush brushBack = new SolidBrush(e.Node.TreeView.BackColor); |
| 320 | + if (bounds.IsEmpty || !e.Node.IsVisible) return; |
| 321 | + if ((e.State & TreeNodeStates.Focused) != 0) |
| 322 | + { |
| 323 | + e.Graphics.FillRectangle(new SolidBrush(backHl), Rectangle.Inflate(bounds, 1, 0)); |
| 324 | + } |
| 325 | + else if ((e.State & TreeNodeStates.Selected) != 0) |
| 326 | + { |
| 327 | + e.Graphics.FillRectangle(new SolidBrush(Color.Gray), Rectangle.Inflate(bounds, 1, 0)); |
| 328 | + } |
| 329 | + else e.Graphics.FillRectangle(brushBack, bounds); |
| 330 | + if (e.Node.Nodes.Count > 0) |
| 331 | + { |
| 332 | + Point[] arrow; |
| 333 | + Point middle = new Point(bounds.Left - 28, bounds.Top + bounds.Height / 2); |
| 334 | + if (e.Node.IsExpanded) |
| 335 | + { |
| 336 | + arrow = new Point[] |
| 337 | + { |
| 338 | + new Point(middle.X - SIZE3, middle.Y - 1), |
| 339 | + new Point(middle.X + SIZE3 + 1, middle.Y - 1), |
| 340 | + new Point(middle.X, middle.Y + SIZE3) |
| 341 | + }; |
| 342 | + e.Graphics.FillPolygon(brushFore, arrow); |
| 343 | + arrow = new Point[] |
| 344 | + { |
| 345 | + new Point(middle.X - SIZE1, middle.Y - 1), |
| 346 | + new Point(middle.X + SIZE1 + 1, middle.Y - 1), |
| 347 | + new Point(middle.X, middle.Y + SIZE1) |
| 348 | + }; |
| 349 | + e.Graphics.FillPolygon(brushBack, arrow); |
| 350 | + } |
| 351 | + else |
| 352 | + { |
| 353 | + arrow = new Point[] |
| 354 | + { |
| 355 | + new Point(middle.X - SIZE2, middle.Y - 2 * SIZE2), |
| 356 | + new Point(middle.X - SIZE2, middle.Y + 2 * SIZE2), |
| 357 | + new Point(middle.X + SIZE2, middle.Y) |
| 358 | + }; |
| 359 | + e.Graphics.FillPolygon(brushFore, arrow); |
| 360 | + arrow = new Point[] |
| 361 | + { |
| 362 | + new Point(middle.X - SIZE1 - 1, middle.Y - 2 * SIZE1), |
| 363 | + new Point(middle.X - SIZE1 - 1, middle.Y + 2 * SIZE1), |
| 364 | + new Point(middle.X + SIZE1 - 1, middle.Y) |
| 365 | + }; |
| 366 | + e.Graphics.FillPolygon(brushBack, arrow); |
| 367 | + } |
| 368 | + } |
| 369 | + if (e.Node.ImageIndex != -1) |
| 370 | + { |
| 371 | + Point nodePt = new Point(bounds.Location.X - 20, bounds.Location.Y + 1); |
| 372 | + Image nodeImg = e.Node.TreeView.ImageList.Images[e.Node.ImageIndex]; |
| 373 | + e.Graphics.DrawImage(nodeImg, nodePt); |
| 374 | + } |
| 375 | + Rectangle textRect = bounds; |
| 376 | + Font nodeFont = e.Node.NodeFont; |
| 377 | + Color textColor = e.Node.ForeColor; |
| 378 | + textRect = Rectangle.Inflate(textRect, 2, 0); |
| 379 | + if (nodeFont == null) nodeFont = ((TreeView)sender).Font; |
| 380 | + if (nodeFont.Bold) textRect.X += 1; |
| 381 | + if ((e.State & TreeNodeStates.Focused) != 0) textColor = foreHl; |
| 382 | + if ((e.State & TreeNodeStates.Selected) != 0) textColor = foreHl; |
| 383 | + if ((e.State & TreeNodeStates.Hot) != 0) nodeFont = new Font(nodeFont, FontStyle.Underline); |
| 384 | + TextRenderer.DrawText(e.Graphics, e.Node.Text, nodeFont, textRect, textColor); |
| 385 | + } |
| 386 | + |
| 387 | + } |
| 388 | + |
279 | 389 | public class ToolStripComboBoxEx : ToolStripControlHost
|
280 | 390 | {
|
281 | 391 | public ToolStripComboBoxEx() : base(new FlatCombo())
|
|
0 commit comments