We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Positioning a Label

I have a problem to position a label correctly. If i set a lables position Property for example to "BottomCenter" than the label is positioned half inside the container an half outside. I expected that the label appears on the bottom end of the container (not on the border of the container).

Kind regards,
Michi



positionLabel.zip

7 Replies

SS Sri Subhashini M Syncfusion Team December 5, 2007 06:40 AM UTC

Hi Michi,

Sorry for delay getting back with you.

We can adjust the label position by setting the Position as Custom type. Then we have to set the Offset values for the X,Y co-ordinates to specify the label position.

Kindly review the code snippet

outerRect.Labels.Add(new Syncfusion.Windows.Forms.Diagram.Label());
outerRect.Labels[0].Text = "Rectangle";
outerRect.Labels[0].Position = Position.Custom;
outerRect.Labels[0].OffsetX = 50;
outerRect.Labels[0].OffsetY= 65;

Please take a look at the sample and let me know if its helpful.

http://websamples.syncfusion.com/samples/Diagram.Windows/70249/main.htm

Regards,
Suba




MM Michael M. December 5, 2007 07:15 AM UTC

The problem with custom positioning is, that i allways need to recalulate the offset if i resize the node which contains the label.
For example if i want to have it aligned on the bottom center (all the time) of my node.

Is there any other solution to achieve my goal.

Regards
Michi



SS Sri Subhashini M Syncfusion Team December 6, 2007 10:05 AM UTC

Hi Michi,

We can retain the labels offset value using the SizeChanged event. While resizing a node the SizeEvent gets fired. Using the event we can retain the labels position.

Please use the following code and let me know if this helpful.

// Adding Event Handler
((DocumentEventSink)diagram1.Model.EventSink).SizeChanged += new SizeChangedEventHandler(Form1_SizeChanged);

outerRect.Labels.Add(new Syncfusion.Windows.Forms.Diagram.Label());
outerRect.Labels[0].Text = "Rectangle";
outerRect.Labels[0].Position = Position.Custom;
outerRect.Labels[0].OffsetX = outerRect.Size.Width / 2;
outerRect.Labels[0].OffsetY = outerRect.Size.Height;

// Resizing
void Form1_SizeChanged(SizeChangedEventArgs evtArgs)
{
outerRect.Labels[0].OffsetX = outerRect.Size.Width / 2;
outerRect.Labels[0].OffsetY = outerRect.Size.Height;
}

Regards,
Suba




MM Michael M. December 7, 2007 05:41 AM UTC

Hallo, thanks for your help but i have known this possibility before and i hopped that there is another way too, to achieve centering a label on the bottom end of a node.

If there isn't any other way, please inform me.

Regards
Michi



SS Sri Subhashini M Syncfusion Team December 8, 2007 07:27 AM UTC

Hi Michi,

I apologize for the delay in responding.

I am able to understand your requirement, but fixing custom label positions for a node is not possible. Because the custom labels position is calculated with respective of the top left of the node. Once the node get resized we have to recalculate the offset position of the label using SizeChanged event.

Please let me know if you have any question.

Regards,
Suba



MM Michael M. December 12, 2007 06:53 AM UTC

I am not happy about your answer. If i recalculate the position on every resize, i get refresh problems. For some times the label is not repositioned correct until i refresh it explicit.

Why your default positioning with TopCenter, BottomCenter positions the Label on the border of the node. I dont understand why you do this

regards
michi




SS Sri Subhashini M Syncfusion Team December 14, 2007 07:10 AM UTC

Hi Michi,

Sorry for the delay in responding you.

For built-in Position we are calculating the labels position based on the size and location of the node. But for custom position it is not possible to calculate the position from size of the node. Since the custom position is calculated relative to the top left of the node. If we want to calculate the custom position relative to the node size as like built-in position, we need to add additional codes.

So we will consider "Diagram should calculate the label position respective to the node size" as a feature request. We have notified our development team on this regard and will get back to you once we hear back from them.

Regards,
Suba



Loader.
Live Chat Icon For mobile
Up arrow icon