// task dialog callback that uses the callback data member; // does not use mpCallbackData public bool TaskDialogCallbackUsingMemberData( ActiveTaskDialog taskDialog, TaskDialogCallbackArgs args, object mpCallbackData) { // use the helper method to do the actual processing return(handleCallback(taskDialog, args, memberCallbackData)); }
private bool Callback(ActiveTaskDialog taskDialog, TaskDialogNotificationArgs args, object callbackData) { using (var niActiveTaskDialog = new NiActiveTaskDialog(this, taskDialog)) { switch (args.Notification) { case TaskDialogNotification.Created: _connectionPoint.ForAll(p => p.OnCreated(niActiveTaskDialog)); return(false); case TaskDialogNotification.ButtonClicked: bool close = false; _connectionPoint.ForAll(p => p.OnButtonClick(niActiveTaskDialog, args.ButtonId, ref close)); return(close); case TaskDialogNotification.HyperlinkClicked: _connectionPoint.ForAll(p => p.OnHyperlinkClicked(niActiveTaskDialog, args.Hyperlink)); return(false); case TaskDialogNotification.Timer: bool resetTimer = false; _connectionPoint.ForAll(p => p.OnTimer(niActiveTaskDialog, (int)args.TimerTickCount, ref resetTimer)); return(resetTimer); case TaskDialogNotification.Destroyed: _connectionPoint.ForAll(p => p.OnDestroyed(niActiveTaskDialog)); return(false); case TaskDialogNotification.RadioButtonClicked: _connectionPoint.ForAll(p => p.OnRadioButtonClicked(niActiveTaskDialog, args.ButtonId)); return(false); case TaskDialogNotification.DialogConstructed: _connectionPoint.ForAll(p => p.OnDialogConstructed(niActiveTaskDialog)); return(false); case TaskDialogNotification.VerificationClicked: _connectionPoint.ForAll(p => p.OnVerificationClicked(niActiveTaskDialog, args.VerificationFlagChecked)); return(false); case TaskDialogNotification.Help: _connectionPoint.ForAll(p => p.OnHelp(niActiveTaskDialog)); return(false); case TaskDialogNotification.ExpandoButtonClicked: _connectionPoint.ForAll(p => p.OnExpandoButtonClicked(niActiveTaskDialog, args.Expanded)); return(false); default: throw new InvalidOperationException(); } } }
///////////////////////////////////////////////////////////////// // This sample uses a local instance of the callback data. // Since the TaskDialog class needs to convert the callback data // to an IntPtr to pass it across the managed-unmanaged divide, // be sure to convert it to an IntPtr before passing it off // to the TaskDialog instance. // // This case requires more code than the member-based sample // below, but is useful when a callback is shared // between multiple task dialogs. ///////////////////////////////////////////////////////////////// // task dialog callback that uses the mpCallbackData argument public bool TaskDialogCallback(ActiveTaskDialog taskDialog, TaskDialogCallbackArgs args, object mpCallbackData) { // convert the callback data from an IntPtr to the actual // object using GCHandle GCHandle callbackDataHandle = GCHandle.FromIntPtr((IntPtr)mpCallbackData); MyData callbackData = (MyData)callbackDataHandle.Target; // use the helper method to do the actual processing return(handleCallback(taskDialog, args, callbackData)); }
public NiActiveTaskDialog(NiTaskDialog taskDialog, ActiveTaskDialog active) { _taskDialog = taskDialog; _active = active; }
// helper method for processing the callback both in the // data-member case and the callback argument case private bool handleCallback(ActiveTaskDialog taskDialog, TaskDialogCallbackArgs args, MyData callbackData) { // This gets called continuously until we finished completely if (args.Notification == TaskDialogNotification.Timer) { // To make it longer we do some delay in every second call if (callbackData.delay) { System.Threading.Thread.Sleep(1000); } else { callbackData.counter += 10; taskDialog.SetProgressBarRange(0, 100); taskDialog.SetProgressBarPosition( callbackData.counter); // This is the main action - adding 100 lines 1 by 1 Database db = HostApplicationServices.WorkingDatabase; Transaction tr = db.TransactionManager.TopTransaction; BlockTable bt = (BlockTable)tr.GetObject( db.BlockTableId, OpenMode.ForRead); BlockTableRecord ms = (BlockTableRecord)tr.GetObject( bt[BlockTableRecord.ModelSpace], OpenMode.ForWrite); Line ln = new Line( new Point3d(0, callbackData.counter, 0), new Point3d(10, callbackData.counter, 0)); ms.AppendEntity(ln); tr.AddNewlyCreatedDBObject(ln, true); // To make it appear on the screen - might be a bit costly tr.TransactionManager.QueueForGraphicsFlush(); acApp.DocumentManager.MdiActiveDocument.Editor.Regen(); // We are finished if (callbackData.counter >= 100) { // We only have a cancel button, // so this is what we can press taskDialog.ClickButton( (int)WinForms.DialogResult.Cancel); return(true); } } callbackData.delay = !callbackData.delay; } else if ( args.Notification == TaskDialogNotification.ButtonClicked) { // we only have a cancel button if (args.ButtonId == (int)WinForms.DialogResult.Cancel) { return(false); } } return(true); }