Unvisible text

Hi Walter,
Now I’m testing a link mode.
As I’d like to allow to user makes a links in all position of node,
I change a midlabelmargin property as “node.MiddleLabelMargin = new SizeF(0, 0);”.
But the text of node is unvisible when I resize sizef by zero.
How can I make a always visible text?

OK, so you are using a GoBasicNode, and you have set .MiddleLabelMargin to have zero space between the .Label (a GoText) and the bounds of the .Shape (a GoShape).
Normally, the shape will be automatically sized to be the same as the label, plus the margins. If you have set GoBasicNode.AutoResizes to false, then changing the text will not resize the shape, and instead the text is wrapped and truncated (GoText.Wrapping and .Clipping are set to true).
If you want the text to always be visible, leave GoBasicNode.AutoResizes false. (If you had set it to true, then after you set it back to false you may need to call LayoutChildren(null) afterwards.)

But I don’t wanna resize of nodes when I change MiddleLabelMargin.
For this reason, I have set node.autoresize to false.

But if the user resizes the node to have zero size, of course there won’t be room to display any text.
Are you asking about how to keep the user from resizing the node too small when GoBasicNode.AutoResizes is true? If so, somehow you need to modify the resizing behavior.
You can do that by setting GoToolResizing.MinimumSize:
(goView1.FindMouseTool(typeof(GoToolResizing), true) as GoToolResizing).MinimumSize = new SizeF(100, 50);
Or you can override GoObject.DoResize:
[Serializable]
public class LimitedRectangle : GoRectangle {
public LimitedRectangle() {
this.Resizable = true;
}
public override void DoResize(GoView view, RectangleF origRect, PointF newPoint, int whichHandle, GoInputState evttype, SizeF min, SizeF max) {
base.DoResize(view, origRect, newPoint, whichHandle, evttype, new SizeF(100, 50), max);
}
}
Where you want to put the code depends on whether you want it to apply to all resizing or just to the resizing of one particular kind of object.
The above possibilities work with objects that have the usual resize handles at the corners. I suppose you could override GoObject.ComputeResize or GoObject.DoResize to be more sophisticated regarding the resizing.

Thanks for your response.
But I don’t want to resize automatically a node when I change a middlelabelmargin property. The node size must be alwalys same.
I put the code as below, but it doesn’t works.
That’s not easy…
float width = 0
float height = 0;
foreach(GoObject obj in goView1.Document)
{
GoBasicNode node = obj as GoBasicNode;
if(node != null)
{
width = node.Width;
height = node.Height;
if(this.ChkLink.Checked == true)
{
(this.goView1.FindMouseT ool(typeof(GoToolResizing), true) as GoToolResizing).MinimumSize = new SizeF(width, height);
//unvisible when I change the middlelabelmargin
node.MiddleLabelMargin = new SizeF(node.Width, node.Height);
}
else
{
(this.goView1.FindMouseT ool(typeof(GoToolResizing), true) as GoToolResizing).MinimumSize = new SizeF(width, height);
node.MiddleLabelMargin = new SizeF(0, 0);
}
}
}

OK, I guess I misunderstood you, since I thought you wanted to resize the node. Forget about GoToolResizing.MinimumSize and GoObject.DoResize.
Could you explain what you really want? What is the purpose of setting GoBasicNode.MiddleLabelMargin?
If AutoResizes is false, as you increase the size of the margin, the size of the GoText label will necessarily decrease. Obviously if you make the margin too large for the size of the node, there won’t be any room left for the label, so you won’t see anything.

My customer wants “link mode and drag mode”, so I want a function as below.
When I click only a link mode, user can’t drag a nodes clicking the text of a node but user can make a link.
When I click a drag mode, user can’t not make a link but user can drag a node dragging all of a node’s position without univisible and resizing a text.
Sorry to make you confused…

OK, so your application has two modes:

  • one that supports linking but not dragging nodes (i.e. no moving or copying nodes), and
  • one that supports moving and copying nodes but not linking
    So you just need to toggle the values of GoView.AllowMove and AllowCopy and AllowLink appropriately.
    Furthermore, to allow users to draw a link from anywhere in the GoBasicNode (when GoView.AllowLink is true), you need to expose the whole GoBasicNode.Port.
    I assume that for all of your GoBasicNodes, GoBasicNode.LabelSpot is GoObject.Middle, and that you have already created a label by setting the GoBasicNode.Text property. The port is not seen because GoPort.Style is GoPortStyle.None. It is normally partly occluded by the GoBasicNode.Label, which is in front of the port. So you just need to make sure the port is in front of the label:
    n.InsertAfter(null, n.Port)
    So if I understand your requirements correctly, you don’t need to fiddle with tools or override any methods or implement any event handlers. Just set those “Allow…” properties on GoView, and modify each GoBasicNode’s Z-ordering to make sure the Port is in front of the Label.
    Hmmm, if you have a mode where you want to let the user click on the label to edit it in place, you’ll need to change the Z-order again to have the label be in front of the port. Or else you can implement an ObjectSingleClicked event handler for the node to programmatically start editing the text, even though the GoText is behind the GoPort. Well, this last paragraph was just speculation…

I put the code you suggested, that is working fine.
Thanks for your reply.