首先我想知道richtextbox可不可以利用GDI画箭头???如果可以画我是想将上面右侧反显的文字加上箭头。即:在左面“二”是“一”的子节点,那么在右边找到“二”和“一”反显后画上箭头,且是“二”指向“一”。其它一样,只需要子节点指向父节点。这个可能需要坐标,我只知道右面控件的左上角的坐标是(324,0),这个richtextbox大小是367,389.且一行能显示28个汉字,每增加一行y值增加16. 我的反显代码: private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
richTextBox1.SelectAll();
richTextBox1.SelectionBackColor = Color.White;
//richTextBox1.SelectionFont = new Font(Font, FontStyle.Regular); //当前选中的节点在richtextbox中检索并改变关键字背景色
string s = e.Node.Text;
int i = richTextBox1.Text.IndexOf(s);
while (i > -1)
{
richTextBox1.Select(i, s.Length);
richTextBox1.SelectionBackColor = Color.Red;
i = richTextBox1.Text.IndexOf(s, i + 1);
}
//当前选中的节点的子节点在richtextbox中检索并改变关键字背景色
if (e.Node.Nodes.Count > 0)
{
foreach (TreeNode ss in e.Node.Nodes)
{
int j = richTextBox1.Text.IndexOf(ss.Text);
while (j > -1)
{
richTextBox1.Select(j, ss.Text.Length);
richTextBox1.SelectionBackColor = Color.Red;
j = richTextBox1.Text.IndexOf(ss.Text, j + 1);
}
if (ss.Nodes.Count > 0)
{
SetChildNodeSelect(ss);
} }
}
} private void SetChildNodeSelect(TreeNode e)
{
//当前选中的节点的子节点在richtextbox中检索并改变关键字背景色 foreach (TreeNode ss in e.Nodes)
{
int j = richTextBox1.Text.IndexOf(ss.Text);
while (j > -1)
{
richTextBox1.Select(j, ss.Text.Length);
richTextBox1.SelectionBackColor = Color.Red;
j = richTextBox1.Text.IndexOf(ss.Text, j + 1);
}
if (ss.Nodes.Count > 0)
{
SetChildNodeSelect(ss);
}
}
}
{
richTextBox1.SelectAll();
richTextBox1.SelectionBackColor = Color.White;
//richTextBox1.SelectionFont = new Font(Font, FontStyle.Regular); //当前选中的节点在richtextbox中检索并改变关键字背景色
string s = e.Node.Text;
int i = richTextBox1.Text.IndexOf(s);
while (i > -1)
{
richTextBox1.Select(i, s.Length);
richTextBox1.SelectionBackColor = Color.Red;
i = richTextBox1.Text.IndexOf(s, i + 1);
}
//当前选中的节点的子节点在richtextbox中检索并改变关键字背景色
if (e.Node.Nodes.Count > 0)
{
foreach (TreeNode ss in e.Node.Nodes)
{
int j = richTextBox1.Text.IndexOf(ss.Text);
while (j > -1)
{
richTextBox1.Select(j, ss.Text.Length);
richTextBox1.SelectionBackColor = Color.Red;
j = richTextBox1.Text.IndexOf(ss.Text, j + 1);
}
if (ss.Nodes.Count > 0)
{
SetChildNodeSelect(ss);
} }
}
} private void SetChildNodeSelect(TreeNode e)
{
//当前选中的节点的子节点在richtextbox中检索并改变关键字背景色 foreach (TreeNode ss in e.Nodes)
{
int j = richTextBox1.Text.IndexOf(ss.Text);
while (j > -1)
{
richTextBox1.Select(j, ss.Text.Length);
richTextBox1.SelectionBackColor = Color.Red;
j = richTextBox1.Text.IndexOf(ss.Text, j + 1);
}
if (ss.Nodes.Count > 0)
{
SetChildNodeSelect(ss);
}
}
}
http://www.codeproject.com/KB/edit/numberedtextbox.aspx