dialog.Close(); dialog.Dispose();
DialogResult.OK;
public partial class BetterDialog : Form { /// <summary> /// Create a special dialog in the style of Windows XP or Vista. A dialog has a custom icon, an optional large /// title in the form, body text, window text, and one or two custom-labeled buttons. /// </summary> /// <param name="titleString">This string will be displayed in the system window frame.</param> /// <param name="bigString">This is the first string to appear in the dialog. It will be most prominent.</param> /// <param name="smallString">This string appears either under the big string, or is null, which means it is /// not displayed at all.</param> /// <param name="leftButton">This is the left button, typically the "accept" button--label it with an /// action verb (or "OK").</param> /// <param name="rightButton">The right button--typically "Cancel", but could be "No".</param> /// <param name="iconSet">An image to be displayed on the left side of the dialog. Should be 32 x 32 pixels.</param> static public DialogResult ShowDialog(string title, string largeHeading, string smallExplanation,string leftButton, string rightButton, Image iconSet) { //title, largeHeading,smallExplanation, leftButton, rightButton, iconSet using (BetterDialog dialog = new BetterDialog(title, largeHeading, smallExplanation, leftButton,rightButton, iconSet)) { DialogResult result = dialog.ShowDialog(); return result; } } /// <summary> /// The private constructor. This is only called by the static method ShowDialog. /// </summary> private BetterDialog(string title, string largeHeading, string smallExplanation,string leftButton, string rightButton, Image iconSet) { this.Font = SystemFonts.MessageBoxFont; this.ForeColor = SystemColors.WindowText; InitializeComponent(); // set our width and height to these values (redundant, but who cares?) this.Width = 350; this.Height = 150; using (Graphics graphics = this.CreateGraphics()) { SizeF smallSize; SizeF bigSize; if (string.IsNullOrEmpty(smallExplanation) == false) { if (SystemFonts.MessageBoxFont.FontFamily.Name == "Segoe UI") { // use the special, windows-vista font style if we are running vista (using Segoe UI). label1.ForeColor = Color.FromArgb(0, 51, 153); // [ColorTranslator.FromHtml("#003399")] label1.Font = new Font("Segoe UI", 12.0f, FontStyle.Regular, GraphicsUnit.Point); // bigger for vista/aero this.Width += 50; label1.Width += 50; label2.Width += 50; smallSize = graphics.MeasureString(smallExplanation, this.Font, this.label2.Width); bigSize = graphics.MeasureString(largeHeading, label1.Font, this.label1.Width); this.Height = (int)smallSize.Height + 158; // add in a little margin on the top as well pictureBox1.Margin = new Padding(pictureBox1.Margin.Left, pictureBox1.Margin.Top + 6, pictureBox1.Margin.Right, pictureBox1.Margin.Bottom); } else { // might want to special case the old, MS Sans Serif font. // use the regular
Close();
using (BetterDialog dialog = new BetterDialog(title, largeHeading, smallExplanation, leftButton,rightButton, iconSet)) { DialogResult result = dialog.ShowDialog(); Thread.Sleep(1000); dialog.Close(); return result; }
<pre>private void timer1_Tick(object sender, EventArgs e) { Close(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)