Helo!
Can anybody help me to do such a thing:
I would like to create for example node which will be including the TButton or other object inside, and then will be possible to use its properties.
thank You
regards
Jacek
// create the button when a rectangular node is inserted
procedure TForm1.SimpleGraph1ObjectInsert(Graph: TSimpleGraph;
GraphObject: TGraphObject);
var
btn: TButton;
begin
if GraphObject is TRectangularNode then
begin
// create the button
btn := TButton.Create(nil);
// set button's parent to simplegraph
btn.Parent := Graph;
// save a reference to button for recall
GraphObject.Tag := Integer(btn);
// position the button
SimpleGraph1NodeMoveResize(Graph, TGraphNode(GraphObject));
end;
end;
// destroy the button when the node is deleted
procedure TForm1.SimpleGraph1ObjectRemove(Graph: TSimpleGraph;
GraphObject: TGraphObject);
var
btn: TButton;
begin
// if any button is attached
if GraphObject.Tag <> 0 then
begin
// get the button
btn := TButton(GraphObject.Tag);
// remove reference
GraphObject.Tag := 0;
// free the button
btn.Free;
end;
end;
// reposition/resize the button when its node moved or resized
procedure TForm1.SimpleGraph1NodeMoveResize(Graph: TSimpleGraph;
Node: TGraphNode);
var
btn: TButton;
Pos: TPoint;
Size: TPoint;
begin
// if any button is attached
if Node.Tag <> 0 then
begin
// get the button
btn := TButton(Node.Tag);
// convert node's coordinates from graph to simplegraph
Pos := Graph.GraphToClient(Node.Left, Node.Top);
Size := Graph.GraphToClient(Node.Width, Node.Height);
// Set button's size as half size of the node and center it inside the node
Size.X := Size.X div 2;
Size.Y := Size.Y div 2;
Inc(Pos.X, Size.X div 2);
Inc(Pos.Y, Size.Y div 2);
btn.SetBounds(Pos.X, Pos.Y, Size.X, Size.Y);
end;
end;
procedure TForm1.SimpleGraph1ZoomChange(Sender: TObject);
begin
SimpleGraph1.ForEachObject(AdjustNodeBounds, 0);
end;
function TForm1.AdjustNodeBounds(GraphObject: TGraphObject; UserData: Integer): Boolean;
begin
if (GraphObject.Tag <> 0) and (GraphObject is TGraphNode) then
SimpleGraph1NodeMoveResize(SimpleGraph1, TGraphNode(GraphObject));
Result := True;
end;
Return to DELPHI AREA Projects
Users browsing this forum: No registered users and 1 guest