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.
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

ContextMenu

Thread ID:

Created:

Updated:

Platform:

Replies:

75853 Aug 12,2008 11:21 AM UTC Aug 13,2008 09:25 AM UTC Windows Forms 5
loading
Tags: Diagram
Segey
Asked On August 12, 2008 11:21 AM UTC

Hi,
How in a class to use ContextMenu?
Here a code example:

[Serializable ()]
public class Spiral: Group
{
CurveNode m_node;
private ContextMenuStrip contextMenu;

public ContextMenuStrip ContextMenu
{
get {return contextMenu;}
set {contextMenu = value;}
}

private string name;
private int number;
private DateTime date;

public Spiral ()
{

PointF [] pt = {new PointF (130, 208), new PointF (240, 210), new PointF (270, 225), new PointF (245, 240), new PointF (220, 240),
new PointF (245, 240), new PointF (270,255), new PointF (245,275), new PointF (220,275),
new PointF (245,275), new PointF (270,290), new PointF (245,310), new PointF (220,310),
new PointF (245,310), new PointF (270,325), new PointF (245,345), new PointF (130,345)};

m_node = new CurveNode (pt);
m_node. Size = new SizeF (60, 70);
m_node. LineStyle. LineColor = Color. Maroon;
m_node. LineStyle. LineWidth = 2;
this. AppendChild (m_node);
}

protected Spiral (SerializationInfo info, StreamingContext context)
: base (info, context)
{

}

protected override void OnMouseDoubleClick ()
{
base. OnMouseDoubleClick ();
TestForm tf = new TestForm ();
tf. Visible = true;

}

public Spiral (Spiral src)
: base (src)
{

m_node = (CurveNode) this. GetChild (0);
}


public string NameT
{
get
{
return name;
}

set
{
name = value;
}
}
public int NumberT
{
get
{
return number;
}

set
{
number = value;
}
}
public DateTime DateT
{
get
{
return date;
}

set
{
date = value;
}
}
public override object Clone ()
{
return new Spiral (this);
}
}

How to add in a class a call of the contextual menu.
In advance thanks.


J.Nagarajan [Syncfusion]
Replied On August 12, 2008 12:02 PM UTC

Hi ,

Thanks for your interest in Syncfusion products.

If your intention is to bring the context menu, then you have to override OnMouseClick() method. Please refer to the below code snippet.

protected override void OnMouseClick()
{
Component component = this.Root as Component;
PointF ptMouseLocation = PointF.Empty;
if (component != null)
{
IContainer container = component.Container;
if (container != null)
{
foreach (Component comp in container.Components)
{
Controls.Diagram diagramControl = comp as Controls.Diagram;

if (diagramControl != null )
{
diagramControl.MouseUp += new MouseEventHandler(diagramControl_MouseUp);

}
}
}
}

}

void diagramControl_MouseUp(object sender, MouseEventArgs e)
{
Diagram.Controls.Diagram diagram = sender as Diagram.Controls.Diagram;
RectangleF m_Bounds = new RectangleF(e.X, e.Y, 1, 1);
if (e.Button == MouseButtons.Right && m_Bounds.IntersectsWith(this.BoundingRectangle))
{
if (diagram.Controller.SelectionList.Count > 0)
m_contextMenu.Show(diagram, new Point((int)diagram.Controller.MouseLocation.X, (int)diagram.Controller.MouseLocation.Y));
else
MessageBox.Show("Please select the Node");
}

}

Here is the working sample.

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

Please let me know if this helps.

Regards,
Nagaraj


Segey
Replied On August 12, 2008 12:26 PM UTC

Thanks for a prompt reply. But there is a problem if a component to take from a palette of tools then it gives out an error "Object reference not set to an instance of an object." As it to solve.
In advance thanks.


J.Nagarajan [Syncfusion]
Replied On August 12, 2008 12:53 PM UTC

Hi ,

Sorry for the inconvenience caused. This issue occured because the context menu is not instantiate in copy constructor. I have modified the sample and attached here.

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

Please refer to the sample and let me know if this helps.

Another way you can add the below code snippet in the copy constructor to resolve this issue.

public MySymbol(MySymbol src)
: base(src)
{
// update reference
m_node = (CurveNode)this.GetChild(0);
this.m_contextMenu = src.m_contextMenu;
}

Please try this and let me know if this helps.

Thanks,
Nagaraj


Segey
Replied On August 13, 2008 09:13 AM UTC

Thanks a lot for help. Whether It is possible to connect with you on messenger or on mail agent or icq at you is what or fast contacts for support of fast communication
Can you send you fast contact in may mail

In advance thanks


J.Nagarajan [Syncfusion]
Replied On August 13, 2008 09:25 AM UTC

Hi ,

Thanks for the update. Please open a new Direct trac incident if you have any other concern. We will glad to assist you quickly. Please use the below link to create a new Direct trac incident.

https://www.syncfusion.com/Support/DirectTrac/logon.aspx?URL=/Support/DirectTrac/default.aspx

Thanks,
Nagaraj


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;