|
Mouse interaction
Tuesday, 08 September 2009
Every node control allows you to easily interact with the mouse to change the default behavior. To do that, inherit your node control class as stated below and override behavior for a mouse action that you need. Here is the custom node control class draws red pixels on the own image when the mouse was clicked and moved over this node control. class NodeImageActeractive : NodeImage { private bool _clicked; protected override void MouseDown(MouseActionArgs pArgs, DrawContext pContext) { _clicked = true; // pContext.Bounds contains the node control bounds rectangle. DrawPoint(pArgs.Node, pContext.Bounds, pArgs.Location); } protected override void MouseUp(MouseActionArgs pArgs) { _clicked = false; } protected override void MouseMove(MouseActionArgs pArgs, DrawContext pContext) { DrawPoint(pArgs.Node, pContext.Bounds, pArgs.Location); } void DrawPoint(Node pNode, Rectangle pBounds, Point pMouseLocation) { Bitmap bmp; Point pos; if (!_clicked) return; // calculate the pixel position inside the image. pos = pMouseLocation; pos.X –= pBounds.Location.X; pos.Y –= pBounds.Location.Y; bmp = GetValue<Bitmap>(pNode); bmp.SetPixel(pos .X, pos.Y, Color.Red); // notify and invalidate the treeview after node control changes. OnControlChanged(eNodeControlChangeType.Look); } } // use our node control. NodeImageActeractive nc = new NodeImageActeractive(); nc.AttachTo(tree); NodeWithImage n = new NodeWithImage(ourImage); // where ourImage is an image to display inside a node. n.AttachTo(tree);
|
|