我正在使用以下代码使我的treenodes加粗:
Font font = new Font(tvQuestionSequence.Font, FontStyle.Bold);
foreach (QuestionnaireBuilder_Category cat in categories)
{
TreeNode node = new TreeNode();
node.Text = cat.Description;
node.Name = cat.Id.ToString();
node.NodeFont = font;
tvQuestionSequence.Nodes.Add(node);
}
Run Code Online (Sandbox Code Playgroud)
但粗体节点的文本未正确显示.最后一个字母未显示.怎么会?以及如何解决这个问题?
我需要更改所选节点的颜色,当选择节点并具有焦点时 - 返回颜色变为绿色,选中但没有焦点 - 红色.我无法区分选定的节点与焦点在树视图和没有.位于TabPage对象中的树视图.
//...
this.myTreeView.HideSelection = false;
//...
private void myTreeView_drawNode(object sender, DrawTreeNodeEventArgs e)
{
Color backColorSelected = System.Drawing.Color.Green;
Color backColor = System.Drawing.Color.Red;
// node selected and has focus
if (((e.State & TreeNodeStates.Selected) != 0)
&& (this.myTabControl.Focused)) // this doesn't work, node is always red
{
using (SolidBrush brush = new SolidBrush(backColorSelected))
{
e.Graphics.FillRectangle(brush, e.Bounds);
}
}
// node selected but doesn't have focus
else if ((e.State & TreeNodeStates.Selected) != 0)
{
using (SolidBrush brush = new SolidBrush(backColor)) …Run Code Online (Sandbox Code Playgroud)