Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Group Two Boxes (Read 3715 times)
SWATalk
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Oct 23rd, 2005
Group Two Boxes
Dec 26th, 2005 at 11:13pm
Print Post  
Stoyo,

A while back, you sent me some code to attach two boxes (icon box and label box) together with the label box centered beneath the icon box.  See code below:

[code]
Image i = ( Image )e.Data.GetData( DataFormats.Bitmap );
Box icon = fcx.CreateBox( pt.X, pt.Y, 18, 10 );
icon.Picture = i;
//icon.PicturePos = EImagePos.imgTopCenter;
icon.FitSizeToPicture();
icon.FrameColor = Color.Red;
icon.Transparent = true;

// Create the text box that is attached to the image
Box label = fcx.CreateBox( pt.X - 16, pt.Y + 10, 40, 10 );

label.Transparent = true;
//label.MnpHandlesMask = 0;
//label.SelStyle = ESelStyle.sstInvisible;
label.FrameColor = Color.Black;
label.IgnoreLayout = true;
label.EnableStyledText = true;
label.Font = new Font( "Tahoma", 3f, GraphicsUnit.World );

// Centers the text under the image
RectangleF rcNode = icon.BoundingRect;
RectangleF rc = label.BoundingRect;
rc.X = rcNode.X + rcNode.Width / 2 - rc.Width / 2;
label.BoundingRect = rc;

MindFusion.FlowChartX.Group g = fcx.CreateGroup( icon );
g.AttachToSideMiddle( label, 2 );
[/code]

Currently, this code wraps a long line of code in which I do not want wordwrap.  It also pushes the label location either over the icon or pushes it farther down (see attached images).

I would want the label text to stay in the same location as in the image title (subject.jpg).

I also want to be able to edit the label box by double clicking it as well as to show a dialog in which I can edit the text on the label box.  I also want to be able to expand the label box while editing and not push the text up without being able to see what the user is editing.  Sort of like dynamically expanding the label text while in edit mode.

Can you provide me on how I could possibly be able to do this?

Thanks in advance

** I couldn't figure out how to attach the images so I will send them to your e-mail.
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Group Two Boxes
Reply #1 - Dec 27th, 2005 at 7:05am
Print Post  
Hi,

I guess your application calls FitSizeToText when the label's text changes ? However that method always wraps the text while resizing the box. FitSizeToText preserves the original box width/height ratio if PolyTextLayout is enabled, or it just changes the box height if PolyTextLayout is set to false. So before calling FitSizeToText, you could explicitly set the box width to make sure the text won't be wrapped. Use this function:

SizeF getLineSize(String s, Font f)
{
  Graphics g = fc.CreateGraphics();
  g.PageUnit = fc.MeasureUnit;
  SizeF size = g.MeasureString(s, f);
  g.Dispose();
  return size;
}

and after changing the label text set its size like this:

e.Box.BoundingRect = new RectangleF(
  e.Box.BoundingRect.Location,
  getLineSize("Line 1 has an extremely long line of text", e.Box.Font));
e.Box.FitSizeToText();

Make sure that the label's Y coordinate is always at the same distance from the icon's Y + Height so the text isn't pushed up or down. Also use the StringAlignment.Near as value of box.TextFormat.LineAlignment.

Handle the EnterInplaceEditMode event to get a reference to the TextBox control used for inplace editing. Then you could move or resize the TextBox to make sure it does not hide the icon and label, and set its font, to make sure it matches the label's text size. You can also attach your event handlers to the text box and resize it dynamically while the user types there.

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


I love YaBB 1G - SP1!

Posts: 15
Joined: Oct 23rd, 2005
Re: Group Two Boxes
Reply #2 - Dec 28th, 2005 at 2:59am
Print Post  
Stoyan,

I think I have it figured out but I don't know if this is the cleanest solution to solving the problem.  Any input would be helpful.

Code
Select All
m_SelectedTextBox.Text = frm.txtLabel.Text.Trim();;

m_SelectedTextBox.BoundingRect = new RectangleF( m_SelectedTextBox.BoundingRect.Location, GetLineSize( m_SelectedTextBox.Text, e.Box.Font ) );

// Center the label under the icon node
RectangleF rcNode = ( m_SelectedTextBox.MasterGroup.MainObject as Box ).BoundingRect;
RectangleF rc = m_SelectedTextBox.BoundingRect;
rc.X = rcNode.X + rcNode.Width / 2 - rc.Width / 2;

// Match any newlines in the text to adjust the height of the label
int height = 5;
MatchCollection mc = Regex.Matches( m_SelectedTextBox.Text, "\r\n" );

if ( mc.Count == 0 )
    height = ( mc.Count * 5 ) + 9;
else
    height = ( mc.Count * 5 ) + 5;

m_SelectedTextBox.BoundingRect = rc;
m_SelectedTextBox.Resize( rc.Width, height );
 



I also changed the TextFormat.LineAlignment to StringAlignment.Near.

I only have to lock the label box to prevent the user from moving it while still retaining the ability to double click it for edits.

Thanks for your help.
Brandon
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Group Two Boxes
Reply #3 - Dec 28th, 2005 at 6:50am
Print Post  
Brandon,

It seems that code is enough to set the label box size:

Code
Select All
e.Box.BoundingRect = new RectangleF(
   e.Box.BoundingRect.Location,
   getLineSize(e.Box.Text, e.Box.Font));
e.Box.FitSizeToText();
 



Replace "e.Box" above with "label". And then the label only has to be centered horizontally below the icon.

As for editing the text of a locked box - I guess you could call the box.BeginInplaceEdit() from a BoxDoubleClicked event handler or from a context menu command handler. That should work even if Locked = true.

Stoyan
  
Back to top
 
IP Logged
 
SWATalk
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 15
Joined: Oct 23rd, 2005
Re: Group Two Boxes
Reply #4 - Jan 4th, 2006 at 3:51am
Print Post  
Stoyan,

I think I have attaching two nodes nailed down but I have run into another problem.

I have an icon box and a label box grouped together to create one node.  I create another node in the same manner and create an arrow to the label box of the first node.  I rotate the second node that was created around the first node which positions the second node on top of the first node.  The arrow is set to automatically route which causes the arrow to attach to the top of the label box (index 4 of the handles).  This also causes the arrow to go through the icon node.

What I would like to do is detach the arrow once it is routed to index 4 and then attach it to the icon node at index 4.  I looked at the ArrowRouted, ArrowModifying and ArrowAttaching event but I couldn't find where I could get a reference to the handles to determine which handle was attached to the arrow. 

Is this the best way to solve the problem I'm experiencing?  If so, how can I get a reference to the handle to detach and reattach to the icon node?

I hope this makes sense.

Thanks in advance
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Group Two Boxes
Reply #5 - Jan 4th, 2006 at 5:36am
Print Post  
Brandon,

Use Arrow's class OrgnAnchor and DestAnchor properties to determine to which points an arrow is attached. Could you email me the diagram that shows the routing problem ?

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