В пользовательской древовидной форме при рисовании узлов между узлами возникают некоторые артефакты. как убрать этот артC#

Место общения программистов C#
Ответить Пред. темаСлед. тема
Anonymous
 В пользовательской древовидной форме при рисовании узлов между узлами возникают некоторые артефакты. как убрать этот арт

Сообщение Anonymous »

Не могу понять, почему появляются эти артефакты и как их убрать?
вверху:

Код: Выделить всё

public partial class CustomFolderBrowser : Form
{
private TreeView folderTreeView;
private Button okButton;
private Button cancelButton;
private Button makeNewFolderButton;
private BufferedLabel feedbackLabel;

private Image expandIcon;
private Image collapseIcon;

public string SelectedPath { get; private set; }
затем в событии drawode:

Код: Выделить всё

private void FolderTreeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
// Get the bounds of the node
Rectangle nodeRect = e.Node.Bounds;

// Clear the icon area before redrawing
e.Graphics.FillRectangle(SystemBrushes.Window, e.Bounds);  // Clear previous drawing

/*--------- 1. Draw expand/collapse icon ---------*/
if (e.Node.Nodes.Count > 0)
{
// Calculate position for expand/collapse icon
Point ptExpand = new Point(nodeRect.Left - 16, nodeRect.Top + (nodeRect.Height - 16) / 2); // Align vertically

// Choose the appropriate icon
Image expandCollapseImg = e.Node.IsExpanded ? collapseIcon : expandIcon;

// Draw the icon (ensure it is redrawn over a clear background)
e.Graphics.DrawImage(expandCollapseImg, ptExpand);
}

/*--------- 2. Draw node text ---------*/
// Get the node's font (default if none is set)
Font nodeFont = e.Node.NodeFont ?? ((TreeView)sender).Font;

// Set the color for the text (highlight if selected)
Brush textBrush = SystemBrushes.WindowText;
if ((e.State & TreeNodeStates.Selected) != 0)
{
textBrush = SystemBrushes.HighlightText;
e.Graphics.FillRectangle(SystemBrushes.Highlight, nodeRect); // Highlight background
}

// Draw the text
e.Graphics.DrawString(e.Node.Text, nodeFont, textBrush, nodeRect);

// Draw focus rectangle if node is selected
if ((e.State & TreeNodeStates.Focused) != 0)
{
ControlPaint.DrawFocusRectangle(e.Graphics, e.Bounds);
}
}
этот артефакт возникает во многих узлах. я просто показываю несколько примеров.
Изображение

и здесь я отметил артефакты справа красными кружками
Изображение


Подробнее здесь: https://stackoverflow.com/questions/790 ... cts-betwee
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «C#»