Hello!
I understand that we can show the context menu for a GoObject by overriding OnContextClick. How can I control the context menu for multiple selection?
Thanks,
Pradip
Hello!
I understand that we can show the context menu for a GoObject by overriding OnContextClick. How can I control the context menu for multiple selection?
Thanks,
Pradip
If you can’t put the code on a particular GoObject class, perhaps because there is more than one class to which it would apply, you should associate the code with the GoView, by implementing a GoView.ObjectContextClicked event handler. And maybe a GoView.BackgroundContextClicked event handler too, depending on what you want your application to do.
Remember to set GoView.ContextClickSingleSelection to false.
I tried the following code. It works correctly except that I don’t want the MessageBox 2 appearing. What am I missing?
public partial class Form1 : Form
{
private View view;
private Fb fb;
private Var var;
public Form1()
{
InitializeComponent();
InitGoObjects();
Controls.Add(view);
}
private void InitGoObjects()
{
view = new View();
view.Dock = DockStyle.Fill;
view.ContextClickSingleSelection = false;
fb = new Fb();
fb.Initialize(null, 0, "Top", "Bottom", 4, 2);
fb.Position = new PointF(40, 40);
view.Document.Add(fb);
var = new Var();
var.Text = "foo";
var.Position = new PointF(200, 80);
view.Document.Add(var);
}
}
public class Fb : GoGeneralNode
{
public override bool OnContextClick(GoInputEventArgs evt, GoView view)
{
MessageBox.Show("1");
return base.OnContextClick(evt, view);
}
}
public class Var : GoText
{
public override bool OnContextClick(GoInputEventArgs evt, GoView view)
{
MessageBox.Show("2");
return base.OnContextClick(evt, view);
}
}
public class View : GoView
{
public View()
{
ObjectContextClicked += new GoObjectEventHandler(View_ObjectContextClicked);
}
void View_ObjectContextClicked(object sender, GoObjectEventArgs e)
{
foreach (GoObject obj in Selection)
MessageBox.Show(obj.ToString());
}
}
Thanks in advance.
Pradip
I thought you were implying you couldn’t put the context menu code in the individual classes. So you should only have your code in the view’s ObjectContextClicked event handler.
In the above code, each class - Fb and Var - have custom context menus. Also, if I select both Fb and Var, then I want to show a different context menu. Extending this further, if I have 3 different classes selected, the context menu will be different from all the previous ones. How can I achieve this?
Sorry if I have not been clear earlier. Please let me know if you need further clarification.
Thanks,
Pradip
That’s right – you need to put all the context-menu creating code in the view’s handler, because you apparently want to decide what to show based on the Selection. So you can’t have any in overrides of GoObject.OnContextClick.