/// <summary> /// Raises a callback. /// </summary> /// <param name="e">The <see cref="VistaTaskDialogNotificationArgs"/> instance containing the event data.</param> protected void OnCallback(VistaTaskDialogNotificationArgs e) { if (options.Callback != null) { HandleCallbackReturn(e, options.Callback(this, e, options.CallbackData)); } }
private bool taskDialog_Callback2(IActiveTaskDialog dialog, VistaTaskDialogNotificationArgs args, object callbackData) { bool result = false; switch (args.Notification) { case VistaTaskDialogNotification.Created: _downloadedPercent = 0; dialog.SetProgressBarRange(0, 100); break; case VistaTaskDialogNotification.ButtonClicked: if (args.ButtonIndex == 0) { _downloadTimerReset = true; result = true; // prevent dialog from closing } break; case VistaTaskDialogNotification.Timer: if (_downloadedPercent < 100 && _downloadRandomizer.Next(0, 3) == 0) { _downloadedPercent++; dialog.SetProgressBarPosition(_downloadedPercent); dialog.SetWindowTitle( String.Format( "{0:P0} Complete Downloading File...", (Convert.ToDouble(_downloadedPercent) / 100d))); } else if (_downloadedPercent >= 100) { // Download finished // Close the dialog by simulating a click on the cancel button dialog.ClickCustomButton(1); // Alternative method: //dialog.ClickButton(TaskDialog.GetButtonIdForCustomButton(1)); } // 131072 = 1 MB in bytes dialog.SetContent( String.Format( "Time elapsed: {0} | Download rate: {1}/s", TimeSpan.FromMilliseconds(args.TimerTickCount).ToString(@"h\:mm\:ss"), GetByteScaleSizeBinary(_downloadRandomizer.Next(0, 131072)))); if (_downloadTimerReset) { // TRUE: reset tick count (args.TimerTickCount) result = true; _downloadTimerReset = false; } break; } return(result); }
/// <summary> /// Notifies any callback handlers that the dialog has been created but not yet shown. /// </summary> public void NotifyCreated() { var args = new VistaTaskDialogNotificationArgs(); args.Config = this.options; args.Notification = VistaTaskDialogNotification.Created; OnCallback(args); }
private void CallbackTimer_Tick(object sender, EventArgs e) { var args = new VistaTaskDialogNotificationArgs(); args.Config = this.options; args.Notification = VistaTaskDialogNotification.Timer; args.TimerTickCount = Convert.ToUInt32(Math.Round(DateTime.Now.Subtract(_callbackTimerStart).TotalMilliseconds, 0)); OnCallback(args); }
/// <summary> /// Notifies any callback handlers that the dialog is destroyed. /// </summary> public void NotifyClosed() { if (options.EnableCallbackTimer) { _callbackTimer.Stop(); } var args = new VistaTaskDialogNotificationArgs(); args.Config = this.options; args.Notification = VistaTaskDialogNotification.Destroyed; OnCallback(args); }
private bool taskDialog_Callback1(IActiveTaskDialog dialog, VistaTaskDialogNotificationArgs args, object callbackData) { if (args.Notification == VistaTaskDialogNotification.HyperlinkClicked) { try { Process.Start(args.Hyperlink); } catch { } } return(false); }
private bool taskDialog_Callback1(IActiveTaskDialog dialog, VistaTaskDialogNotificationArgs args, object callbackData) { bool result = false; switch (args.Notification) { case VistaTaskDialogNotification.HyperlinkClicked: //result = true; // prevents HREF from being processed automatically by ShellExecute MessageBox.Show("Hyperlink clicked: " + args.Hyperlink); break; } return(result); }
/// <summary> /// Notifies any callback handlers that the close button was clicked. /// </summary> public void NotifyClosing() { // Caused by clicking X or Alt+F4 or Esc, so notify via callback if (!_requestingClose) { var args = new VistaTaskDialogNotificationArgs(); args.Config = this.options; args.Notification = VistaTaskDialogNotification.ButtonClicked; args.ButtonId = (int)TaskDialogSimpleResult.Cancel; args.ButtonIndex = TaskDialog.GetButtonIndexForCommonButton(options.CommonButtons, args.ButtonId); //args.ButtonIndex = -1; // See TaskDialogInterop.cs PrivateCallback method for why //the above line is commented out OnCallback(args); } }
private void HandleCallbackReturn(VistaTaskDialogNotificationArgs e, bool returnValue) { switch (e.Notification) { default: // all others // Return value ignored according to MSDN break; case VistaTaskDialogNotification.ButtonClicked: // TRUE : prevent dialog from closing _preventClose = returnValue; break; case VistaTaskDialogNotification.Timer: // TRUE : reset tickcount if (returnValue) { _callbackTimerStart = DateTime.Now; } break; } }