TreeView 컨트롤의 DrawMode를 OwnerDrawText로 설정하고 DrawNode
이벤트 처리기 내에서 드로잉을 수행하여이 작업을 수행 할 수 있다고 생각합니다.
예제 DrawNode 구현 (노드 문자열을 공백으로 분할하고 굵은 체의 첫 번째 요소를 그립니다 나머지 문자열은 일반 글꼴을 사용하고 공백이없는 경우 운영 체제가 도면을 대신 처리하도록합니다)
private void TreeView_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
string regex = @"^.*\s+\[\d+\]$";
if (Regex.IsMatch(e.Node.Text, regex, RegexOptions.Compiled))
{
string[] parts = e.Node.Text.Split(' ');
if (parts.Length > 1)
{
string count = parts[parts.Length - 1];
string text = " " + string.Join(" ", parts, 0, parts.Length - 1);
Font normalFont = e.Node.TreeView.Font;
float textWidth = e.Graphics.MeasureString(text, normalFont).Width;
e.Graphics.DrawString(text,
normalFont,
SystemBrushes.WindowText,
e.Bounds);
using (Font boldFont = new Font(normalFont, FontStyle.Bold))
{
e.Graphics.DrawString(count,
boldFont,
SystemBrushes.WindowText,
e.Bounds.Left + textWidth,
e.Bounds.Top);
}
}
}
else
{
e.DrawDefault = true;
}
}
참고 : 대신 다시 그려진 각 TreeNode를 위해 그것을 폐기의 굵은 글꼴을 보유하고 폼에 변수 또는 속성을 추가 할 수 있습니다.
그것은 내가 아직 알지 못했던 것입니다. 그냥 필요한 것 – Gerbrand
원본 샘플과 같이 텍스트를 렌더링하도록 코드를 업데이트했습니다. –