Exemple #1
0
 protected override void WndProc(ref Message m)
 {
     if (m.Msg == Win32Declarations.WM_NCPAINT && BorderStyle == BorderStyle.FixedSingle)
     {
         IntPtr hdc      = Win32Declarations.GetWindowDC(Handle);
         IntPtr brush    = Win32Declarations.CreateSolidBrush(Win32Declarations.ColorToRGB(_borderColor));
         IntPtr oldBrush = Win32Declarations.SelectObject(hdc, brush);
         RECT   rect     = new RECT(0, 0, Width, Height);
         Win32Declarations.FrameRect(hdc, ref rect, brush);
         Win32Declarations.SelectObject(hdc, oldBrush);
         Win32Declarations.DeleteObject(brush);
         Win32Declarations.ReleaseDC(Handle, hdc);
         m.Result = IntPtr.Zero;
     }
     else
     {
         base.WndProc(ref m);
     }
 }
Exemple #2
0
        public void Draw(TreeNode node, IntPtr hdc, Rectangle rect)
        {
            if (!IsHandled(node) || node.Bounds.IsEmpty || node.IsEditing)
            {
                return;
            }

            CustomTreeView.CustomTreeView treeView = (CustomTreeView.CustomTreeView)node.TreeView;

            int offset = CalculateOffset(node);

            RichText.RichText text = (RichText.RichText)myNodes[node];

            Rectangle contentRect = CalculateContentRectangle(node, hdc, offset);

            rect.X     += offset;
            rect.Width -= offset;

            Rectangle fullRect = new Rectangle(contentRect.X - 1, node.Bounds.Top, contentRect.Width + 5, node.Bounds.Height);

            //g.SetClip(fullRect);

            TreeNode dropHiliteNode = treeView.DraggingOver ? treeView.DropHighlightedNode : null;
            bool     hasFocus       = node.TreeView.Focused;
            bool     drawSelected   = treeView.DraggingOver
          ? (node == dropHiliteNode)
          : node.IsSelected && hasFocus;
            bool drawNonfocusedSelection = node.IsSelected && !node.TreeView.HideSelection &&
                                           (!hasFocus || treeView.DraggingOver);

            Color backColor;

            if (drawSelected)
            {
                backColor = SystemColors.Highlight;
            }
            else if (drawNonfocusedSelection)
            {
                backColor = SystemColors.Control;
            }
            else
            {
                backColor = treeView.BackColor;
            }

            IntPtr hBrush = Win32Declarations.CreateSolidBrush(Win32Declarations.ColorToRGB(backColor));

            RECT lineRect = new RECT(fullRect.Left - 1, node.Bounds.Top, fullRect.Right + 1, node.Bounds.Bottom);

            Win32Declarations.FillRect(hdc, ref lineRect, hBrush);
            Win32Declarations.DeleteObject(hBrush);

            if (drawSelected)
            {
                text = (RichText.RichText)text.Clone();
                text.SetColors(SystemColors.HighlightText, SystemColors.Highlight);
            }
            else if (drawNonfocusedSelection)
            {
                text = (RichText.RichText)text.Clone();
                text.SetColors(SystemColors.WindowText, SystemColors.Control);
            }

            text.Draw(hdc, contentRect);

            if (hasFocus && treeView.SelectedNode == node && treeView.NeedFocusRect() && dropHiliteNode == null)
            {
                RECT rc = new RECT(fullRect.Left - 1, fullRect.Top, fullRect.Right + 1, fullRect.Bottom);
                Win32Declarations.DrawFocusRect(hdc, ref rc);
            }
        }