using System; using System.Drawing; using System.Windows.Forms; namespace Core.Common.Controls.Dialogs { /// /// Base class for dialogs which should be derived in order to get a consistent look and feel. /// The base class ensures: /// /// /// the dialog is shown in the center of the parent form ( is set to ); /// /// /// no task bar icon is shown ( is set to false); /// /// /// no minimize control box item is shown ( is set to false); /// /// /// no maximize control box item is shown ( is set to false); /// /// /// the minimum width and minimum height are always set during creation time; /// /// /// the owning form is always set during creation time. /// /// /// public abstract partial class DialogBase : Form { private readonly IWin32Window owner; /// /// Constructs a new . /// /// The owner of the dialog. /// The icon to show in the control box. /// The minimum width of the dialog. /// The minimum height of the dialog. protected DialogBase(IWin32Window owner, Icon icon, int minWidth, int minHeight) { InitializeComponent(); this.owner = owner; Icon = icon; MinimumSize = new Size(minWidth, minHeight); } /// /// This method provides a new implementation of . /// In this new implementation the dialog is shown by passing the owner provided during creation time (. /// /// A . public new DialogResult ShowDialog() { return base.ShowDialog(owner); } protected override void OnShown(EventArgs e) { // Initialize the cancel button (as this cannot be done during creation time) CancelButton = GetCancelButton(); base.OnShown(e); } /// /// Gets the cancel button of the . /// /// The cancel button. /// By forcing derivatives to provide a cancel button, dialogs can be closed by hitting the ESC key on the keyboard. protected abstract Button GetCancelButton(); } }