Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic 2 textareas in one node (Read 3005 times)
nezzy
YaBB Newbies
*
Offline



Posts: 25
Joined: May 31st, 2010
2 textareas in one node
May 31st, 2010 at 12:26pm
Print Post  
Hi.
I am looking at Tutorial3, with a custom made node. It has 2 extra string properties, Title and Fullname.
Is there a way of editing the Title/Fullname by dubbelclick or right-click the node?
/
Anders
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: 2 textareas in one node
Reply #1 - May 31st, 2010 at 12:46pm
Print Post  
Hi,

Try implementing the InplaceEditable interface in the derived node class. The control will call GetEditRect(mousePosition) before displaying the text entry control, and the GetTextToEdit/SetEditedText methods to get and update the text.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nezzy
YaBB Newbies
*
Offline



Posts: 25
Joined: May 31st, 2010
Re: 2 textareas in one node
Reply #2 - May 31st, 2010 at 1:24pm
Print Post  
Hi.
Thanks for a quick reply.
I'm not quite sure how to implement the InplaceEditable interface. Do you have an example?
Best regards
Anders
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: 2 textareas in one node
Reply #3 - May 31st, 2010 at 2:17pm
Print Post  
Hi,

It turned out it's not that easy without the Get/Set methods receiving a mouse position parameter. We'll add it as argument for the next release.

For now you can add a MouseMove handler to the node to track the mouse position, or do that from the diagram handler. Once you have it, you can implement the interface as shown below.

Code
Select All
public class OrgChartNode : ShapeNode, InplaceEditable

...

// in the constructor
MouseMove += OrgChartNode_MouseMove;

// implementation
Rect InplaceEditable.GetEditRect(Point position)
{
	var r = Bounds;
	r.Height = r.Height / 2;
	if (position.Y > r.Y + r.Height / 2)
		r.Y = r.Y + r.Height;
	return r;
}

DiagramItem InplaceEditable.GetDiagramItem()
{
	return this;
}

string InplaceEditable.GetTextToEdit()
{
	if (textBeingEdited == -1)
		textBeingEdited = mousePos.Y < Bounds.Height / 2 ? 0 : 1;

	switch (textBeingEdited)
	{
		case 0:
			return Title;
		case 1:
			return FullName;
	}
	return "";
}

void InplaceEditable.SetEditedText(string newText)
{
	switch (textBeingEdited)
	{
		case 0:
			Title = newText;
			break;
		case 1:
			FullName = newText;
			break;
	}
	textBeingEdited = -1;
}

private Point mousePos;
private int textBeingEdited = -1;

void OrgChartNode_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
{
	mousePos = e.GetPosition(this);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
nezzy
YaBB Newbies
*
Offline



Posts: 25
Joined: May 31st, 2010
Re: 2 textareas in one node
Reply #4 - May 31st, 2010 at 2:26pm
Print Post  
Hi again.
That work lika a charm. Just as I wanted.
You are the best !
Many thanks.
BR
Anders
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint