Page Index Toggle Pages: 1 Send TopicPrint
Hot Topic (More than 10 Replies) Event on image (Read 4841 times)
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Event on image
Nov 11th, 2008 at 7:42pm
Print Post  
Hi,

I'm trying to create a "collapse node" option that will hide all rows from a specific table when the user clicks on an image next to caption.

I am wondering if there is an EventHandler when the user clicks on the image or if I need to create a ShapeNode button and handle clicks on it using diagram.NodeClicked event handler?

Also, if I need to use the 2nd technique, how do I know which table this collapseButton is linked to?

Thanks,
Marie
« Last Edit: Dec 9th, 2008 at 2:53pm by marie »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event on image
Reply #1 - Nov 11th, 2008 at 8:18pm
Print Post  
Hi,

If you use custom drawing to display the image at a specific position inside the caption area, you could handle the NodeClicked event for the table and check if the mouse pointer is inside the image rectangle using the RectangleF.Contains mehtod. If the image is an attached ShapeNode object, then you can access the table through the ShapeNode.MasterGroup.MainItem property.

I hope htat helps,
Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #2 - Nov 11th, 2008 at 8:31pm
Print Post  
Hi,

I'm not using custom drawing (not yet Wink). It doesn't really matter to me what code I'm using. For now, I have the following to add the image to the table (comes from Entities exemple):
Code
Select All
Group btnsGroup = diagram.Factory.CreateGroup(t);
ShapeNode collapseBtn = new ShapeNode(diagram);
collapseBtn.Transparent = true;
collapseBtn.Image = Properties.Resources.CollapseNode;
collapseBtn.ImageAlign = ImageAlign.TopLeft;
btnsGroup.AttachToCorner(collapseBtn, 0);
collapseBtn.Locked = true;
this.diagram.Nodes.Add(collapseBtn);
collapseBtn.Tag = "Collapse"; 



However, when I use the EventHandler diagram.NodeClicked, it doesn't get called for my shape nodes, only for the table. How do I know if the user clicked the ShapeNode and not somewhere else in the table?

Thanks,
Marie
« Last Edit: Dec 16th, 2008 at 3:45pm by marie »  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event on image
Reply #3 - Nov 11th, 2008 at 8:45pm
Print Post  
Hi,

The ERM Diagram page in the fcdemo sample uses the same kind of attached nodes as buttons; if you open that step and click the red X button, doesn't it delete the table?

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #4 - Nov 11th, 2008 at 9:00pm
Print Post  
Hi,

Yes it does. Thanks. I was using the standalone Entity example.

Regards,
Marie
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #5 - Nov 11th, 2008 at 9:23pm
Print Post  
Hi,

The example is so big and I can't find what settings are wrong in my code. Is there a setting somewhere to tell to call the child? Because now I'm using the same code to create tables than ERM diagram, but NodeClicked is still called on the table itself and not on the ShapeNode s.

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event on image
Reply #6 - Nov 12th, 2008 at 11:45am
Print Post  
Hi,

I have added a NodeClicked handler to the Entities sample and this works fine:

Code
Select All
private void diagram_NodeClicked(object sender, NodeEventArgs e)
{
	ShapeNode shape = e.Node as ShapeNode;
	if (shape != null)
		MessageBox.Show("shape clicked");

	TableNode table = e.Node as TableNode;
	if (table != null)
		MessageBox.Show("table clicked");
}
 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #7 - Nov 12th, 2008 at 3:14pm
Print Post  
Hi,

I found what the problem was. I had moved the diagram.Nodes.Add(t); command to the end of the button1_Click method. That was hiding the button when the node was not selected and it is why (for some reason) the event didn't get raised for the button.

Thanks,
Marie
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #8 - Nov 12th, 2008 at 6:33pm
Print Post  
Hi,

Another question related to that:
I added a shapeNode using the following:

Code
Select All
ShapeNode btn = diagram.Factory.CreateShapeNode(x, y, image.Width, image.Height);
btn.Transparent = true;
btn.Image = image;
btn.ImageAlign = ImageAlign.Center;
btn.AttachTo(node, attType);
btn.Locked = true;
btn.Tag = tag; 



How do I remove that btn after? I tried to detach it, but that just removes it from the parent. How do I tell the diagram that this is deprecated?

Edit: Anything else needed other than diagram.Nodes.remove(btn) ? I want it to be a clean deletion...

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event on image
Reply #9 - Nov 12th, 2008 at 6:43pm
Print Post  
Hi,

Calling diagram.Nodes.Remove() should be enough.

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #10 - Nov 13th, 2008 at 3:35pm
Print Post  
Hi Stoyan,

I have another question. How can I get the selected cell in a tableNode?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event on image
Reply #11 - Nov 13th, 2008 at 3:50pm
Print Post  
Hi Marie,

The control does not support selection of cells, but you might implement it by handling the CellClicked event and changing the cell color.

Stoyan
  
Back to top
 
IP Logged
 
marie
Full Member
***
Offline



Posts: 147
Joined: Nov 11th, 2008
Re: Event on image
Reply #12 - Nov 13th, 2008 at 4:44pm
Print Post  
Hi Stoyan,

Thanks. If I decide to change the cell color, how do I know when to change it back to its original color when it lost selection? I don't find any CellUnclicked (!) event... Do I need to reset the last selected cell color in all other "click" events (Clicked, LinkClicked, NodeClicked, etc.)?

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


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Event on image
Reply #13 - Nov 13th, 2008 at 5:42pm
Print Post  
If you allow cell selection only in a selected table, you could reset the cell from the NodeDeselected event for that table, when a different item is clicked, or from CellClicked, when another cell in the same table is clicked.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint