1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
namespace LibLinkNode
{
public partial class TreeViewLink : TreeView
{
private NodeLink m_CurrentNode = null;
public TreeViewLink()
{
InitializeComponent();
}
protected override void OnNodeMouseClick(TreeNodeMouseClickEventArgs e)
{// Are we dealing with a dropdown node?
if (e.Node is NodeLink)
{
this.m_CurrentNode = (NodeLink)e.Node;
// Need to add the node's ComboBox to the
// TreeView's list of controls for it to work
this.Controls.Add(this.m_CurrentNode.LinkLabel);
// Now show the ComboBox
this.m_CurrentNode.LinkLabel.Show();
// Set the bounds of the ComboBox, with
// a little adjustment to make it look right
this.m_CurrentNode.LinkLabel.SetBounds(
this.m_CurrentNode.Bounds.X - 1,
this.m_CurrentNode.Bounds.Y - 2,
this.m_CurrentNode.Bounds.Width + 25,
this.m_CurrentNode.Bounds.Height);
// Listen to the SelectedValueChanged
// event of the node's ComboBox
this.m_CurrentNode.LinkLabel.LinkClicked += new LinkLabelLinkClickedEventHandler(LinkLabel_LinkClicked);
}
base.OnNodeMouseClick(e);
}
void LinkLabel_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
LinkLabel lnk = sender as LinkLabel;
lnk.Links[lnk.Links.IndexOf(e.Link)].Visited = true;
string target = e.Link.LinkData as string;
// If the value looks like a URL, navigate to it.
// Otherwise, display it in a message box.
if (null != target && target.StartsWith("www"))
{
System.Diagnostics.Process.Start(target);
}
else
{
MessageBox.Show("Item clicked: " + target);
}
}
}
} |
Partager