Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Fit Size to Text (Read 3840 times)
pelion
Junior Member
**
Offline



Posts: 61
Joined: Nov 12th, 2006
Fit Size to Text
Apr 5th, 2007 at 3:47am
Print Post  
Hi, I am creating a box as a text holder label for another image box, with the text length being variable. My problem is that the FitSizeToText just doesn't seem to do anything, and my text is constantly been truncated.

If there is a reason my code below can't work, how can I get the length of a string as compared to a box size to set it myself?

(I also don't want it to be wrapping on spaces, just all one line)

Thanks

Code
Select All
private Box CreateTextBox(FlowChart chart, PointF pointf, string ImageText)

  {


//Create Box



Box box = chart.CreateBox(pointf.X - 16, pointf.Y + 8, 10, 8);





box.FrameColor = Color.Black;


//box.IgnoreLayout = true;


//box.EnableStyledText = true;


box.HandlesStyle = HandlesStyle.InvisibleMove;


box.Font = new Font("Tahoma", 3f, GraphicsUnit.World);


box.Text = ImageText;



box.FitSizeToText(FitSize.KeepHeight);



box.Locked = true;


box.Transparent = true;




//Handle Style



box.FrameColor = Color.Gray;



return box;

  }
 

  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Fit Size to Text
Reply #1 - Apr 5th, 2007 at 5:07am
Print Post  
Are there new-line characters in the string? If there are some, there might not be enough space to fit the text in the fixed height and the method just returns false.

Stoyan
  
Back to top
 
IP Logged
 
rand_acs
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 8
Joined: Jan 23rd, 2007
Re: Fit Size to Text
Reply #2 - Apr 5th, 2007 at 8:25am
Print Post  
I have a problem that is the opposite. How to fit text to size.

I have a shape that has an image rectangle and a text area under it. The text string can become quite long. It gets truncated when to long and words that are to long for the box width also has the same effect.

I can't let the icons change size, so I can't use the FitSizeToText function. Is there any way of getting the text to format better?

And another question. What would be the best way of uniquely identifying the boxes already created by the FlowChart class?
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Fit Size to Text
Reply #3 - Apr 5th, 2007 at 10:52am
Print Post  
If you attach another box to the icon and use it as a label, you could call the label's FitSizeToText. That way the icon won't be resized, but just the label box below it. Or you might create a temporary box, get its size after calling FitToText, and apply that size to the ShapeTemplate' text area.

You could use the Box.ZIndex to identify a box. There aren't any two boxes with the same ZIndex, and the following dependence is always true: fc.Objects[aBox.ZIndex] == aBox. You might also assign some GUID to the Box.Tag and use fc.FindBox() to get the box that corresponds to a GUID.

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


I love YaBB 1G - SP1!

Posts: 3
Joined: Apr 12th, 2007
Re: Fit Size to Text
Reply #4 - Apr 12th, 2007 at 6:12am
Print Post  
How works this "attach"? Is it possible to use one Box which contains two shapes. One for the Image and one for the Text?

Or is it possible to resize the Shape back to its "normal" size after doing the FitSizeToText.

Thanks, Oli
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Fit Size to Text
Reply #5 - Apr 12th, 2007 at 6:35am
Print Post  
Hi,

The attached box will follow the master box when the latter is moved or resized. This will create a composite shape that contains one box for the image and another for the text:

Code
Select All
string imagePath = @"D:\Images\1.jpg";

Box icon = new Box(fc);
icon.Image = Image.FromFile(imagePath);
icon.FitSizeToImage();
icon.Transparent = true;
fc.Add(icon);

Box label = new Box(fc);
label.Text = "label text";
label.BoundingRect = new RectangleF(PointF.Empty,
	fc.MeasureString(label.Text, label.Font, int.MaxValue, label.TextFormat));
label.Transparent = true;
label.Locked = true;
fc.Add(label);

// attach the label to the icon
RectangleF rc1 = icon.BoundingRect;
RectangleF rc2 = label.BoundingRect;
label.BoundingRect = new RectangleF(
	rc1.Left + rc1.Width / 2 - rc2.Width / 2,
	rc1.Bottom + 1,
	rc2.Width, rc2.Height);
label.AttachTo(icon, AttachToNode.BottomCenter);
 



Stoyan
  
Back to top
 
IP Logged
 
sambalmueslie
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 3
Joined: Apr 12th, 2007
Re: Fit Size to Text
Reply #6 - Apr 12th, 2007 at 10:14am
Print Post  
Hi,
thank you for the answer.
But I still have two problems. First one is, that the Text  on the Label changes later. Its possible to change it. But the Label doesn't resize. It has still the size from the beginning. I try to resize the BoundingRect but I don't know how.
And the second Problem is, that the TextLabel remains when the Icon will be deleted. How can I fix this.

Oli
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Fit Size to Text
Reply #7 - Apr 12th, 2007 at 10:22am
Print Post  
Hi,

After calling label.AttachTo(icon), set icon.SubordinateGroup.AutoDeleteItems = true.

You could use the same code as above to set the label.BoundingRect again. I.e. first call Box.FitSizeToText or Box.BoundingRect = fc.MeasureString(). That will set the correct size, but won't keep the label aligned to the horizontal center of the icon. To align the label to the icon, set the BoundingRect in the same way as before calling label.AttachTo. There is no need to call AttachTo again.

Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint