DarkDialog & DarkMessageBox

Added a dynamic dialog window and message box.
This commit is contained in:
Robin 2015-09-18 11:40:14 +01:00
parent e0be7e0d0a
commit 27a5ad0c6e
16 changed files with 1135 additions and 5 deletions

View File

@ -25,4 +25,23 @@
Vertical,
Horizontal
}
public enum DarkDialogButton
{
Ok,
Close,
OkCancel,
YesNo,
YesNoCancel,
AbortRetryIgnore,
RetryCancel
}
public enum DarkMessageBoxIcon
{
None,
Information,
Warning,
Error
}
}

View File

@ -34,9 +34,6 @@ namespace DarkUI
}
}
[Category("Layout")]
[Description("Enables automatic resizing based on font size. Note that this is only valid for label controls that do not wrap text.")]
[DefaultValue(true)]
public new bool AutoSize
{
get { return base.AutoSize; }

View File

@ -35,6 +35,7 @@
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Config\Colors.cs" />
@ -66,14 +67,31 @@
</Compile>
<Compile Include="Controls\EventArgs\ScrollValueEventArgs.cs" />
<Compile Include="Extensions\BitmapExtensions.cs" />
<Compile Include="Forms\DarkDialog.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\DarkDialog.Designer.cs">
<DependentUpon>DarkDialog.cs</DependentUpon>
</Compile>
<Compile Include="Forms\DarkForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\DarkMessageBox.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Forms\DarkMessageBox.Designer.cs">
<DependentUpon>DarkMessageBox.cs</DependentUpon>
</Compile>
<Compile Include="Icons\MenuIcons.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MenuIcons.resx</DependentUpon>
</Compile>
<Compile Include="Icons\MessageBoxIcons.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>MessageBoxIcons.resx</DependentUpon>
</Compile>
<Compile Include="Icons\ScrollIcons.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@ -84,11 +102,22 @@
<Compile Include="Renderers\DarkToolStripRenderer.cs" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Forms\DarkDialog.resx">
<DependentUpon>DarkDialog.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Forms\DarkMessageBox.resx">
<DependentUpon>DarkMessageBox.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Icons\MenuIcons.resx">
<Generator>PublicResXFileCodeGenerator</Generator>
<LastGenOutput>MenuIcons.Designer.cs</LastGenOutput>
<CustomToolNamespace>DarkUI</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="Icons\MessageBoxIcons.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>MessageBoxIcons.Designer.cs</LastGenOutput>
<CustomToolNamespace>DarkUI</CustomToolNamespace>
</EmbeddedResource>
<EmbeddedResource Include="Icons\ScrollIcons.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ScrollIcons.Designer.cs</LastGenOutput>
@ -113,6 +142,15 @@
<ItemGroup>
<None Include="Resources\scrollbar_arrow_standard.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\error.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\info.png" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\warning.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

186
DarkUI/Forms/DarkDialog.Designer.cs generated Normal file
View File

@ -0,0 +1,186 @@
namespace DarkUI
{
partial class DarkDialog
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.pnlFooter = new System.Windows.Forms.Panel();
this.flowInner = new System.Windows.Forms.FlowLayoutPanel();
this.btnOk = new DarkUI.DarkButton();
this.btnCancel = new DarkUI.DarkButton();
this.btnClose = new DarkUI.DarkButton();
this.btnYes = new DarkUI.DarkButton();
this.btnNo = new DarkUI.DarkButton();
this.btnAbort = new DarkUI.DarkButton();
this.btnRetry = new DarkUI.DarkButton();
this.btnIgnore = new DarkUI.DarkButton();
this.pnlFooter.SuspendLayout();
this.flowInner.SuspendLayout();
this.SuspendLayout();
//
// pnlFooter
//
this.pnlFooter.Controls.Add(this.flowInner);
this.pnlFooter.Dock = System.Windows.Forms.DockStyle.Bottom;
this.pnlFooter.Location = new System.Drawing.Point(0, 357);
this.pnlFooter.Name = "pnlFooter";
this.pnlFooter.Size = new System.Drawing.Size(767, 45);
this.pnlFooter.TabIndex = 1;
//
// flowInner
//
this.flowInner.Controls.Add(this.btnOk);
this.flowInner.Controls.Add(this.btnCancel);
this.flowInner.Controls.Add(this.btnClose);
this.flowInner.Controls.Add(this.btnYes);
this.flowInner.Controls.Add(this.btnNo);
this.flowInner.Controls.Add(this.btnAbort);
this.flowInner.Controls.Add(this.btnRetry);
this.flowInner.Controls.Add(this.btnIgnore);
this.flowInner.Dock = System.Windows.Forms.DockStyle.Right;
this.flowInner.Location = new System.Drawing.Point(104, 0);
this.flowInner.Name = "flowInner";
this.flowInner.Padding = new System.Windows.Forms.Padding(10);
this.flowInner.Size = new System.Drawing.Size(663, 45);
this.flowInner.TabIndex = 10014;
//
// btnOk
//
this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
this.btnOk.Location = new System.Drawing.Point(10, 10);
this.btnOk.Margin = new System.Windows.Forms.Padding(0);
this.btnOk.Name = "btnOk";
this.btnOk.Padding = new System.Windows.Forms.Padding(5);
this.btnOk.Size = new System.Drawing.Size(75, 26);
this.btnOk.TabIndex = 3;
this.btnOk.Text = "Ok";
//
// btnCancel
//
this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnCancel.Location = new System.Drawing.Point(85, 10);
this.btnCancel.Margin = new System.Windows.Forms.Padding(0);
this.btnCancel.Name = "btnCancel";
this.btnCancel.Padding = new System.Windows.Forms.Padding(5);
this.btnCancel.Size = new System.Drawing.Size(75, 26);
this.btnCancel.TabIndex = 4;
this.btnCancel.Text = "Cancel";
//
// btnClose
//
this.btnClose.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btnClose.Location = new System.Drawing.Point(160, 10);
this.btnClose.Margin = new System.Windows.Forms.Padding(0);
this.btnClose.Name = "btnClose";
this.btnClose.Padding = new System.Windows.Forms.Padding(5);
this.btnClose.Size = new System.Drawing.Size(75, 26);
this.btnClose.TabIndex = 5;
this.btnClose.Text = "Close";
//
// btnYes
//
this.btnYes.DialogResult = System.Windows.Forms.DialogResult.Yes;
this.btnYes.Location = new System.Drawing.Point(235, 10);
this.btnYes.Margin = new System.Windows.Forms.Padding(0);
this.btnYes.Name = "btnYes";
this.btnYes.Padding = new System.Windows.Forms.Padding(5);
this.btnYes.Size = new System.Drawing.Size(75, 26);
this.btnYes.TabIndex = 6;
this.btnYes.Text = "Yes";
//
// btnNo
//
this.btnNo.DialogResult = System.Windows.Forms.DialogResult.No;
this.btnNo.Location = new System.Drawing.Point(310, 10);
this.btnNo.Margin = new System.Windows.Forms.Padding(0);
this.btnNo.Name = "btnNo";
this.btnNo.Padding = new System.Windows.Forms.Padding(5);
this.btnNo.Size = new System.Drawing.Size(75, 26);
this.btnNo.TabIndex = 7;
this.btnNo.Text = "No";
//
// btnAbort
//
this.btnAbort.DialogResult = System.Windows.Forms.DialogResult.Abort;
this.btnAbort.Location = new System.Drawing.Point(385, 10);
this.btnAbort.Margin = new System.Windows.Forms.Padding(0);
this.btnAbort.Name = "btnAbort";
this.btnAbort.Padding = new System.Windows.Forms.Padding(5);
this.btnAbort.Size = new System.Drawing.Size(75, 26);
this.btnAbort.TabIndex = 8;
this.btnAbort.Text = "Abort";
//
// btnRetry
//
this.btnRetry.DialogResult = System.Windows.Forms.DialogResult.Retry;
this.btnRetry.Location = new System.Drawing.Point(460, 10);
this.btnRetry.Margin = new System.Windows.Forms.Padding(0);
this.btnRetry.Name = "btnRetry";
this.btnRetry.Padding = new System.Windows.Forms.Padding(5);
this.btnRetry.Size = new System.Drawing.Size(75, 26);
this.btnRetry.TabIndex = 9;
this.btnRetry.Text = "Retry";
//
// btnIgnore
//
this.btnIgnore.DialogResult = System.Windows.Forms.DialogResult.Ignore;
this.btnIgnore.Location = new System.Drawing.Point(535, 10);
this.btnIgnore.Margin = new System.Windows.Forms.Padding(0);
this.btnIgnore.Name = "btnIgnore";
this.btnIgnore.Padding = new System.Windows.Forms.Padding(5);
this.btnIgnore.Size = new System.Drawing.Size(75, 26);
this.btnIgnore.TabIndex = 10;
this.btnIgnore.Text = "Ignore";
//
// DarkDialog
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(767, 402);
this.Controls.Add(this.pnlFooter);
this.Name = "DarkDialog";
this.Text = "DarkDialog";
this.pnlFooter.ResumeLayout(false);
this.flowInner.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel pnlFooter;
private System.Windows.Forms.FlowLayoutPanel flowInner;
protected DarkButton btnOk;
protected DarkButton btnCancel;
protected DarkButton btnClose;
protected DarkButton btnYes;
protected DarkButton btnNo;
protected DarkButton btnAbort;
protected DarkButton btnRetry;
protected DarkButton btnIgnore;
}
}

162
DarkUI/Forms/DarkDialog.cs Normal file
View File

@ -0,0 +1,162 @@
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
namespace DarkUI
{
public partial class DarkDialog : DarkForm
{
#region Field Region
private DarkDialogButton _dialogButtons = DarkDialogButton.Ok;
private List<DarkButton> _buttons;
#endregion
#region Property Region
[Description("Determines the type of the dialog window.")]
[DefaultValue(DarkDialogButton.Ok)]
public DarkDialogButton DialogButtons
{
get { return _dialogButtons; }
set
{
if (_dialogButtons == value)
return;
_dialogButtons = value;
SetButtons();
}
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public int TotalButtonSize { get; private set; }
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new IButtonControl AcceptButton
{
get { return base.AcceptButton; }
private set { base.AcceptButton = value; }
}
[Browsable(false)]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public new IButtonControl CancelButton
{
get { return base.CancelButton; }
private set { base.CancelButton = value; }
}
#endregion
#region Constructor Region
public DarkDialog()
{
InitializeComponent();
_buttons = new List<DarkButton>
{
btnAbort, btnRetry, btnIgnore, btnOk,
btnCancel, btnClose, btnYes, btnNo
};
}
#endregion
#region Event Handler Region
protected override void OnLoad(System.EventArgs e)
{
base.OnLoad(e);
SetButtons();
}
#endregion
#region Method Region
private void SetButtons()
{
foreach (var btn in _buttons)
btn.Visible = false;
switch (_dialogButtons)
{
case DarkDialogButton.Ok:
ShowButton(btnOk, true);
AcceptButton = btnOk;
break;
case DarkDialogButton.Close:
ShowButton(btnClose, true);
AcceptButton = btnClose;
CancelButton = btnClose;
break;
case DarkDialogButton.OkCancel:
ShowButton(btnOk);
ShowButton(btnCancel, true);
AcceptButton = btnOk;
CancelButton = btnCancel;
break;
case DarkDialogButton.AbortRetryIgnore:
ShowButton(btnAbort);
ShowButton(btnRetry);
ShowButton(btnIgnore, true);
AcceptButton = btnAbort;
CancelButton = btnIgnore;
break;
case DarkDialogButton.RetryCancel:
ShowButton(btnRetry);
ShowButton(btnCancel, true);
AcceptButton = btnRetry;
CancelButton = btnCancel;
break;
case DarkDialogButton.YesNo:
ShowButton(btnYes);
ShowButton(btnNo, true);
AcceptButton = btnYes;
CancelButton = btnNo;
break;
case DarkDialogButton.YesNoCancel:
ShowButton(btnYes);
ShowButton(btnNo);
ShowButton(btnCancel, true);
AcceptButton = btnYes;
CancelButton = btnCancel;
break;
}
SetFlowSize();
}
private void ShowButton(DarkButton button, bool isLast = false)
{
button.SendToBack();
if (!isLast)
button.Margin = new Padding(0, 0, 10, 0);
button.Visible = true;
}
private void SetFlowSize()
{
var width = flowInner.Padding.Horizontal;
foreach (var btn in _buttons)
{
if (btn.Visible)
width += btn.Width + btn.Margin.Right;
}
flowInner.Width = width;
TotalButtonSize = width;
}
#endregion
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

81
DarkUI/Forms/DarkMessageBox.Designer.cs generated Normal file
View File

@ -0,0 +1,81 @@
namespace DarkUI
{
partial class DarkMessageBox
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.picIcon = new System.Windows.Forms.PictureBox();
this.lblText = new DarkUI.DarkLabel();
((System.ComponentModel.ISupportInitialize)(this.picIcon)).BeginInit();
this.SuspendLayout();
//
// picIcon
//
this.picIcon.Location = new System.Drawing.Point(10, 10);
this.picIcon.Name = "picIcon";
this.picIcon.Size = new System.Drawing.Size(32, 32);
this.picIcon.TabIndex = 3;
this.picIcon.TabStop = false;
//
// lblText
//
this.lblText.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(220)))), ((int)(((byte)(220)))), ((int)(((byte)(220)))));
this.lblText.Location = new System.Drawing.Point(50, 9);
this.lblText.Name = "lblText";
this.lblText.Size = new System.Drawing.Size(185, 15);
this.lblText.TabIndex = 4;
this.lblText.Text = "Something something something";
//
// DarkMessageBox
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(244, 86);
this.Controls.Add(this.lblText);
this.Controls.Add(this.picIcon);
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "DarkMessageBox";
this.ShowIcon = false;
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "Message box";
this.Controls.SetChildIndex(this.picIcon, 0);
this.Controls.SetChildIndex(this.lblText, 0);
((System.ComponentModel.ISupportInitialize)(this.picIcon)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.PictureBox picIcon;
private DarkLabel lblText;
}
}

