The CommandMethods class where the PaletteSet is created
using System; using Autodesk.AutoCAD.Runtime; using Autodesk.AutoCAD.Windows; [assembly: CommandClass(typeof(ZoomFromModalDialogFromPalette.CommandMethods))] namespace ZoomFromModalDialogFromPalette { public class CommandMethods { private static PaletteSet ps; [CommandMethod("Test", CommandFlags.Modal)] public void Test() { if (ps == null) { ps = new PaletteSet("zoom", new Guid("{BEE26D4D-DD21-4B01-8080-7B6E38AD3FBA}")); ps.Style = PaletteSetStyles.ShowPropertiesMenu | PaletteSetStyles.ShowAutoHideButton | PaletteSetStyles.ShowCloseButton; ps.Name = "Test Zoom"; ps.Add("Zoom", new ZoomControl()); } ps.Visible = true; } } }
The ZoomControl class with the btnDialog event handler
using System; using System.Windows.Forms; using AcAp = Autodesk.AutoCAD.ApplicationServices.Application; namespace ZoomFromModalDialogFromPalette { public partial class ZoomControl : UserControl { public ZoomControl() { InitializeComponent(); } private void btnDialog_Click(object sender, EventArgs e) { Dialog dlg = new Dialog(); AcAp.ShowModalDialog(dlg); } } }
The Dialog class in which the btnZoom event handler is defined
using System; using System.Windows.Forms; using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD.EditorInput; using Autodesk.AutoCAD.Geometry; using AcAp = Autodesk.AutoCAD.ApplicationServices.Application; namespace ZoomFromModalDialogFromPalette { public partial class Dialog : Form { public Dialog() { InitializeComponent(); } private void btnZoom_Click(object sender, EventArgs e) { Document doc = AcAp.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; using (ViewTableRecord view = ed.GetCurrentView()) { Matrix3d worldToEye = (Matrix3d.Rotation(-view.ViewTwist, view.ViewDirection, view.Target) * Matrix3d.Displacement(view.Target - Point3d.Origin) * Matrix3d.PlaneToWorld(view.ViewDirection)).Inverse(); Extents3d ext = (short)AcAp.GetSystemVariable("cvport") == 1 ? new Extents3d(db.Pextmin, db.Pextmax) : new Extents3d(db.Extmin, db.Extmax); ext.TransformBy(worldToEye); view.Width = ext.MaxPoint.X - ext.MinPoint.X; view.Height = ext.MaxPoint.Y - ext.MinPoint.Y; view.CenterPoint = new Point2d( (ext.MaxPoint.X + ext.MinPoint.X) / 2.0, (ext.MaxPoint.Y + ext.MinPoint.Y) / 2.0); ed.SetCurrentView(view); } } } }