using System.Drawing;
using System.Windows.Forms;
using WindowsFormsAero.TaskDialog;
namespace OnTopReplica {
partial class MainForm {
///
/// Opens the context menu.
///
/// Optional position of the mouse, relative to which the menu is shown.
public void OpenContextMenu(Point? position) {
Point menuPosition = MousePosition;
if (position.HasValue)
menuPosition = position.Value;
if (FullscreenManager.IsFullscreen) {
menuFullscreenContext.Show(menuPosition);
}
else {
menuContext.Show(menuPosition);
}
}
///
/// Gets the window's vertical chrome size.
///
public int ChromeBorderVertical {
get {
if (IsChromeVisible)
return SystemInformation.FrameBorderSize.Height;
else
return 0;
}
}
///
/// Gets the window's horizontal chrome size.
///
public int ChromeBorderHorizontal {
get {
if (IsChromeVisible)
return SystemInformation.FrameBorderSize.Width;
else
return 0;
}
}
///
/// Displays an error task dialog.
///
/// Main instruction of the error dialog.
/// Detailed informations about the error.
/// Expanded error codes/messages.
private void ShowErrorDialog(string mainInstruction, string explanation, string errorMessage) {
TaskDialog dlg = new TaskDialog(mainInstruction, Strings.ErrorGenericTitle, explanation) {
CommonIcon = TaskDialogIcon.Stop,
IsExpanded = false
};
if (!string.IsNullOrEmpty(errorMessage)) {
dlg.ExpandedInformation = Strings.ErrorGenericInfoText + errorMessage;
dlg.ExpandedControlText = Strings.ErrorGenericInfoButton;
}
dlg.Show(this);
}
///
/// Ensures that the main form is visible (either closing the fullscreen mode or reactivating from task icon).
///
public void EnsureMainFormVisible() {
//Reset special modes
FullscreenManager.SwitchBack();
ClickThroughEnabled = false;
Opacity = 1.0;
//Restore main form in a platform-dependent method
Program.Platform.RestoreForm(this);
}
///
/// Opens a confirmation dialog to confirm whether to reset the main form or not.
///
public void ResetMainFormWithConfirmation() {
var dlg = new TaskDialog(Strings.AskReset, Strings.AskResetTitle, Strings.AskResetContent);
dlg.UseCommandLinks = true;
dlg.CustomButtons = new CustomButton[] {
new CustomButton(Result.OK, Strings.AskResetButtonOk),
new CustomButton(Result.Cancel, Strings.ButtonCancel)
};
dlg.CommonIcon = TaskDialogIcon.Information;
if (dlg.Show(this).CommonButton == Result.OK) {
ResetMainForm();
}
}
///
/// Resets the main form to its initial state.
///
public void ResetMainForm() {
//Reset form settings
UnsetThumbnail();
CloseSidePanel();
//Reset location and size (edge of the screen, min size)
Point nuLoc = Screen.PrimaryScreen.WorkingArea.Location;
nuLoc.Offset(40, 40);
Location = nuLoc;
Size = new Size(240, 220);
this.Show();
this.Activate();
}
}
}