|
NodePopupContainer node control
Saturday, 12 September 2009
NodePopupContainer allows you to display a popup with any content on mouse click. The popup would be hidden when a user clicks outside of the popup or if the popup loses focus. Using of the NodePopupContainer node control involves these steps:
You can catch the moment when the popup was shown or hidden using the NodeControlPopupShow and NodeControlPopupHide treeview events respectively. Example: NodePopupContainer nc = new NodePopupContainer(); nc.AttachTo(tree); Node node= new Node(); node.AttachTo(tree); tree.MeasureNodeControl += tree_MeasureNodeControl; tree.PaintNodeControl += tree_PaintNodeControl; tree.NodeControlPopupShow += tree_NodeControlPopupShow; // measure the node control content size. private void tree_MeasureNodeControl(FlexibleTreeView pTreeview, MeasureObjectEventArgs pArgs) { // later we`ll draw the 17x17 pixels red rectangle. pArgs.Size = new Size(17, 17); } // draw the node control as a red rectangle. void tree_PaintNodeControl(FlexibleTreeView pTreeview, NodeControlDrawEventArgs pArgs) { using (SolidBrush br = new SolidBrush(Color.Red)) { pArgs.Context.Graphics.FillRectangle(br, pArgs.Context.Bounds); } } // provide the popup content. private void tree_NodeControlPopupShow(FlexibleTreeView pTreeview, PopupShowEventArgs pArgs) { // create a control to show in the popup. Button btn = new Button(); btn.Text = "Click me!"; btn.Click += btn_Click; pArgs.PopupContent = btn; // Optional: update the PopupContent.Size property to set the popup custom size. //pArgs.PopupContent.Size = btn.Size; } // handle popup content`s events as for any other control. private void btn_Click(object sender, EventArgs e) { MessageBox.Show("Button clicked"); }
|
|