Hi everyone,
I’m developing a custom Grasshopper plugin and working on a component where I want a color menu to appear when clicking a color box. I am trying to recreate the swatch component behavior, however, when clicking in the canvas the Color picker Form does not appear in the coordinates of the click. My goal is to make match the top-right corner of the Color Picker Form with the coordinates of the click (as the swatch component). I do not know what is wrong with the code… but when clicking the window appears far from the click.
GH_ColourPicker picker = new GH_ColourPicker();
picker.Colour = comp.PrefixColors[i];
picker.ColourChanged += (s, args) =>
{
comp.UpdateColor(i, picker.Colour);
sender.Refresh();
};
// Show the picker as a popup form
Form pickerForm = new Form
{
FormBorderStyle = FormBorderStyle.None,
StartPosition = FormStartPosition.Manual,
TopMost = true,
ShowInTaskbar = false
};
picker.Dock = DockStyle.Fill;
pickerForm.Controls.Add(picker);
pickerForm.Size = new Size(picker.Width, picker.DesiredHeight);
// Position the picker so the TOP-RIGHT corner is at the mouse click position
Point screenPoint = sender.PointToScreen(new Point((int)e.CanvasLocation.X, (int)e.CanvasLocation.Y));
pickerForm.Location = new Point(screenPoint.X - pickerForm.Width, screenPoint.Y);
// Handle closing
picker.LostFocus += (s, args) => pickerForm.Close();
pickerForm.Deactivate += (s, args) => pickerForm.Close();
pickerForm.Show();
Does anyone know about how to do this?
Any tips or guidance would be greatly appreciated!
