using wpf = System.Windows;
using acad = Autodesk.AutoCAD.ApplicationServices.Application;
...
const Int32 offset_x = 0;
const Int32 offset_y = 40;
static Double _x, _y;
...
public void Initialize() {
// Create new WPF window for using its as context menu
wpf
.Window win
= new wpf
.Window(); wpf
.Controls.StackPanel sp
= new wpf
.Controls.StackPanel();
wpf
.Controls.MenuItem _clear
= new wpf
.Controls.MenuItem(); _clear.Header = "Clear result";
_clear.Click += mi_Click;
sp.Children.Add(_clear);
wpf
.Controls.MenuItem _report
= new wpf
.Controls.MenuItem(); _report.Header = "Show Report";
sp.Children.Add(_report);
win.Content = sp;
win.SizeToContent = wpf.SizeToContent.WidthAndHeight;
win.WindowStyle = wpf.WindowStyle.None;
win.ResizeMode = wpf.ResizeMode.NoResize;
win.WindowStartupLocation = wpf.WindowStartupLocation.Manual;
_x = System.Windows.Forms.Cursor.Position.X;
_y = System.Windows.Forms.Cursor.Position.Y;
win.Activated += win_Activated;
win.Deactivated += win_Deactivated;
acad.ShowModelessWindow(win);
}
void win_Activated(object sender, EventArgs e) {
wpf.Window win = (wpf.Window)sender;
win.Left = _x - win.ActualWidth - offset_x;
win.Top = _y - win.ActualHeight - offset_y;
}
void win_Deactivated(object sender, EventArgs e) {
((wpf.Window)sender).Close();
}
void mi_Click(object sender, wpf.RoutedEventArgs e) {
history.Reset();
wpf.Window win = ((wpf.Window)((wpf.Controls.StackPanel)
((wpf.Controls.MenuItem)sender).Parent).Parent);
win.Deactivated -= win_Deactivated;
win.Close();
}
void clear_Click(object sender, EventArgs e) {
history.Reset();
}