Here's a way, following Kean Walmsley advice:
"Once again there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute()."
The CustomPalette class which exposes the control as property:
using Autodesk.AutoCAD.Windows;
using System;
namespace ModalModelessDialog
{
internal class CustomPaletteSet : PaletteSet
{
public UserControl1 GetPointControl { get; }
/// <summary>
/// Crée une nouvelle instance de CustomPaletteSet
/// </summary>
public CustomPaletteSet()
: base("Palette", "CMD_PALETTE", new Guid("{ABC4C47C-16A9-4C82-98CD-6636C02B1A4E}"))
{
Style =
PaletteSetStyles.ShowAutoHideButton |
PaletteSetStyles.ShowCloseButton |
PaletteSetStyles.ShowPropertiesMenu;
MinimumSize = new System.Drawing.Size(250, 150);
GetPointControl = new UserControl1();
Add("Get Point", GetPointControl);
}
}
}
The UserControl1 class with a read/write Point property and the Button1.Click handler which calls a custom command:
using Autodesk.AutoCAD.Geometry;
using System;
using System.Windows.Forms;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
namespace ModalModelessDialog
{
public partial class UserControl1 : UserControl
{
Point3d point;
public UserControl1()
{
InitializeComponent();
}
public Point3d Point
{
get { return point; }
set
{
point = value;
textBoxX.Text = $"{point.X:0.00}";
textBoxY.Text = $"{point.Y:0.00}";
textBoxZ.Text = $"{point.Z:0.00}";
}
}
private void button1_Click(object sender, EventArgs e)
{
var doc = AcAp.DocumentManager.MdiActiveDocument;
if (doc != null)
{
doc.SendStringToExecute("GetPointFromPaletteCommand ", false, false, true);
}
}
}
}
The commands class with a command to show the palette and another one to prompt the use to specify a point and pass the result to the palette user control property:
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using AcAp = Autodesk.AutoCAD.ApplicationServices.Core.Application;
namespace ModalModelessDialog
{
public class Commands
{
static CustomPaletteSet palette;
[CommandMethod("CMD_PALETTE")]
public void ShowPaletteSet()
{
if (palette == null)
palette = new CustomPaletteSet();
palette.Visible = true;
}
[CommandMethod("GetPointFromPaletteCommand")]
public void GetPointFromPaletteCommand()
{
var ed = AcAp.DocumentManager.MdiActiveDocument.Editor;
var ppo = new PromptPointOptions("\nPick a point: ");
ppo.AllowNone = true;
var ppr = ed.GetPoint(ppo);
if (ppr.Status == PromptStatus.OK)
{
palette.GetPointControl.Point = ppr.Value;
}
}
}
}