View File

@ -0,0 +1,149 @@
using System;
using System.ComponentModel;
using System.Drawing;
namespace DarkUI
{
public partial class DarkMessageBox : DarkDialog
{
#region Field Region
private string _message;
private int _maximumWidth = 350;
#endregion
#region Property Region
[Description("Determines the maximum width of the message box when it autosizes around the displayed message.")]
[DefaultValue(350)]
public int MaximumWidth
{
get { return _maximumWidth; }
set
{
_maximumWidth = value;
CalculateSize();
}
}
#endregion
#region Constructor Region
public DarkMessageBox()
{
InitializeComponent();
}
public DarkMessageBox(string message, string title, DarkMessageBoxIcon icon, DarkDialogButton buttons)
: this()
{
var offsetHeight = Height - picIcon.Height;
Text = title;
_message = message;
DialogButtons = buttons;
SetIcon(icon);
}
public DarkMessageBox(string message)
: this(message, null, DarkMessageBoxIcon.None, DarkDialogButton.Ok)
{ }
public DarkMessageBox(string message, string title)
: this(message, title, DarkMessageBoxIcon.None, DarkDialogButton.Ok)
{ }
public DarkMessageBox(string message, string title, DarkDialogButton buttons)
: this(message, title, DarkMessageBoxIcon.None, buttons)
{ }
public DarkMessageBox(string message, string title, DarkMessageBoxIcon icon)
: this(message, title, icon, DarkDialogButton.Ok)
{ }
#endregion
#region Method Region
private void SetIcon(DarkMessageBoxIcon icon)
{
switch (icon)
{
case DarkMessageBoxIcon.None:
picIcon.Visible = false;
lblText.Left = 10;
break;
case DarkMessageBoxIcon.Information:
picIcon.Image = MessageBoxIcons.info;
break;
case DarkMessageBoxIcon.Warning:
picIcon.Image = MessageBoxIcons.warning;
break;
case DarkMessageBoxIcon.Error:
picIcon.Image = MessageBoxIcons.error;
break;
}
}
private void CalculateSize()
{
var width = 260; var height = 124;
// Reset form back to original size
Size = new Size(width, height);
lblText.Text = string.Empty;
lblText.AutoSize = true;
lblText.Text = _message;
// Set the minimum dialog size to whichever is bigger - the original size or the buttons.
var minWidth = Math.Max(width, TotalButtonSize + 15);
// Calculate the total size of the message
var totalWidth = lblText.Right + 25;
// Make sure we're not making the dialog bigger than the maximum size
if (totalWidth < _maximumWidth)
{
// Width is smaller than the maximum width.
// This means we can have a single-line message box.
// Move the label to accomodate this.
width = totalWidth;
lblText.Top = picIcon.Top + (picIcon.Height / 2) - (lblText.Height / 2);
}
else
{
// Width is larger than the maximum width.
// Change the label size and wrap it.
width = _maximumWidth;
var offsetHeight = Height - picIcon.Height;
lblText.AutoUpdateHeight = true;
lblText.Width = width - lblText.Left - 25;
height = offsetHeight + lblText.Height;
}
// Force the width to the minimum width
if (width < minWidth)
width = minWidth;
// Set the new size of the dialog
Size = new Size(width, height);
}
#endregion
#region Event Handler Region
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
CalculateSize();
}
#endregion
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

93
DarkUI/Icons/MessageBoxIcons.Designer.cs generated Normal file
View File

@ -0,0 +1,93 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.42000
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace DarkUI {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class MessageBoxIcons {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal MessageBoxIcons() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DarkUI.Icons.MessageBoxIcons", typeof(MessageBoxIcons).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap error {
get {
object obj = ResourceManager.GetObject("error", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap info {
get {
object obj = ResourceManager.GetObject("info", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
internal static System.Drawing.Bitmap warning {
get {
object obj = ResourceManager.GetObject("warning", resourceCulture);
return ((System.Drawing.Bitmap)(obj));
}
}
}
}

View File

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<assembly alias="System.Windows.Forms" name="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
<data name="error" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\error.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="info" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\info.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
<data name="warning" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>..\Resources\warning.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
</data>
</root>

BIN
DarkUI/Resources/error.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 745 B

BIN
DarkUI/Resources/info.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 629 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 431 B

View File

@ -77,6 +77,8 @@
this.toolStripStatusLabel4 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel6 = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabel5 = new System.Windows.Forms.ToolStripStatusLabel();
this.btnDialog = new DarkUI.DarkButton();
this.btnMessageBox = new DarkUI.DarkButton();
this.mnuMain.SuspendLayout();
this.toolMain.SuspendLayout();
this.darkStatusStrip1.SuspendLayout();
@ -538,16 +540,35 @@
this.toolStripStatusLabel5.Text = "120 MB";
this.toolStripStatusLabel5.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btnDialog
//
this.btnDialog.Location = new System.Drawing.Point(25, 73);
this.btnDialog.Name = "btnDialog";
this.btnDialog.Padding = new System.Windows.Forms.Padding(5);
this.btnDialog.Size = new System.Drawing.Size(97, 30);
this.btnDialog.TabIndex = 3;
this.btnDialog.Text = "Dialog";
//
// btnMessageBox
//
this.btnMessageBox.Location = new System.Drawing.Point(128, 73);
this.btnMessageBox.Name = "btnMessageBox";
this.btnMessageBox.Padding = new System.Windows.Forms.Padding(5);
this.btnMessageBox.Size = new System.Drawing.Size(97, 30);
this.btnMessageBox.TabIndex = 4;
this.btnMessageBox.Text = "Message Box";
//
// MainForm
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(784, 562);
this.Controls.Add(this.btnMessageBox);
this.Controls.Add(this.btnDialog);
this.Controls.Add(this.darkStatusStrip1);
this.Controls.Add(this.toolMain);
this.Controls.Add(this.mnuMain);
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MainMenuStrip = this.mnuMain;
this.MinimumSize = new System.Drawing.Size(640, 480);
this.Name = "MainForm";
@ -614,6 +635,8 @@
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel4;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel6;
private System.Windows.Forms.ToolStripStatusLabel toolStripStatusLabel5;
private DarkUI.DarkButton btnDialog;
private DarkUI.DarkButton btnMessageBox;
}
}

View File

@ -1,5 +1,4 @@
using DarkUI;
using System.Windows.Forms;
namespace Example
{
@ -8,6 +7,19 @@ namespace Example
public MainForm()
{
InitializeComponent();
btnDialog.Click += delegate {
var msgBox = new DarkMessageBox("This is small",
"Dark UI Example", DarkMessageBoxIcon.Information, DarkDialogButton.AbortRetryIgnore);
msgBox.ShowDialog();
};
btnMessageBox.Click += delegate {
var msgBox = new DarkMessageBox("This is a test of the dark message box. It's cool, isn't it? You can have really quite a lot of text in here and the message box will size itself appropriately. I dislike how the default .NET message box handled this, so hopefully this will be a better option for you. :)",
"Dark UI Example", DarkMessageBoxIcon.Information, DarkDialogButton.AbortRetryIgnore);
msgBox.MaximumWidth = 350;
msgBox.ShowDialog();
};
}
}
}