diff --git a/.gitignore b/.gitignore
index 663f9df3..280cc22b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -68,6 +68,7 @@ StyleCopReport.xml
*_i.c
*_p.c
*_h.h
+*.cache
*.ilk
*.meta
*.obj
diff --git a/.nuspec b/.nuspec
index 2851f241..8547675e 100644
--- a/.nuspec
+++ b/.nuspec
@@ -2,9 +2,9 @@
MaterialSkin.2
- 2.1.2
+ 2.3.1
MaterialSkin 2
- leocb, IgnaceMaes
+ leocb, IgnaceMaes, orapps44
leocb
MIT
https://github.com/leocb/MaterialSkin
@@ -12,15 +12,15 @@
false
Google's Material Design for your windows forms.
see github page for release notes
- Copyright Leonardo C Bottaro © 2020
+ Copyright Leonardo C Bottaro © 2021
material design materialdesign google forms theme skin
- The MaterialSkin 2 is a Google's Material Design skin for you windows forms app. this updated version brings new user controls, unified theming and consistency. This package superseeds the MaterialSkin package By IgnaceMaes. Example app and documentation is available on the project site. Have a quick question? Join our Slack!
+ The MaterialSkin 2 is a Google's Material Design skin for you windows forms app. this updated version brings new user controls, unified theming and consistency. This package superseeds the MaterialSkin package By IgnaceMaes. Example app and documentation is available on the project site.
-
\ No newline at end of file
+
diff --git a/MaterialSkin.sln b/MaterialSkin.sln
index 081e6042..140bfb4f 100644
--- a/MaterialSkin.sln
+++ b/MaterialSkin.sln
@@ -1,10 +1,7 @@
-
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 15
-VisualStudioVersion = 15.0.28307.136
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30717.126
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialSkinExample", "MaterialSkinExample\MaterialSkinExample.csproj", "{47409AA5-62AE-4189-8E83-C471502DF5E9}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialSkin", "MaterialSkin\MaterialSkin.csproj", "{8EB7611B-68CD-4B8B-987A-11717E2B250C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{17028688-3699-4BC7-849F-A6B0F6E766BC}"
@@ -12,20 +9,34 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MaterialSkinCore", "MaterialSkin\MaterialSkinCore.csproj", "{031DCCA6-79CD-41F0-AA5A-09FDE1C1D308}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialSkinExample.RTL", "MaterialSkinExample.RTL\MaterialSkinExample.RTL.csproj", "{8E08A8CF-A5DB-41DF-B486-E0E5DE552697}"
+EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialSkinExample", "MaterialSkinExample\MaterialSkinExample.csproj", "{47409AA5-62AE-4189-8E83-C471502DF5E9}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
- {47409AA5-62AE-4189-8E83-C471502DF5E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
- {47409AA5-62AE-4189-8E83-C471502DF5E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
- {47409AA5-62AE-4189-8E83-C471502DF5E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
- {47409AA5-62AE-4189-8E83-C471502DF5E9}.Release|Any CPU.Build.0 = Release|Any CPU
{8EB7611B-68CD-4B8B-987A-11717E2B250C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8EB7611B-68CD-4B8B-987A-11717E2B250C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8EB7611B-68CD-4B8B-987A-11717E2B250C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8EB7611B-68CD-4B8B-987A-11717E2B250C}.Release|Any CPU.Build.0 = Release|Any CPU
+ {031DCCA6-79CD-41F0-AA5A-09FDE1C1D308}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {031DCCA6-79CD-41F0-AA5A-09FDE1C1D308}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {031DCCA6-79CD-41F0-AA5A-09FDE1C1D308}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {031DCCA6-79CD-41F0-AA5A-09FDE1C1D308}.Release|Any CPU.Build.0 = Release|Any CPU
+ {8E08A8CF-A5DB-41DF-B486-E0E5DE552697}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {8E08A8CF-A5DB-41DF-B486-E0E5DE552697}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {8E08A8CF-A5DB-41DF-B486-E0E5DE552697}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {8E08A8CF-A5DB-41DF-B486-E0E5DE552697}.Release|Any CPU.Build.0 = Release|Any CPU
+ {47409AA5-62AE-4189-8E83-C471502DF5E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {47409AA5-62AE-4189-8E83-C471502DF5E9}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {47409AA5-62AE-4189-8E83-C471502DF5E9}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {47409AA5-62AE-4189-8E83-C471502DF5E9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/MaterialSkin/ColorHelper.cs b/MaterialSkin/ColorHelper.cs
index 22f02460..7c77d7b3 100644
--- a/MaterialSkin/ColorHelper.cs
+++ b/MaterialSkin/ColorHelper.cs
@@ -138,5 +138,25 @@ public static Color FromHsl(int alpha, float hue, float saturation, float lighti
return Color.FromArgb(alpha, iMax, iMid, iMin);
}
}
+
+ ///
+ /// Removes alpha value without changing Color.
+ ///
+ /// The foreground color.
+ /// The background color.
+ ///
+ public static Color RemoveAlpha(Color foreground, Color background)
+ {
+ if (foreground.A == 255)
+ return foreground;
+
+ var alpha = foreground.A / 255.0;
+ var diff = 1.0 - alpha;
+ return Color.FromArgb(255,
+ (byte)(foreground.R * alpha + background.R * diff),
+ (byte)(foreground.G * alpha + background.G * diff),
+ (byte)(foreground.B * alpha + background.B * diff));
+ }
+
}
-}
\ No newline at end of file
+}
diff --git a/MaterialSkin/ColorScheme.cs b/MaterialSkin/ColorScheme.cs
index 1c286772..af25baf4 100644
--- a/MaterialSkin/ColorScheme.cs
+++ b/MaterialSkin/ColorScheme.cs
@@ -1,4 +1,4 @@
-namespace MaterialSkin
+namespace MaterialSkin
{
using System.Drawing;
@@ -10,6 +10,10 @@ public class ColorScheme
public readonly Brush PrimaryBrush, DarkPrimaryBrush, LightPrimaryBrush, AccentBrush, TextBrush;
+ public ColorScheme() : this(Primary.Indigo500, Primary.Indigo700, Primary.Indigo100, Accent.Pink200, TextShade.WHITE)
+ {
+ }
+
public ColorScheme(Primary primary, Primary darkPrimary, Primary lightPrimary, Accent accent, TextShade textShade)
{
//Color
@@ -34,6 +38,30 @@ public ColorScheme(Primary primary, Primary darkPrimary, Primary lightPrimary, A
TextBrush = new SolidBrush(TextColor);
}
+ public ColorScheme(int primary, int darkPrimary, int lightPrimary, int accent, TextShade textShade)
+ {
+ //Color
+ PrimaryColor = ((int)primary).ToColor();
+ DarkPrimaryColor = ((int)darkPrimary).ToColor();
+ LightPrimaryColor = ((int)lightPrimary).ToColor();
+ AccentColor = ((int)accent).ToColor();
+ TextColor = ((int)textShade).ToColor();
+
+ //Pen
+ PrimaryPen = new Pen(PrimaryColor);
+ DarkPrimaryPen = new Pen(DarkPrimaryColor);
+ LightPrimaryPen = new Pen(LightPrimaryColor);
+ AccentPen = new Pen(AccentColor);
+ TextPen = new Pen(TextColor);
+
+ //Brush
+ PrimaryBrush = new SolidBrush(PrimaryColor);
+ DarkPrimaryBrush = new SolidBrush(DarkPrimaryColor);
+ LightPrimaryBrush = new SolidBrush(LightPrimaryColor);
+ AccentBrush = new SolidBrush(AccentColor);
+ TextBrush = new SolidBrush(TextColor);
+ }
+
public ColorScheme(Color primary, Color darkPrimary, Color lightPrimary, Color accent, TextShade textShade)
{
//Color
@@ -327,4 +355,4 @@ public enum Accent
DeepOrange400 = 0xFF3D00,
DeepOrange700 = 0xDD2C00
}
-}
\ No newline at end of file
+}
diff --git a/MaterialSkin/Controls/BaseTextBox.cs b/MaterialSkin/Controls/BaseTextBox.cs
new file mode 100644
index 00000000..0a6d46e9
--- /dev/null
+++ b/MaterialSkin/Controls/BaseTextBox.cs
@@ -0,0 +1,241 @@
+namespace MaterialSkin.Controls
+{
+ using System;
+ using System.ComponentModel;
+ using System.Drawing;
+ using System.Windows.Forms;
+
+ [ToolboxItem(false)]
+ public class BaseTextBox : TextBox, IMaterialControl
+ {
+ #region "Public Properties"
+
+ //Properties for managing the material design properties
+ [Browsable(false)]
+ public int Depth { get; set; }
+
+ [Browsable(false)]
+ public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
+
+ [Browsable(false)]
+ public MouseState MouseState { get; set; }
+
+ private string hint = string.Empty;
+ public string Hint
+ {
+ get { return hint; }
+ set
+ {
+ hint = value;
+ Invalidate();
+ }
+ }
+
+ public new void SelectAll()
+ {
+ BeginInvoke((MethodInvoker)delegate ()
+ {
+ base.Focus();
+ base.SelectAll();
+ });
+ }
+
+ #endregion
+
+ public BaseTextBox()
+ {
+ }
+
+
+ protected override void OnGotFocus(EventArgs e)
+ {
+ base.OnGotFocus(e);
+ Invalidate();
+ }
+
+ protected override void OnLostFocus(EventArgs e)
+ {
+ base.OnLostFocus(e);
+ Invalidate();
+ }
+
+ private const int WM_ENABLE = 0x0A;
+ private const int WM_PAINT = 0xF;
+ private const UInt32 WM_USER = 0x0400;
+ private const UInt32 EM_SETBKGNDCOLOR = (WM_USER + 67);
+ private const UInt32 WM_KILLFOCUS = 0x0008;
+ protected override void WndProc(ref Message m)
+ {
+ base.WndProc(ref m);
+
+
+ if (m.Msg == WM_PAINT)
+ {
+ if (m.Msg == WM_ENABLE)
+ {
+ Graphics g = Graphics.FromHwnd(Handle);
+ Rectangle bounds = new Rectangle(0, 0, Width, Height);
+ g.FillRectangle(SkinManager.BackgroundDisabledBrush, bounds);
+ }
+ }
+
+ if (m.Msg == WM_PAINT && String.IsNullOrEmpty(Text) && !Focused)
+ {
+ using (NativeTextRenderer NativeText = new NativeTextRenderer(Graphics.FromHwnd(m.HWnd)))
+ {
+ var textAlignFlag = RightToLeft == RightToLeft.Yes ? NativeTextRenderer.TextAlignFlags.Right : NativeTextRenderer.TextAlignFlags.Left;
+ NativeText.DrawTransparentText(
+ Hint,
+ SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle1,RightToLeft),
+ Enabled ?
+ ColorHelper.RemoveAlpha(SkinManager.TextMediumEmphasisColor, BackColor) : // not focused
+ ColorHelper.RemoveAlpha(SkinManager.TextDisabledOrHintColor, BackColor), // Disabled
+ ClientRectangle.Location,
+ ClientRectangle.Size,
+ textAlignFlag | NativeTextRenderer.TextAlignFlags.Top);
+ }
+ }
+
+ if (m.Msg == EM_SETBKGNDCOLOR)
+ {
+ Invalidate();
+ }
+
+ if (m.Msg == WM_KILLFOCUS) //set border back to normal on lost focus
+ {
+ Invalidate();
+ }
+
+ }
+
+ }
+
+ [ToolboxItem(false)]
+ public class BaseMaskedTextBox : MaskedTextBox, IMaterialControl
+ {
+ //Properties for managing the material design properties
+ [Browsable(false)]
+ public int Depth { get; set; }
+
+ [Browsable(false)]
+ public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
+
+ [Browsable(false)]
+ public MouseState MouseState { get; set; }
+
+ private string hint = string.Empty;
+ public string Hint
+ {
+ get { return hint; }
+ set
+ {
+ hint = value;
+ Invalidate();
+ }
+ }
+
+ public new void SelectAll()
+ {
+ BeginInvoke((MethodInvoker)delegate ()
+ {
+ base.Focus();
+ base.SelectAll();
+ });
+ }
+
+
+ public BaseMaskedTextBox()
+ {
+ }
+
+ protected override void OnGotFocus(EventArgs e)
+ {
+ base.OnGotFocus(e);
+ Invalidate();
+ }
+
+ protected override void OnLostFocus(EventArgs e)
+ {
+ base.OnLostFocus(e);
+ Invalidate();
+ }
+
+ private const int WM_ENABLE = 0x0A;
+ private const int WM_PAINT = 0xF;
+ private const UInt32 WM_USER = 0x0400;
+ private const UInt32 EM_SETBKGNDCOLOR = (WM_USER + 67);
+ private const UInt32 WM_KILLFOCUS = 0x0008;
+ protected override void WndProc(ref Message m)
+ {
+ base.WndProc(ref m);
+
+
+ if (m.Msg == WM_PAINT)
+ {
+ if (m.Msg == WM_ENABLE)
+ {
+ Graphics g = Graphics.FromHwnd(Handle);
+ Rectangle bounds = new Rectangle(0, 0, Width, Height);
+ g.FillRectangle(SkinManager.BackgroundDisabledBrush, bounds);
+ }
+ }
+
+ if (m.Msg == WM_PAINT && String.IsNullOrEmpty(Text) && !Focused)
+ {
+ using (NativeTextRenderer NativeText = new NativeTextRenderer(Graphics.FromHwnd(m.HWnd)))
+ {
+ var textAlignFlag = RightToLeft == RightToLeft.Yes ? NativeTextRenderer.TextAlignFlags.Right : NativeTextRenderer.TextAlignFlags.Left;
+ NativeText.DrawTransparentText(
+ Hint,
+ SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle1, RightToLeft),
+ Enabled ?
+ ColorHelper.RemoveAlpha(SkinManager.TextMediumEmphasisColor, BackColor) : // not focused
+ ColorHelper.RemoveAlpha(SkinManager.TextDisabledOrHintColor, BackColor), // Disabled
+ ClientRectangle.Location,
+ ClientRectangle.Size,
+ textAlignFlag | NativeTextRenderer.TextAlignFlags.Top);
+ }
+ }
+
+ if (m.Msg == EM_SETBKGNDCOLOR)
+ {
+ Invalidate();
+ }
+
+ if (m.Msg == WM_KILLFOCUS) //set border back to normal on lost focus
+ {
+ Invalidate();
+ }
+
+ }
+ }
+
+ [ToolboxItem(false)]
+ public class BaseTextBoxContextMenuStrip : MaterialContextMenuStrip
+ {
+ public readonly ToolStripItem undo = new MaterialToolStripMenuItem { Text = "Undo" };
+ public readonly ToolStripItem seperator1 = new ToolStripSeparator();
+ public readonly ToolStripItem cut = new MaterialToolStripMenuItem { Text = "Cut" };
+ public readonly ToolStripItem copy = new MaterialToolStripMenuItem { Text = "Copy" };
+ public readonly ToolStripItem paste = new MaterialToolStripMenuItem { Text = "Paste" };
+ public readonly ToolStripItem delete = new MaterialToolStripMenuItem { Text = "Delete" };
+ public readonly ToolStripItem seperator2 = new ToolStripSeparator();
+ public readonly ToolStripItem selectAll = new MaterialToolStripMenuItem { Text = "Select All" };
+
+ public BaseTextBoxContextMenuStrip()
+ {
+ Items.AddRange(new[]
+ {
+ undo,
+ seperator1,
+ cut,
+ copy,
+ paste,
+ delete,
+ seperator2,
+ selectAll
+ });
+ }
+ }
+
+}
diff --git a/MaterialSkin/Controls/FlexibleMaterialDialog.cs b/MaterialSkin/Controls/FlexibleMaterialDialog.cs
index 3c4caae2..91d527db 100644
--- a/MaterialSkin/Controls/FlexibleMaterialDialog.cs
+++ b/MaterialSkin/Controls/FlexibleMaterialDialog.cs
@@ -1,786 +1,970 @@
-using System;
-using System.Diagnostics;
-using System.Drawing;
-using System.Globalization;
-using System.Linq;
-using System.Windows.Forms;
-
-namespace MaterialSkin.Controls
-{
- ///
- /// The form to show the customized message box.
- /// It is defined as an internal class to keep the public interface of the FlexibleMessageBox clean.
- ///
- public class FlexibleMaterialForm : MaterialForm, IMaterialControl
- {
+using System;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Drawing;
+using System.Globalization;
+using System.Linq;
+using System.Windows.Forms;
+
+namespace MaterialSkin.Controls
+{
+ ///
+ /// The form to show the customized message box.
+ /// It is defined as an internal class to keep the public interface of the FlexibleMessageBox clean.
+ ///
+ public class FlexibleMaterialForm : MaterialForm, IMaterialControl
+ {
private readonly MaterialSkinManager materialSkinManager;
-
- ///
- /// Defines the font for all FlexibleMessageBox instances.
- ///
- /// Default is: SystemFonts.MessageBoxFont
- ///
- public static Font FONT;
-
- ///
- /// Defines the maximum width for all FlexibleMessageBox instances in percent of the working area.
- ///
- /// Allowed values are 0.2 - 1.0 where:
- /// 0.2 means: The FlexibleMessageBox can be at most half as wide as the working area.
- /// 1.0 means: The FlexibleMessageBox can be as wide as the working area.
- ///
- /// Default is: 70% of the working area width.
- ///
- public static double MAX_WIDTH_FACTOR = 0.7;
-
- ///
- /// Defines the maximum height for all FlexibleMessageBox instances in percent of the working area.
- ///
- /// Allowed values are 0.2 - 1.0 where:
- /// 0.2 means: The FlexibleMessageBox can be at most half as high as the working area.
- /// 1.0 means: The FlexibleMessageBox can be as high as the working area.
- ///
- /// Default is: 90% of the working area height.
- ///
- public static double MAX_HEIGHT_FACTOR = 0.9;
-
- private MaterialMultiLineTextBox richTextBoxMessage;
-
- ///
- /// Erforderliche Designervariable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Verwendete Ressourcen bereinigen.
- ///
- /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- ///
- /// Erforderliche Methode für die Designerunterstützung.
- /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
- ///
- private void InitializeComponent()
- {
- this.components = new System.ComponentModel.Container();
- this.leftButton = new MaterialSkin.Controls.MaterialButton();
- this.FlexibleMaterialFormBindingSource = new System.Windows.Forms.BindingSource(this.components);
- this.messageContainer = new System.Windows.Forms.Panel();
- this.pictureBoxForIcon = new System.Windows.Forms.PictureBox();
- this.richTextBoxMessage = new MaterialSkin.Controls.MaterialMultiLineTextBox();
- this.middleButton = new MaterialSkin.Controls.MaterialButton();
- this.rightButton = new MaterialSkin.Controls.MaterialButton();
- ((System.ComponentModel.ISupportInitialize)(this.FlexibleMaterialFormBindingSource)).BeginInit();
- this.messageContainer.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxForIcon)).BeginInit();
- this.SuspendLayout();
- //
- // leftButton
- //
- this.leftButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.leftButton.AutoSize = false;
- this.leftButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.leftButton.Depth = 0;
- this.leftButton.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.leftButton.DrawShadows = true;
- this.leftButton.HighEmphasis = false;
- this.leftButton.Icon = null;
- this.leftButton.Location = new System.Drawing.Point(44, 163);
- this.leftButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
- this.leftButton.MinimumSize = new System.Drawing.Size(0, 24);
- this.leftButton.MouseState = MaterialSkin.MouseState.HOVER;
- this.leftButton.Name = "leftButton";
- this.leftButton.Size = new System.Drawing.Size(108, 36);
- this.leftButton.TabIndex = 2;
- this.leftButton.Text = "OK";
- this.leftButton.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Text;
- this.leftButton.UseAccentColor = false;
- this.leftButton.UseVisualStyleBackColor = true;
- this.leftButton.Visible = false;
- //
- // messageContainer
- //
- this.messageContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.messageContainer.BackColor = System.Drawing.Color.White;
- this.messageContainer.Controls.Add(this.pictureBoxForIcon);
- this.messageContainer.Controls.Add(this.richTextBoxMessage);
- this.messageContainer.Location = new System.Drawing.Point(0, 65);
- this.messageContainer.Name = "messageContainer";
- this.messageContainer.Size = new System.Drawing.Size(388, 81);
- this.messageContainer.TabIndex = 1;
- //
- // pictureBoxForIcon
- //
- this.pictureBoxForIcon.BackColor = System.Drawing.Color.Transparent;
- this.pictureBoxForIcon.Location = new System.Drawing.Point(15, 19);
- this.pictureBoxForIcon.Name = "pictureBoxForIcon";
- this.pictureBoxForIcon.Size = new System.Drawing.Size(32, 32);
- this.pictureBoxForIcon.TabIndex = 8;
- this.pictureBoxForIcon.TabStop = false;
- //
- // richTextBoxMessage
- //
- this.richTextBoxMessage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
- | System.Windows.Forms.AnchorStyles.Left)
- | System.Windows.Forms.AnchorStyles.Right)));
- this.richTextBoxMessage.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(237)))), ((int)(((byte)(237)))), ((int)(((byte)(237)))));
- this.richTextBoxMessage.BorderStyle = System.Windows.Forms.BorderStyle.None;
- this.richTextBoxMessage.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlexibleMaterialFormBindingSource, "MessageText", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
- this.richTextBoxMessage.Depth = 0;
- this.richTextBoxMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
- this.richTextBoxMessage.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(180)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
- this.richTextBoxMessage.Hint = "";
- this.richTextBoxMessage.Location = new System.Drawing.Point(47, 2);
- this.richTextBoxMessage.Margin = new System.Windows.Forms.Padding(0);
- this.richTextBoxMessage.MouseState = MaterialSkin.MouseState.HOVER;
- this.richTextBoxMessage.Name = "richTextBoxMessage";
- this.richTextBoxMessage.ReadOnly = true;
- this.richTextBoxMessage.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
- this.richTextBoxMessage.Size = new System.Drawing.Size(338, 78);
- this.richTextBoxMessage.TabIndex = 0;
- this.richTextBoxMessage.TabStop = false;
- this.richTextBoxMessage.Text = "";
- this.richTextBoxMessage.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBoxMessage_LinkClicked);
- //
- // middleButton
- //
- this.middleButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.middleButton.AutoSize = false;
- this.middleButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.middleButton.Depth = 0;
- this.middleButton.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.middleButton.DrawShadows = true;
- this.middleButton.HighEmphasis = true;
- this.middleButton.Icon = null;
- this.middleButton.Location = new System.Drawing.Point(160, 163);
- this.middleButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
- this.middleButton.MinimumSize = new System.Drawing.Size(0, 24);
- this.middleButton.MouseState = MaterialSkin.MouseState.HOVER;
- this.middleButton.Name = "middleButton";
- this.middleButton.Size = new System.Drawing.Size(102, 36);
- this.middleButton.TabIndex = 3;
- this.middleButton.Text = "OK";
- this.middleButton.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Text;
- this.middleButton.UseAccentColor = false;
- this.middleButton.UseVisualStyleBackColor = true;
- this.middleButton.Visible = false;
- //
- // rightButton
- //
- this.rightButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.rightButton.AutoSize = false;
- this.rightButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.rightButton.Depth = 0;
- this.rightButton.DialogResult = System.Windows.Forms.DialogResult.OK;
- this.rightButton.DrawShadows = true;
- this.rightButton.HighEmphasis = true;
- this.rightButton.Icon = null;
- this.rightButton.Location = new System.Drawing.Point(270, 163);
- this.rightButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
- this.rightButton.MinimumSize = new System.Drawing.Size(0, 24);
- this.rightButton.MouseState = MaterialSkin.MouseState.HOVER;
- this.rightButton.Name = "rightButton";
- this.rightButton.Size = new System.Drawing.Size(106, 36);
- this.rightButton.TabIndex = 0;
- this.rightButton.Text = "OK";
- this.rightButton.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained;
- this.rightButton.UseAccentColor = false;
- this.rightButton.UseVisualStyleBackColor = true;
- this.rightButton.Visible = false;
- //
- // FlexibleMaterialForm
- //
- this.BackColor = System.Drawing.Color.White;
- this.ClientSize = new System.Drawing.Size(388, 208);
- this.Controls.Add(this.rightButton);
- this.Controls.Add(this.middleButton);
- this.Controls.Add(this.messageContainer);
- this.Controls.Add(this.leftButton);
- this.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlexibleMaterialFormBindingSource, "CaptionText", true));
- this.MaximizeBox = false;
- this.MinimizeBox = false;
- this.MinimumSize = new System.Drawing.Size(276, 140);
- this.Name = "FlexibleMaterialForm";
- this.ShowIcon = false;
- this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
- this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
- this.Text = "";
- this.Load += new System.EventHandler(this.FlexibleMaterialForm_Load);
- this.Shown += new System.EventHandler(this.FlexibleMaterialForm_Shown);
- ((System.ComponentModel.ISupportInitialize)(this.FlexibleMaterialFormBindingSource)).EndInit();
- this.messageContainer.ResumeLayout(false);
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxForIcon)).EndInit();
- this.ResumeLayout(false);
- }
-
- private MaterialButton leftButton;
-
- ///
- /// Defines the FlexibleMaterialFormBindingSource
- ///
- private System.Windows.Forms.BindingSource FlexibleMaterialFormBindingSource;
-
- ///
- /// Defines the panel1
- ///
- private System.Windows.Forms.Panel messageContainer;
-
- ///
- /// Defines the pictureBoxForIcon
- ///
- private System.Windows.Forms.PictureBox pictureBoxForIcon;
-
- private MaterialButton middleButton;
- private MaterialButton rightButton;
-
- //These separators are used for the "copy to clipboard" standard operation, triggered by Ctrl + C (behavior and clipboard format is like in a standard MessageBox)
- ///
- /// Defines the STANDARD_MESSAGEBOX_SEPARATOR_LINES
- ///
- private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_LINES = "---------------------------\n";
-
- ///
- /// Defines the STANDARD_MESSAGEBOX_SEPARATOR_SPACES
- ///
- private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " ";
-
- //These are the possible buttons (in a standard MessageBox)
- private enum ButtonID
- { ///
- /// Defines the OK
- ///
+
+ ///
+ /// Defines the font for all FlexibleMessageBox instances.
+ ///
+ /// Default is: SystemFonts.MessageBoxFont
+ ///
+ public static Font FONT;
+
+ ///
+ /// Defines the maximum width for all FlexibleMessageBox instances in percent of the working area.
+ ///
+ /// Allowed values are 0.2 - 1.0 where:
+ /// 0.2 means: The FlexibleMessageBox can be at most half as wide as the working area.
+ /// 1.0 means: The FlexibleMessageBox can be as wide as the working area.
+ ///
+ /// Default is: 70% of the working area width.
+ ///
+ public static double MAX_WIDTH_FACTOR = 0.7;
+
+ ///
+ /// Defines the maximum height for all FlexibleMessageBox instances in percent of the working area.
+ ///
+ /// Allowed values are 0.2 - 1.0 where:
+ /// 0.2 means: The FlexibleMessageBox can be at most half as high as the working area.
+ /// 1.0 means: The FlexibleMessageBox can be as high as the working area.
+ ///
+ /// Default is: 90% of the working area height.
+ ///
+ public static double MAX_HEIGHT_FACTOR = 0.9;
+
+ private MaterialMultiLineTextBox richTextBoxMessage;
+ private MaterialLabel materialLabel1;
+ private MaterialButton leftButton;
+ private MaterialButton middleButton;
+ private MaterialButton rightButton;
+
+ [Browsable(false)]
+ ///
+ /// Defines position of buttons in Dialog window. By default, ButtonStyle is Fill
+ ///
+ public enum ButtonsPosition
+ {
+ Fill,
+ Left,
+ Right,
+ Center
+ }
+
+ public ButtonsPosition ButtonsPositionEnum { get; set; } = FlexibleMaterialForm.ButtonsPosition.Right;
+
+ ///
+ /// Erforderliche Designervariable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Verwendete Ressourcen bereinigen.
+ ///
+ /// True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ ///
+ /// Erforderliche Methode für die Designerunterstützung.
+ /// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
+ ///
+ private void InitializeComponent()
+ {
+ this.components = new System.ComponentModel.Container();
+ this.FlexibleMaterialFormBindingSource = new System.Windows.Forms.BindingSource(this.components);
+ this.messageContainer = new System.Windows.Forms.Panel();
+ this.materialLabel1 = new MaterialSkin.Controls.MaterialLabel();
+ this.pictureBoxForIcon = new System.Windows.Forms.PictureBox();
+ this.richTextBoxMessage = new MaterialSkin.Controls.MaterialMultiLineTextBox();
+ this.leftButton = new MaterialSkin.Controls.MaterialButton();
+ this.middleButton = new MaterialSkin.Controls.MaterialButton();
+ this.rightButton = new MaterialSkin.Controls.MaterialButton();
+ ((System.ComponentModel.ISupportInitialize)(this.FlexibleMaterialFormBindingSource)).BeginInit();
+ this.messageContainer.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxForIcon)).BeginInit();
+ this.SuspendLayout();
+ //
+ // messageContainer
+ //
+ this.messageContainer.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.messageContainer.BackColor = System.Drawing.Color.White;
+ this.messageContainer.Controls.Add(this.materialLabel1);
+ this.messageContainer.Controls.Add(this.pictureBoxForIcon);
+ this.messageContainer.Controls.Add(this.richTextBoxMessage);
+ this.messageContainer.Location = new System.Drawing.Point(1, 65);
+ this.messageContainer.Name = "messageContainer";
+ this.messageContainer.Size = new System.Drawing.Size(382, 89);
+ this.messageContainer.TabIndex = 1;
+ //
+ // materialLabel1
+ //
+ this.materialLabel1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.materialLabel1.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlexibleMaterialFormBindingSource, "MessageText", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
+ this.materialLabel1.Depth = 0;
+ this.materialLabel1.Font = new System.Drawing.Font("Roboto", 14F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Pixel);
+ this.materialLabel1.Location = new System.Drawing.Point(56, 12);
+ this.materialLabel1.MouseState = MaterialSkin.MouseState.HOVER;
+ this.materialLabel1.Name = "materialLabel1";
+ this.materialLabel1.Size = new System.Drawing.Size(314, 65);
+ this.materialLabel1.TabIndex = 9;
+ this.materialLabel1.Text = "";
+ this.materialLabel1.Visible = false;
+ //
+ // pictureBoxForIcon
+ //
+ this.pictureBoxForIcon.BackColor = System.Drawing.Color.Transparent;
+ this.pictureBoxForIcon.Location = new System.Drawing.Point(12, 12);
+ this.pictureBoxForIcon.Name = "pictureBoxForIcon";
+ this.pictureBoxForIcon.Size = new System.Drawing.Size(32, 32);
+ this.pictureBoxForIcon.TabIndex = 8;
+ this.pictureBoxForIcon.TabStop = false;
+ //
+ // richTextBoxMessage
+ //
+ this.richTextBoxMessage.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
+ | System.Windows.Forms.AnchorStyles.Left)
+ | System.Windows.Forms.AnchorStyles.Right)));
+ this.richTextBoxMessage.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(255)))));
+ this.richTextBoxMessage.BorderStyle = System.Windows.Forms.BorderStyle.None;
+ this.richTextBoxMessage.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlexibleMaterialFormBindingSource, "MessageText", true, System.Windows.Forms.DataSourceUpdateMode.OnPropertyChanged));
+ this.richTextBoxMessage.Depth = 0;
+ this.richTextBoxMessage.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
+ this.richTextBoxMessage.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(222)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))), ((int)(((byte)(0)))));
+ this.richTextBoxMessage.Location = new System.Drawing.Point(56, 12);
+ this.richTextBoxMessage.Margin = new System.Windows.Forms.Padding(0);
+ this.richTextBoxMessage.MouseState = MaterialSkin.MouseState.HOVER;
+ this.richTextBoxMessage.Name = "richTextBoxMessage";
+ this.richTextBoxMessage.ReadOnly = true;
+ this.richTextBoxMessage.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.Vertical;
+ this.richTextBoxMessage.Size = new System.Drawing.Size(314, 65);
+ this.richTextBoxMessage.TabIndex = 0;
+ this.richTextBoxMessage.TabStop = false;
+ this.richTextBoxMessage.Text = "";
+ this.richTextBoxMessage.LinkClicked += new System.Windows.Forms.LinkClickedEventHandler(this.richTextBoxMessage_LinkClicked);
+ //
+ // leftButton
+ //
+ this.leftButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
+ this.leftButton.AutoSize = false;
+ this.leftButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
+ this.leftButton.Density = MaterialSkin.Controls.MaterialButton.MaterialButtonDensity.Default;
+ this.leftButton.Depth = 0;
+ this.leftButton.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.leftButton.HighEmphasis = false;
+ this.leftButton.Icon = null;
+ this.leftButton.Location = new System.Drawing.Point(32, 163);
+ this.leftButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
+ this.leftButton.MinimumSize = new System.Drawing.Size(0, 24);
+ this.leftButton.MouseState = MaterialSkin.MouseState.HOVER;
+ this.leftButton.Name = "leftButton";
+ this.leftButton.Size = new System.Drawing.Size(108, 36);
+ this.leftButton.TabIndex = 14;
+ this.leftButton.Text = "OK";
+ this.leftButton.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Text;
+ this.leftButton.UseAccentColor = false;
+ this.leftButton.UseVisualStyleBackColor = true;
+ this.leftButton.Visible = false;
+ //
+ // middleButton
+ //
+ this.middleButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
+ this.middleButton.AutoSize = false;
+ this.middleButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
+ this.middleButton.Density = MaterialSkin.Controls.MaterialButton.MaterialButtonDensity.Default;
+ this.middleButton.Depth = 0;
+ this.middleButton.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.middleButton.HighEmphasis = true;
+ this.middleButton.Icon = null;
+ this.middleButton.Location = new System.Drawing.Point(148, 163);
+ this.middleButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
+ this.middleButton.MinimumSize = new System.Drawing.Size(0, 24);
+ this.middleButton.MouseState = MaterialSkin.MouseState.HOVER;
+ this.middleButton.Name = "middleButton";
+ this.middleButton.Size = new System.Drawing.Size(102, 36);
+ this.middleButton.TabIndex = 15;
+ this.middleButton.Text = "OK";
+ this.middleButton.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Text;
+ this.middleButton.UseAccentColor = false;
+ this.middleButton.UseVisualStyleBackColor = true;
+ this.middleButton.Visible = false;
+ //
+ // rightButton
+ //
+ this.rightButton.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
+ this.rightButton.AutoSize = false;
+ this.rightButton.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
+ this.rightButton.Density = MaterialSkin.Controls.MaterialButton.MaterialButtonDensity.Default;
+ this.rightButton.Depth = 0;
+ this.rightButton.DialogResult = System.Windows.Forms.DialogResult.OK;
+ this.rightButton.HighEmphasis = true;
+ this.rightButton.Icon = null;
+ this.rightButton.Location = new System.Drawing.Point(258, 163);
+ this.rightButton.Margin = new System.Windows.Forms.Padding(4, 6, 4, 6);
+ this.rightButton.MinimumSize = new System.Drawing.Size(0, 24);
+ this.rightButton.MouseState = MaterialSkin.MouseState.HOVER;
+ this.rightButton.Name = "rightButton";
+ this.rightButton.Size = new System.Drawing.Size(106, 36);
+ this.rightButton.TabIndex = 13;
+ this.rightButton.Text = "OK";
+ this.rightButton.Type = MaterialSkin.Controls.MaterialButton.MaterialButtonType.Contained;
+ this.rightButton.UseAccentColor = false;
+ this.rightButton.UseVisualStyleBackColor = true;
+ this.rightButton.Visible = false;
+ //
+ // FlexibleMaterialForm
+ //
+ this.BackColor = System.Drawing.Color.White;
+ this.ClientSize = new System.Drawing.Size(384, 208);
+ this.Controls.Add(this.leftButton);
+ this.Controls.Add(this.middleButton);
+ this.Controls.Add(this.rightButton);
+ this.Controls.Add(this.messageContainer);
+ this.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.FlexibleMaterialFormBindingSource, "CaptionText", true));
+ this.MaximizeBox = false;
+ this.MinimizeBox = false;
+ this.MinimumSize = new System.Drawing.Size(276, 140);
+ this.Name = "FlexibleMaterialForm";
+ this.ShowIcon = false;
+ this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Show;
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
+ this.Text = "";
+ this.Load += new System.EventHandler(this.FlexibleMaterialForm_Load);
+ this.Shown += new System.EventHandler(this.FlexibleMaterialForm_Shown);
+ ((System.ComponentModel.ISupportInitialize)(this.FlexibleMaterialFormBindingSource)).EndInit();
+ this.messageContainer.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxForIcon)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ ///
+ /// Defines the FlexibleMaterialFormBindingSource
+ ///
+ private System.Windows.Forms.BindingSource FlexibleMaterialFormBindingSource;
+
+ ///
+ /// Defines the panel1
+ ///
+ private System.Windows.Forms.Panel messageContainer;
+
+ ///
+ /// Defines the pictureBoxForIcon
+ ///
+ private System.Windows.Forms.PictureBox pictureBoxForIcon;
+
+ //These separators are used for the "copy to clipboard" standard operation, triggered by Ctrl + C (behavior and clipboard format is like in a standard MessageBox)
+ ///
+ /// Defines the STANDARD_MESSAGEBOX_SEPARATOR_LINES
+ ///
+ private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_LINES = "---------------------------\n";
+
+ ///
+ /// Defines the STANDARD_MESSAGEBOX_SEPARATOR_SPACES
+ ///
+ private static readonly String STANDARD_MESSAGEBOX_SEPARATOR_SPACES = " ";
+
+ //These are the possible buttons (in a standard MessageBox)
+ private enum ButtonID
+ { ///
+ /// Defines the OK
+ ///
OK = 0,
-
- ///
- /// Defines the CANCEL
- ///
+
+ ///
+ /// Defines the CANCEL
+ ///
CANCEL,
-
- ///
- /// Defines the YES
- ///
+
+ ///
+ /// Defines the YES
+ ///
YES,
-
- ///
- /// Defines the NO
- ///
+
+ ///
+ /// Defines the NO
+ ///
NO,
-
- ///
- /// Defines the ABORT
- ///
+
+ ///
+ /// Defines the ABORT
+ ///
ABORT,
-
- ///
- /// Defines the RETRY
- ///
+
+ ///
+ /// Defines the RETRY
+ ///
RETRY,
-
- ///
- /// Defines the IGNORE
- ///
- IGNORE
- };
-
- //These are the buttons texts for different languages.
- //If you want to add a new language, add it here and in the GetButtonText-Function
- private enum TwoLetterISOLanguageID
- { ///
- /// Defines the en
- ///
+
+ ///
+ /// Defines the IGNORE
+ ///
+ IGNORE
+ };
+
+ //These are the buttons texts for different languages.
+ //If you want to add a new language, add it here and in the GetButtonText-Function
+ private enum TwoLetterISOLanguageID
+ { ///
+ /// Defines the en
+ ///
en,
-
- ///
- /// Defines the de
- ///
+
+ ///
+ /// Defines the de
+ ///
de,
-
- ///
- /// Defines the es
- ///
+
+ ///
+ /// Defines the es
+ ///
es,
-
- ///
- /// Defines the it
- ///
- it
- };
-
- ///
- /// Defines the BUTTON_TEXTS_ENGLISH_EN
- ///
- private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore" };//Note: This is also the fallback language
-
- ///
- /// Defines the BUTTON_TEXTS_GERMAN_DE
- ///
- private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren" };
-
- ///
- /// Defines the BUTTON_TEXTS_SPANISH_ES
- ///
- private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar" };
-
- ///
- /// Defines the BUTTON_TEXTS_ITALIAN_IT
- ///
- private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora" };
-
- ///
- /// Defines the defaultButton
- ///
- private MessageBoxDefaultButton defaultButton;
-
- ///
- /// Defines the visibleButtonsCount
- ///
- private int visibleButtonsCount;
-
- ///
- /// Defines the languageID
- ///
- private TwoLetterISOLanguageID languageID = TwoLetterISOLanguageID.en;
-
- ///
- /// Prevents a default instance of the class from being created.
- ///
- private FlexibleMaterialForm()
- {
- InitializeComponent();
-
- //Try to evaluate the language. If this fails, the fallback language English will be used
- Enum.TryParse(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, out this.languageID);
-
- this.KeyPreview = true;
- this.KeyUp += FlexibleMaterialForm_KeyUp;
-
- materialSkinManager = MaterialSkinManager.Instance;
- materialSkinManager.AddFormToManage(this);
- FONT = materialSkinManager.getFontByType(MaterialSkinManager.fontType.Body1);
- }
-
- ///
- /// Gets the string rows.
- ///
- /// The message.
- /// The string rows as 1-dimensional array
- private static string[] GetStringRows(string message)
- {
- if (string.IsNullOrEmpty(message))
- {
- return null;
- }
-
- var messageRows = message.Split(new char[] { '\n' }, StringSplitOptions.None);
- return messageRows;
- }
-
- ///
- /// Gets the button text for the CurrentUICulture language.
- /// Note: The fallback language is English
- ///
- /// The ID of the button.
- /// The button text
- private string GetButtonText(ButtonID buttonID)
- {
- var buttonTextArrayIndex = Convert.ToInt32(buttonID);
-
- switch (this.languageID)
- {
- case TwoLetterISOLanguageID.de: return BUTTON_TEXTS_GERMAN_DE[buttonTextArrayIndex];
- case TwoLetterISOLanguageID.es: return BUTTON_TEXTS_SPANISH_ES[buttonTextArrayIndex];
- case TwoLetterISOLanguageID.it: return BUTTON_TEXTS_ITALIAN_IT[buttonTextArrayIndex];
-
- default: return BUTTON_TEXTS_ENGLISH_EN[buttonTextArrayIndex];
- }
- }
-
- ///
- /// Ensure the given working area factor in the range of 0.2 - 1.0 where:
- ///
- /// 0.2 means: 20 percent of the working area height or width.
- /// 1.0 means: 100 percent of the working area height or width.
- ///
- /// The given working area factor.
- /// The corrected given working area factor.
- private static double GetCorrectedWorkingAreaFactor(double workingAreaFactor)
- {
- const double MIN_FACTOR = 0.2;
- const double MAX_FACTOR = 1.0;
-
- if (workingAreaFactor < MIN_FACTOR)
- {
- return MIN_FACTOR;
- }
-
- if (workingAreaFactor > MAX_FACTOR)
- {
- return MAX_FACTOR;
- }
-
- return workingAreaFactor;
- }
-
- ///
- /// Set the dialogs start position when given.
- /// Otherwise center the dialog on the current screen.
- ///
- /// The FlexibleMessageBox dialog.
- /// The owner.
- private static void SetDialogStartPosition(FlexibleMaterialForm FlexibleMaterialForm, IWin32Window owner)
- {
- //If no owner given: Center on current screen
- if (owner == null)
- {
- var screen = Screen.FromPoint(Cursor.Position);
- FlexibleMaterialForm.StartPosition = FormStartPosition.Manual;
- FlexibleMaterialForm.Left = screen.Bounds.Left + screen.Bounds.Width / 2 - FlexibleMaterialForm.Width / 2;
- FlexibleMaterialForm.Top = screen.Bounds.Top + screen.Bounds.Height / 2 - FlexibleMaterialForm.Height / 2;
- }
- }
-
- ///
- /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
- /// Also set the maximum dialog size.
- ///
- /// The FlexibleMessageBox dialog.
- /// The text (the longest text row is used to calculate the dialog width).
- /// The caption
- private static void SetDialogSizes(FlexibleMaterialForm FlexibleMaterialForm, string text, string caption)
- {
- //First set the bounds for the maximum dialog size
- FlexibleMaterialForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMaterialForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
- Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMaterialForm.GetCorrectedWorkingAreaFactor(MAX_HEIGHT_FACTOR)));
-
- //Get rows. Exit if there are no rows to render...
- var stringRows = GetStringRows(text);
- if (stringRows == null)
- {
- return;
- }
-
- //Calculate whole text height
- var textHeight = Math.Min(TextRenderer.MeasureText(text, FONT).Height, 600);
-
- //Calculate width for longest text line
- const int SCROLLBAR_WIDTH_OFFSET = 15;
- var longestTextRowWidth = stringRows.Max(textForRow => TextRenderer.MeasureText(textForRow, FONT).Width);
- var captionWidth = TextRenderer.MeasureText(caption, SystemFonts.CaptionFont).Width;
- var textWidth = Math.Max(longestTextRowWidth + SCROLLBAR_WIDTH_OFFSET, captionWidth);
-
- //Calculate margins
- var marginWidth = FlexibleMaterialForm.Width - FlexibleMaterialForm.richTextBoxMessage.Width;
- var marginHeight = FlexibleMaterialForm.Height - FlexibleMaterialForm.richTextBoxMessage.Height;
-
- //Set calculated dialog size (if the calculated values exceed the maximums, they were cut by windows forms automatically)
- FlexibleMaterialForm.Size = new Size(textWidth + marginWidth,
- textHeight + marginHeight);
- }
-
- ///
- /// Set the dialogs icon.
- /// When no icon is used: Correct placement and width of rich text box.
- ///
- /// The FlexibleMessageBox dialog.
- /// The MessageBoxIcon.
- private static void SetDialogIcon(FlexibleMaterialForm FlexibleMaterialForm, MessageBoxIcon icon)
- {
- switch (icon)
- {
- case MessageBoxIcon.Information:
- FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Information.ToBitmap();
- break;
-
- case MessageBoxIcon.Warning:
- FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Warning.ToBitmap();
- break;
-
- case MessageBoxIcon.Error:
- FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Error.ToBitmap();
- break;
-
- case MessageBoxIcon.Question:
- FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Question.ToBitmap();
- break;
-
- default:
- //When no icon is used: Correct placement and width of rich text box.
- FlexibleMaterialForm.pictureBoxForIcon.Visible = false;
- FlexibleMaterialForm.richTextBoxMessage.Left -= FlexibleMaterialForm.pictureBoxForIcon.Width;
- FlexibleMaterialForm.richTextBoxMessage.Width += FlexibleMaterialForm.pictureBoxForIcon.Width;
- break;
- }
- }
-
- ///
- /// Set dialog buttons visibilities and texts.
- /// Also set a default button.
- ///
- /// The FlexibleMessageBox dialog.
- /// The buttons.
- /// The default button.
- private static void SetDialogButtons(FlexibleMaterialForm FlexibleMaterialForm, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton)
- {
- //Set the buttons visibilities and texts
- switch (buttons)
- {
- case MessageBoxButtons.AbortRetryIgnore:
- FlexibleMaterialForm.visibleButtonsCount = 3;
-
- FlexibleMaterialForm.leftButton.Visible = true;
- FlexibleMaterialForm.leftButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.ABORT);
- FlexibleMaterialForm.leftButton.DialogResult = DialogResult.Abort;
-
- FlexibleMaterialForm.middleButton.Visible = true;
- FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.RETRY);
- FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Retry;
-
- FlexibleMaterialForm.rightButton.Visible = true;
- FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.IGNORE);
- FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Ignore;
-
- FlexibleMaterialForm.ControlBox = false;
- break;
-
- case MessageBoxButtons.OKCancel:
- FlexibleMaterialForm.visibleButtonsCount = 2;
-
- FlexibleMaterialForm.middleButton.Visible = true;
- FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
- FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Cancel;
-
- FlexibleMaterialForm.rightButton.Visible = true;
- FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.OK);
- FlexibleMaterialForm.rightButton.DialogResult = DialogResult.OK;
-
- FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.middleButton;
- break;
-
- case MessageBoxButtons.RetryCancel:
- FlexibleMaterialForm.visibleButtonsCount = 2;
-
- FlexibleMaterialForm.middleButton.Visible = true;
- FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
- FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Cancel;
-
- FlexibleMaterialForm.rightButton.Visible = true;
- FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.RETRY);
- FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Retry;
-
- FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.middleButton;
- break;
-
- case MessageBoxButtons.YesNo:
- FlexibleMaterialForm.visibleButtonsCount = 2;
-
- FlexibleMaterialForm.middleButton.Visible = true;
- FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.NO);
- FlexibleMaterialForm.middleButton.DialogResult = DialogResult.No;
-
- FlexibleMaterialForm.rightButton.Visible = true;
- FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
- FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;
-
- FlexibleMaterialForm.ControlBox = false;
- break;
-
- case MessageBoxButtons.YesNoCancel:
- FlexibleMaterialForm.visibleButtonsCount = 3;
-
- FlexibleMaterialForm.rightButton.Visible = true;
- FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
- FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;
-
- FlexibleMaterialForm.middleButton.Visible = true;
- FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.NO);
- FlexibleMaterialForm.middleButton.DialogResult = DialogResult.No;
-
- FlexibleMaterialForm.leftButton.Visible = true;
- FlexibleMaterialForm.leftButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
- FlexibleMaterialForm.leftButton.DialogResult = DialogResult.Cancel;
-
- FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.leftButton;
- break;
-
- case MessageBoxButtons.OK:
- default:
- FlexibleMaterialForm.visibleButtonsCount = 1;
- FlexibleMaterialForm.rightButton.Visible = true;
- FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.OK);
- FlexibleMaterialForm.rightButton.DialogResult = DialogResult.OK;
-
- FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.rightButton;
- break;
- }
-
- //Set default button (used in FlexibleMaterialForm_Shown)
- FlexibleMaterialForm.defaultButton = defaultButton;
- }
-
- ///
- /// Handles the Shown event of the FlexibleMaterialForm control.
- ///
- /// The source of the event.
- /// The instance containing the event data.
- private void FlexibleMaterialForm_Shown(object sender, EventArgs e)
- {
- int buttonIndexToFocus = 1;
- Button buttonToFocus;
-
- //Set the default button...
- switch (this.defaultButton)
- {
- case MessageBoxDefaultButton.Button1:
- default:
- buttonIndexToFocus = 1;
- break;
-
- case MessageBoxDefaultButton.Button2:
- buttonIndexToFocus = 2;
- break;
-
- case MessageBoxDefaultButton.Button3:
- buttonIndexToFocus = 3;
- break;
- }
-
- if (buttonIndexToFocus > this.visibleButtonsCount)
- {
- buttonIndexToFocus = this.visibleButtonsCount;
- }
-
- if (buttonIndexToFocus == 3)
- {
- buttonToFocus = this.rightButton;
- }
- else if (buttonIndexToFocus == 2)
- {
- buttonToFocus = this.middleButton;
- }
- else
- {
- buttonToFocus = this.leftButton;
- }
-
- buttonToFocus.Focus();
- }
-
- ///
- /// Handles the LinkClicked event of the richTextBoxMessage control.
- ///
- /// The source of the event.
- /// The instance containing the event data.
- private void richTextBoxMessage_LinkClicked(object sender, LinkClickedEventArgs e)
- {
- try
- {
- Cursor.Current = Cursors.WaitCursor;
- Process.Start(e.LinkText);
- }
- catch (Exception)
- {
- //Let the caller of FlexibleMaterialForm decide what to do with this exception...
- throw;
- }
- finally
- {
- Cursor.Current = Cursors.Default;
- }
- }
-
- ///
- /// Handles the KeyUp event of the richTextBoxMessage control.
- ///
- /// The source of the event.
- /// The instance containing the event data.
- internal void FlexibleMaterialForm_KeyUp(object sender, KeyEventArgs e)
- {
- //Handle standard key strikes for clipboard copy: "Ctrl + C" and "Ctrl + Insert"
- if (e.Control && (e.KeyCode == Keys.C || e.KeyCode == Keys.Insert))
- {
- var buttonsTextLine = (this.leftButton.Visible ? this.leftButton.Text + STANDARD_MESSAGEBOX_SEPARATOR_SPACES : string.Empty)
- + (this.middleButton.Visible ? this.middleButton.Text + STANDARD_MESSAGEBOX_SEPARATOR_SPACES : string.Empty)
- + (this.rightButton.Visible ? this.rightButton.Text + STANDARD_MESSAGEBOX_SEPARATOR_SPACES : string.Empty);
-
- //Build same clipboard text like the standard .Net MessageBox
- var textForClipboard = STANDARD_MESSAGEBOX_SEPARATOR_LINES
- + this.Text + Environment.NewLine
- + STANDARD_MESSAGEBOX_SEPARATOR_LINES
- + this.richTextBoxMessage.Text + Environment.NewLine
- + STANDARD_MESSAGEBOX_SEPARATOR_LINES
- + buttonsTextLine.Replace("&", string.Empty) + Environment.NewLine
- + STANDARD_MESSAGEBOX_SEPARATOR_LINES;
-
- //Set text in clipboard
- Clipboard.SetText(textForClipboard);
- }
- }
-
- ///
- /// Gets or sets the CaptionText
- /// The text that is been used for the heading.
- ///
- public string CaptionText { get; set; }
-
- ///
- /// Gets or sets the MessageText
- /// The text that is been used in the FlexibleMaterialForm.
- ///
- public string MessageText { get; set; }
-
- ///
- /// Shows the specified message box.
- ///
- /// The owner.
- /// The text.
- /// The caption.
- /// The buttons.
- /// The icon.
- /// The default button.
- /// The dialog result.
- public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton)
- {
- //Create a new instance of the FlexibleMessageBox form
- var FlexibleMaterialForm = new FlexibleMaterialForm();
- FlexibleMaterialForm.ShowInTaskbar = false;
-
- //Bind the caption and the message text
- FlexibleMaterialForm.CaptionText = caption;
- FlexibleMaterialForm.MessageText = text;
- FlexibleMaterialForm.FlexibleMaterialFormBindingSource.DataSource = FlexibleMaterialForm;
-
- //Set the buttons visibilities and texts. Also set a default button.
- SetDialogButtons(FlexibleMaterialForm, buttons, defaultButton);
-
- //Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
- SetDialogIcon(FlexibleMaterialForm, icon);
-
- //Set the font for all controls
- FlexibleMaterialForm.Font = FONT;
- FlexibleMaterialForm.richTextBoxMessage.Font = FONT;
-
- //Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
- SetDialogSizes(FlexibleMaterialForm, text, caption);
-
- //Set the dialogs start position when given. Otherwise center the dialog on the current screen.
- SetDialogStartPosition(FlexibleMaterialForm, owner);
-
- //Show the dialog
- return FlexibleMaterialForm.ShowDialog(owner);
- }
-
- private void FlexibleMaterialForm_Load(object sender, EventArgs e)
- {
- }
- }
-}
\ No newline at end of file
+
+ ///
+ /// Defines the it
+ ///
+ it,
+
+ ///
+ /// Defines the fr
+ ///
+ fr,
+
+ ///
+ /// Defines the ro
+ ///
+ ro,
+
+ ///
+ /// Defines the pl
+ ///
+ pl,
+ ///
+ /// Defines the fa
+ ///
+ fa
+ };
+
+ ///
+ /// Defines the BUTTON_TEXTS_ENGLISH_EN
+ ///
+ private static readonly String[] BUTTON_TEXTS_ENGLISH_EN = { "OK", "Cancel", "&Yes", "&No", "&Abort", "&Retry", "&Ignore" };//Note: This is also the fallback language
+
+ ///
+ /// Defines the BUTTON_TEXTS_GERMAN_DE
+ ///
+ private static readonly String[] BUTTON_TEXTS_GERMAN_DE = { "OK", "Abbrechen", "&Ja", "&Nein", "&Abbrechen", "&Wiederholen", "&Ignorieren" };
+
+ ///
+ /// Defines the BUTTON_TEXTS_SPANISH_ES
+ ///
+ private static readonly String[] BUTTON_TEXTS_SPANISH_ES = { "Aceptar", "Cancelar", "&Sí", "&No", "&Abortar", "&Reintentar", "&Ignorar" };
+
+ ///
+ /// Defines the BUTTON_TEXTS_ITALIAN_IT
+ ///
+ private static readonly String[] BUTTON_TEXTS_ITALIAN_IT = { "OK", "Annulla", "&Sì", "&No", "&Interrompi", "&Riprova", "&Ignora" };
+
+ ///
+ /// Defines the BUTTON_TEXTS_FRENCH_FR
+ ///
+ private static readonly String[] BUTTON_TEXTS_FRENCH_FR = { "OK", "Annuler", "&Oui", "&Non", "&Interrompre", "&Recommencer", "&Ignorer" };
+
+ ///
+ /// Defines the BUTTON_TEXTS_ROMANIAN_RO
+ ///
+ private static readonly String[] BUTTON_TEXTS_ROMANIAN_RO = { "Acceptă", "Anulează", "&Da", "&Nu", "&Întrerupe", "&Reîncearcă", "&Ignoră" };
+
+ ///
+ /// Defines the BUTTON_TEXTS_ROMANIAN_PL
+ ///
+ private static readonly String[] BUTTON_TEXTS_POLISH_PL = { "OK", "Anuluj", "Tak", "Nie", "Opuść", "Powtórz", "Ignoruj" };
+
+ ///
+ /// Defines the BUTTON_TEXTS_ROMANIAN_PL
+ ///
+ private static readonly String[] BUTTON_TEXTS_PERSIAN_FA = { "حله", "انصراف", "بله", "خیر", "بیخیال", "دوباره", "رد کن" };//Note: This is also the fallback language
+
+ ///
+ /// Defines the defaultButton
+ ///
+ private MessageBoxDefaultButton defaultButton;
+
+ ///
+ /// Defines the visibleButtonsCount
+ ///
+ private int visibleButtonsCount;
+
+ ///
+ /// Defines the languageID
+ ///
+ private TwoLetterISOLanguageID languageID = TwoLetterISOLanguageID.en;
+
+ ///
+ /// Prevents a default instance of the class from being created.
+ ///
+ private FlexibleMaterialForm(RightToLeft rightToLeft) :base(rightToLeft)
+ {
+ InitializeComponent();
+
+ //Try to evaluate the language. If this fails, the fallback language English will be used
+ Enum.TryParse(CultureInfo.CurrentUICulture.TwoLetterISOLanguageName, out this.languageID);
+
+ this.KeyPreview = true;
+ this.KeyUp += FlexibleMaterialForm_KeyUp;
+
+ materialSkinManager = MaterialSkinManager.Instance;
+ materialSkinManager.AddFormToManage(this);
+ FONT = materialSkinManager.getFontByType(MaterialSkinManager.fontType.Body1, rightToLeft);
+ messageContainer.BackColor = this.BackColor;
+ }
+
+ ///
+ /// Gets the string rows.
+ ///
+ /// The message.
+ /// The string rows as 1-dimensional array
+ private static string[] GetStringRows(string message)
+ {
+ if (string.IsNullOrEmpty(message))
+ {
+ return null;
+ }
+
+ var messageRows = message.Split(new char[] { '\n' }, StringSplitOptions.None);
+ return messageRows;
+ }
+
+ ///
+ /// Gets the button text for the CurrentUICulture language.
+ /// Note: The fallback language is English
+ ///
+ /// The ID of the button.
+ /// The button text
+ private string GetButtonText(ButtonID buttonID)
+ {
+ var buttonTextArrayIndex = Convert.ToInt32(buttonID);
+
+ switch (this.languageID)
+ {
+ case TwoLetterISOLanguageID.de: return BUTTON_TEXTS_GERMAN_DE[buttonTextArrayIndex];
+ case TwoLetterISOLanguageID.es: return BUTTON_TEXTS_SPANISH_ES[buttonTextArrayIndex];
+ case TwoLetterISOLanguageID.it: return BUTTON_TEXTS_ITALIAN_IT[buttonTextArrayIndex];
+ case TwoLetterISOLanguageID.fr: return BUTTON_TEXTS_FRENCH_FR[buttonTextArrayIndex];
+ case TwoLetterISOLanguageID.ro: return BUTTON_TEXTS_ROMANIAN_RO[buttonTextArrayIndex];
+ case TwoLetterISOLanguageID.pl: return BUTTON_TEXTS_POLISH_PL[buttonTextArrayIndex];
+ case TwoLetterISOLanguageID.fa: return BUTTON_TEXTS_PERSIAN_FA[buttonTextArrayIndex];
+
+ default: return BUTTON_TEXTS_ENGLISH_EN[buttonTextArrayIndex];
+ }
+ }
+
+ ///
+ /// Ensure the given working area factor in the range of 0.2 - 1.0 where:
+ ///
+ /// 0.2 means: 20 percent of the working area height or width.
+ /// 1.0 means: 100 percent of the working area height or width.
+ ///
+ /// The given working area factor.
+ /// The corrected given working area factor.
+ private static double GetCorrectedWorkingAreaFactor(double workingAreaFactor)
+ {
+ const double MIN_FACTOR = 0.2;
+ const double MAX_FACTOR = 1.0;
+
+ if (workingAreaFactor < MIN_FACTOR)
+ {
+ return MIN_FACTOR;
+ }
+
+ if (workingAreaFactor > MAX_FACTOR)
+ {
+ return MAX_FACTOR;
+ }
+
+ return workingAreaFactor;
+ }
+
+ ///
+ /// Set the dialogs start position when given.
+ /// Otherwise center the dialog on the current screen.
+ ///
+ /// The FlexibleMessageBox dialog.
+ /// The owner.
+ private static void SetDialogStartPosition(FlexibleMaterialForm FlexibleMaterialForm, IWin32Window owner)
+ {
+ //If no owner given: Center on current screen
+ if (owner == null)
+ {
+ var screen = Screen.FromPoint(Cursor.Position);
+ FlexibleMaterialForm.StartPosition = FormStartPosition.Manual;
+ FlexibleMaterialForm.Left = screen.Bounds.Left + screen.Bounds.Width / 2 - FlexibleMaterialForm.Width / 2;
+ FlexibleMaterialForm.Top = screen.Bounds.Top + screen.Bounds.Height / 2 - FlexibleMaterialForm.Height / 2;
+ }
+ }
+
+ ///
+ /// Calculate the dialogs start size (Try to auto-size width to show longest text row).
+ /// Also set the maximum dialog size.
+ ///
+ /// The FlexibleMessageBox dialog.
+ /// The text (the longest text row is used to calculate the dialog width).
+ /// The caption
+ private static void SetDialogSizes(FlexibleMaterialForm FlexibleMaterialForm, string text, string caption)
+ {
+ //First set the bounds for the maximum dialog size
+ FlexibleMaterialForm.MaximumSize = new Size(Convert.ToInt32(SystemInformation.WorkingArea.Width * FlexibleMaterialForm.GetCorrectedWorkingAreaFactor(MAX_WIDTH_FACTOR)),
+ Convert.ToInt32(SystemInformation.WorkingArea.Height * FlexibleMaterialForm.GetCorrectedWorkingAreaFactor(MAX_HEIGHT_FACTOR)));
+
+ //Get rows. Exit if there are no rows to render...
+ var stringRows = GetStringRows(text);
+ if (stringRows == null)
+ {
+ return;
+ }
+
+ //Calculate whole text height
+ var textHeight = Math.Min(TextRenderer.MeasureText(text, FONT).Height, 600);
+
+ //Calculate width for longest text line
+ const int SCROLLBAR_WIDTH_OFFSET = 15;
+ var longestTextRowWidth = stringRows.Max(textForRow => TextRenderer.MeasureText(textForRow, FONT).Width);
+ var captionWidth = TextRenderer.MeasureText(caption, SystemFonts.CaptionFont).Width;
+ var textWidth = Math.Max(longestTextRowWidth + SCROLLBAR_WIDTH_OFFSET, captionWidth);
+
+ //Calculate margins
+ var marginWidth = FlexibleMaterialForm.Width - FlexibleMaterialForm.richTextBoxMessage.Width;
+ var marginHeight = FlexibleMaterialForm.Height - FlexibleMaterialForm.richTextBoxMessage.Height;
+
+ var minimumHeight = FlexibleMaterialForm.messageContainer.Top + (FlexibleMaterialForm.pictureBoxForIcon.Height + 2 * 8) + 54;
+ if (marginHeight < minimumHeight) marginHeight = minimumHeight;
+
+ //Set calculated dialog size (if the calculated values exceed the maximums, they were cut by windows forms automatically)
+ FlexibleMaterialForm.Size = new Size(textWidth + marginWidth,
+ textHeight + marginHeight);
+ }
+
+ ///
+ /// Set the dialogs icon.
+ /// When no icon is used: Correct placement and width of rich text box.
+ ///
+ /// The FlexibleMessageBox dialog.
+ /// The MessageBoxIcon.
+ private static void SetDialogIcon(FlexibleMaterialForm FlexibleMaterialForm, MessageBoxIcon icon)
+ {
+ switch (icon)
+ {
+ case MessageBoxIcon.Information:
+ FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Information.ToBitmap();
+ break;
+
+ case MessageBoxIcon.Warning:
+ FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Warning.ToBitmap();
+ break;
+
+ case MessageBoxIcon.Error:
+ FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Error.ToBitmap();
+ break;
+
+ case MessageBoxIcon.Question:
+ FlexibleMaterialForm.pictureBoxForIcon.Image = SystemIcons.Question.ToBitmap();
+ break;
+
+ default:
+ //When no icon is used: Correct placement and width of rich text box.
+ FlexibleMaterialForm.pictureBoxForIcon.Visible = false;
+ FlexibleMaterialForm.richTextBoxMessage.Left -= FlexibleMaterialForm.pictureBoxForIcon.Width;
+ FlexibleMaterialForm.richTextBoxMessage.Width += FlexibleMaterialForm.pictureBoxForIcon.Width;
+ break;
+ }
+ }
+
+ ///
+ /// Set dialog buttons visibilities and texts.
+ /// Also set a default button.
+ ///
+ /// The FlexibleMessageBox dialog.
+ /// The buttons.
+ /// The default button.
+ private static void SetDialogButtons(FlexibleMaterialForm FlexibleMaterialForm, MessageBoxButtons buttons, MessageBoxDefaultButton defaultButton, ButtonsPosition buttonsPosition)
+ {
+ //Set the buttons visibilities and texts
+ switch (buttons)
+ {
+ case MessageBoxButtons.AbortRetryIgnore:
+ FlexibleMaterialForm.visibleButtonsCount = 3;
+
+ FlexibleMaterialForm.leftButton.Visible = true;
+ FlexibleMaterialForm.leftButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.ABORT);
+ FlexibleMaterialForm.leftButton.DialogResult = DialogResult.Abort;
+
+ FlexibleMaterialForm.middleButton.Visible = true;
+ FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.RETRY);
+ FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Retry;
+
+ FlexibleMaterialForm.rightButton.Visible = true;
+ FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.IGNORE);
+ FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Ignore;
+
+ FlexibleMaterialForm.ControlBox = false;
+ break;
+
+ case MessageBoxButtons.OKCancel:
+ FlexibleMaterialForm.visibleButtonsCount = 2;
+
+ FlexibleMaterialForm.middleButton.Visible = true;
+ FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
+ FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Cancel;
+
+ FlexibleMaterialForm.rightButton.Visible = true;
+ FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.OK);
+ FlexibleMaterialForm.rightButton.DialogResult = DialogResult.OK;
+
+ FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.middleButton;
+ break;
+
+ case MessageBoxButtons.RetryCancel:
+ FlexibleMaterialForm.visibleButtonsCount = 2;
+
+ FlexibleMaterialForm.middleButton.Visible = true;
+ FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
+ FlexibleMaterialForm.middleButton.DialogResult = DialogResult.Cancel;
+
+ FlexibleMaterialForm.rightButton.Visible = true;
+ FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.RETRY);
+ FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Retry;
+
+ FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.middleButton;
+ break;
+
+ case MessageBoxButtons.YesNo:
+ FlexibleMaterialForm.visibleButtonsCount = 2;
+
+ FlexibleMaterialForm.middleButton.Visible = true;
+ FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.NO);
+ FlexibleMaterialForm.middleButton.DialogResult = DialogResult.No;
+
+ FlexibleMaterialForm.rightButton.Visible = true;
+ FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
+ FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;
+
+ //FlexibleMaterialForm.ControlBox = false;
+ break;
+
+ case MessageBoxButtons.YesNoCancel:
+ FlexibleMaterialForm.visibleButtonsCount = 3;
+
+ FlexibleMaterialForm.rightButton.Visible = true;
+ FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.YES);
+ FlexibleMaterialForm.rightButton.DialogResult = DialogResult.Yes;
+
+ FlexibleMaterialForm.middleButton.Visible = true;
+ FlexibleMaterialForm.middleButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.NO);
+ FlexibleMaterialForm.middleButton.DialogResult = DialogResult.No;
+
+ FlexibleMaterialForm.leftButton.Visible = true;
+ FlexibleMaterialForm.leftButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.CANCEL);
+ FlexibleMaterialForm.leftButton.DialogResult = DialogResult.Cancel;
+
+ FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.leftButton;
+ break;
+
+ case MessageBoxButtons.OK:
+ default:
+ FlexibleMaterialForm.visibleButtonsCount = 1;
+ FlexibleMaterialForm.rightButton.Visible = true;
+ FlexibleMaterialForm.rightButton.Text = FlexibleMaterialForm.GetButtonText(ButtonID.OK);
+ FlexibleMaterialForm.rightButton.DialogResult = DialogResult.OK;
+
+ FlexibleMaterialForm.CancelButton = FlexibleMaterialForm.rightButton;
+ break;
+ }
+
+ //Set default button (used in FlexibleMaterialForm_Shown)
+ FlexibleMaterialForm.defaultButton = defaultButton;
+
+ SetButtonsPosition(FlexibleMaterialForm, buttonsPosition);
+ }
+
+ ///
+ /// Handles the Shown event of the FlexibleMaterialForm control.
+ ///
+ /// The source of the event.
+ /// The instance containing the event data.
+ private void FlexibleMaterialForm_Shown(object sender, EventArgs e)
+ {
+ int buttonIndexToFocus = 1;
+ Button buttonToFocus;
+
+ //Set the default button...
+ switch (this.defaultButton)
+ {
+ case MessageBoxDefaultButton.Button1:
+ default:
+ buttonIndexToFocus = 1;
+ break;
+
+ case MessageBoxDefaultButton.Button2:
+ buttonIndexToFocus = 2;
+ break;
+
+ case MessageBoxDefaultButton.Button3:
+ buttonIndexToFocus = 3;
+ break;
+ }
+
+ if (buttonIndexToFocus > this.visibleButtonsCount)
+ {
+ buttonIndexToFocus = this.visibleButtonsCount;
+ }
+
+ if (buttonIndexToFocus == 3)
+ {
+ buttonToFocus = this.rightButton;
+ }
+ else if (buttonIndexToFocus == 2)
+ {
+ buttonToFocus = this.middleButton;
+ }
+ else
+ {
+ buttonToFocus = this.leftButton;
+ }
+
+ buttonToFocus.Focus();
+ }
+
+ ///
+ /// Handles the LinkClicked event of the richTextBoxMessage control.
+ ///
+ /// The source of the event.
+ /// The instance containing the event data.
+ private void richTextBoxMessage_LinkClicked(object sender, LinkClickedEventArgs e)
+ {
+ try
+ {
+ Cursor.Current = Cursors.WaitCursor;
+ Process.Start(e.LinkText);
+ }
+ catch (Exception)
+ {
+ //Let the caller of FlexibleMaterialForm decide what to do with this exception...
+ throw;
+ }
+ finally
+ {
+ Cursor.Current = Cursors.Default;
+ }
+ }
+
+ ///
+ /// Handles the KeyUp event of the richTextBoxMessage control.
+ ///
+ /// The source of the event.
+ /// The instance containing the event data.
+ internal void FlexibleMaterialForm_KeyUp(object sender, KeyEventArgs e)
+ {
+ //Handle standard key strikes for clipboard copy: "Ctrl + C" and "Ctrl + Insert"
+ if (e.Control && (e.KeyCode == Keys.C || e.KeyCode == Keys.Insert))
+ {
+ var buttonsTextLine = (this.leftButton.Visible ? this.leftButton.Text + STANDARD_MESSAGEBOX_SEPARATOR_SPACES : string.Empty)
+ + (this.middleButton.Visible ? this.middleButton.Text + STANDARD_MESSAGEBOX_SEPARATOR_SPACES : string.Empty)
+ + (this.rightButton.Visible ? this.rightButton.Text + STANDARD_MESSAGEBOX_SEPARATOR_SPACES : string.Empty);
+
+ //Build same clipboard text like the standard .Net MessageBox
+ var textForClipboard = STANDARD_MESSAGEBOX_SEPARATOR_LINES
+ + this.Text + Environment.NewLine
+ + STANDARD_MESSAGEBOX_SEPARATOR_LINES
+ + this.richTextBoxMessage.Text + Environment.NewLine
+ + STANDARD_MESSAGEBOX_SEPARATOR_LINES
+ + buttonsTextLine.Replace("&", string.Empty) + Environment.NewLine
+ + STANDARD_MESSAGEBOX_SEPARATOR_LINES;
+
+ //Set text in clipboard
+ Clipboard.SetText(textForClipboard);
+ }
+ }
+
+ ///
+ /// Gets or sets the CaptionText
+ /// The text that is been used for the heading.
+ ///
+ public string CaptionText { get; set; }
+
+ ///
+ /// Gets or sets the MessageText
+ /// The text that is been used in the FlexibleMaterialForm.
+ ///
+ public string MessageText { get; set; }
+
+ ///
+ /// Shows the specified message box.
+ ///
+ /// The owner.
+ /// The text.
+ /// The caption.
+ /// The buttons.
+ /// The icon.
+ /// The default button.
+ /// The dialog result.
+ public static DialogResult Show(IWin32Window owner, string text, string caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, bool UseRichTextBox = true, ButtonsPosition buttonsPosition = ButtonsPosition.Right,RightToLeft RightToLeft=RightToLeft.No)
+ {
+ //Create a new instance of the FlexibleMessageBox form
+ var FlexibleMaterialForm = new FlexibleMaterialForm(RightToLeft);
+ FlexibleMaterialForm.ShowInTaskbar = false;
+ FlexibleMaterialForm.Sizable = false;
+
+ //Bind the caption and the message text
+ FlexibleMaterialForm.CaptionText = caption;
+ FlexibleMaterialForm.MessageText = text;
+ FlexibleMaterialForm.FlexibleMaterialFormBindingSource.DataSource = FlexibleMaterialForm;
+
+
+ //Set the dialogs icon. When no icon is used: Correct placement and width of rich text box.
+ SetDialogIcon(FlexibleMaterialForm, icon);
+
+ //Set the font for all controls
+ FlexibleMaterialForm.Font = FONT;
+ FlexibleMaterialForm.richTextBoxMessage.Font = FONT;
+ FlexibleMaterialForm.richTextBoxMessage.Visible = UseRichTextBox;
+ FlexibleMaterialForm.materialLabel1.Font = FONT;
+ FlexibleMaterialForm.materialLabel1.Visible = !UseRichTextBox;
+
+ //Calculate the dialogs start size (Try to auto-size width to show longest text row). Also set the maximum dialog size.
+ SetDialogSizes(FlexibleMaterialForm, text, caption);
+
+ //Set the dialogs start position when given. Otherwise center the dialog on the current screen.
+ SetDialogStartPosition(FlexibleMaterialForm, owner);
+
+
+ //Set the buttons visibilities and texts. Also set a default button.
+ //Moved after SetDialogSizes() because it needs Dialog.Width property set.
+ SetDialogButtons(FlexibleMaterialForm, buttons, defaultButton, buttonsPosition);
+ //Show the dialog
+ return FlexibleMaterialForm.ShowDialog(owner);
+ }
+
+ private void FlexibleMaterialForm_Load(object sender, EventArgs e)
+ {
+ }
+
+ private static void SetButtonsPosition(FlexibleMaterialForm fMF, ButtonsPosition buttonsPosition)
+ {
+ const int padding = 10;
+ int visibleButtonsWidth = 0;
+ switch (buttonsPosition)
+ {
+ case ButtonsPosition.Center:
+ switch (fMF.visibleButtonsCount)
+ {
+ case 3:
+ fMF.middleButton.Left = fMF.Width / 2 - fMF.middleButton.Width / 2;
+ fMF.leftButton.Left = fMF.middleButton.Left - fMF.leftButton.Width - padding * 2;
+ fMF.rightButton.Left = fMF.middleButton.Right + padding * 2;
+ visibleButtonsWidth = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
+ break;
+ case 2:
+ fMF.middleButton.Left = fMF.Width / 2 - fMF.middleButton.Width - padding;
+ fMF.rightButton.Left = fMF.Width / 2 + padding;
+ visibleButtonsWidth = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
+ break;
+ case 1:
+ fMF.rightButton.Left = fMF.Width / 2 - fMF.rightButton.Width / 2;
+ visibleButtonsWidth = fMF.rightButton.Width + padding * 2;
+ break;
+ default:
+ break;
+ }
+ break;
+ case ButtonsPosition.Left:
+ switch (fMF.visibleButtonsCount)
+ {
+ case 3:
+ fMF.leftButton.Left = padding;
+ fMF.middleButton.Left = fMF.leftButton.Right + padding * 2;
+ fMF.rightButton.Left = fMF.middleButton.Right + padding * 2;
+ visibleButtonsWidth = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
+ break;
+ case 2:
+ fMF.middleButton.Left = padding;
+ fMF.rightButton.Left = fMF.middleButton.Right + padding * 2;
+ visibleButtonsWidth = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
+ break;
+ case 1:
+ fMF.rightButton.Left = padding;
+ visibleButtonsWidth = fMF.rightButton.Width + padding * 2;
+ break;
+ default:
+ break;
+ }
+ break;
+ case ButtonsPosition.Right:
+ // This alignment is simplest, in this alignment doesn't care how many buttons are visible.
+ // Always the buttons visibility order is right, right + middle, right + middle + left
+ fMF.rightButton.Left = fMF.Width - fMF.rightButton.Width - padding;
+ fMF.middleButton.Left = fMF.rightButton.Left - fMF.middleButton.Width - padding * 2;
+ fMF.leftButton.Left = fMF.middleButton.Left - fMF.leftButton.Width - padding * 2;
+ switch (fMF.visibleButtonsCount)
+ {
+ case 3:
+ visibleButtonsWidth = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
+ break;
+ case 2:
+ visibleButtonsWidth = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
+ break;
+ case 1:
+ visibleButtonsWidth = fMF.rightButton.Width + padding * 2;
+ break;
+ default:
+ break;
+ }
+ break;
+ case ButtonsPosition.Fill:
+ switch (fMF.visibleButtonsCount)
+ {
+ case 3:
+ fMF.leftButton.Left = padding;
+ fMF.middleButton.Left = fMF.Width / 2 - fMF.middleButton.Width / 2;
+ fMF.rightButton.Left = fMF.Width - fMF.rightButton.Width - padding * 2;
+ visibleButtonsWidth = fMF.leftButton.Width + fMF.middleButton.Width + fMF.rightButton.Width + padding * 6;
+ break;
+ case 2:
+ fMF.middleButton.Left = padding;
+ fMF.rightButton.Left = fMF.Width - fMF.rightButton.Width - padding * 2;
+ visibleButtonsWidth = fMF.middleButton.Width + fMF.rightButton.Width + padding * 4;
+ break;
+ case 1:
+ fMF.rightButton.Left = fMF.Width / 2 - fMF.middleButton.Width / 2;
+ visibleButtonsWidth = fMF.rightButton.Width + padding * 2;
+ break;
+ default:
+ break;
+ }
+ break;
+ }
+ fMF.Width = Math.Max(fMF.Width, visibleButtonsWidth);
+ }
+ }
+}
diff --git a/MaterialSkin/Controls/MaterialButton.cs b/MaterialSkin/Controls/MaterialButton.cs
index bfda5089..2ed50adf 100644
--- a/MaterialSkin/Controls/MaterialButton.cs
+++ b/MaterialSkin/Controls/MaterialButton.cs
@@ -1,468 +1,682 @@
-namespace MaterialSkin.Controls
-{
- using MaterialSkin.Animations;
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- using System.Windows.Forms;
-
- ///
- /// Defines the
- ///
- public class MaterialButton : Button, IMaterialControl
- {
- ///
- /// Gets or sets the Depth
- ///
- [Browsable(false)]
- public int Depth { get; set; }
-
- ///
- /// Gets the SkinManager
- ///
- [Browsable(false)]
- public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
-
- ///
- /// Gets or sets the MouseState
- ///
- [Browsable(false)]
- public MouseState MouseState { get; set; }
-
- public enum MaterialButtonType
- {
- Text,
- Outlined,
- Contained
- }
-
- public bool UseAccentColor
- {
- get { return useAccentColor; }
- set { useAccentColor = value; Invalidate(); }
- }
-
- ///
- /// Gets or sets a value indicating whether HighEmphasis
- ///
- public bool HighEmphasis
- {
- get { return highEmphasis; }
- set { highEmphasis = value; Invalidate(); }
- }
-
- public bool DrawShadows
- {
- get { return drawShadows; }
- set { drawShadows = value; Invalidate(); }
- }
-
- ///
- /// Gets or sets a value indicating whether HighEmphasis
- ///
- public MaterialButtonType Type
- {
- get { return type; }
- set { type = value; Invalidate(); }
- }
-
- protected override void InitLayout()
- {
- base.InitLayout();
- Invalidate();
- LocationChanged += (sender, e) => { if (DrawShadows) Parent?.Invalidate(); };
- }
-
- protected override void OnParentChanged(EventArgs e)
- {
- base.OnParentChanged(e);
- if (drawShadows && Parent != null) AddShadowPaintEvent(Parent, drawShadowOnParent);
- if (_oldParent != null) RemoveShadowPaintEvent(_oldParent, drawShadowOnParent);
- _oldParent = Parent;
- }
-
- private Control _oldParent;
-
- protected override void OnVisibleChanged(EventArgs e)
- {
- base.OnVisibleChanged(e);
- if (Parent == null) return;
- if (Visible)
- AddShadowPaintEvent(Parent, drawShadowOnParent);
- else
- RemoveShadowPaintEvent(Parent, drawShadowOnParent);
- }
-
+namespace MaterialSkin.Controls
+{
+ using MaterialSkin.Animations;
+ using System;
+ using System.ComponentModel;
+ using System.Drawing;
+ using System.Drawing.Drawing2D;
+ using System.Drawing.Imaging;
+ using System.Drawing.Text;
+ using System.Globalization;
+ using System.Windows.Forms;
+
+ ///
+ /// Defines the
+ ///
+ public class MaterialButton : Button, IMaterialControl
+ {
+
+ private const int ICON_SIZE = 24;
+ private const int MINIMUMWIDTH = 64;
+ private const int MINIMUMWIDTHICONONLY = 36; //64;
+ private const int HEIGHTDEFAULT = 36;
+ private const int HEIGHTDENSE = 32;
+
+ // icons
+ private TextureBrush iconsBrushes;
+
+ ///
+ /// Gets or sets the Depth
+ ///
+ [Browsable(false)]
+ public int Depth { get; set; }
+
+ ///
+ /// Gets the SkinManager
+ ///
+ [Browsable(false)]
+ public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
+
+ ///
+ /// Gets or sets the MouseState
+ ///
+ [Browsable(false)]
+ public MouseState MouseState { get; set; }
+
+ public enum MaterialButtonType
+ {
+ Text,
+ Outlined,
+ Contained
+ }
+
+ public enum MaterialButtonDensity
+ {
+ Default,
+ Dense
+ }
+
+ [Browsable(false)]
+ public Color NoAccentTextColor { get; set; }
+
+ [Category("Material Skin")]
+ public bool UseAccentColor
+ {
+ get { return useAccentColor; }
+ set { useAccentColor = value; Invalidate(); }
+ }
+
+ [Category("Material Skin")]
+ ///
+ /// Gets or sets a value indicating whether HighEmphasis
+ ///
+ public bool HighEmphasis
+ {
+ get { return highEmphasis; }
+ set { highEmphasis = value; Invalidate(); }
+ }
+
+ [DefaultValue(true)]
+ [Category("Material Skin")]
+ [Description("Draw Shadows around control")]
+ public bool DrawShadows
+ {
+ get { return drawShadows; }
+ set { drawShadows = value; Invalidate(); }
+ }
+
+ [Category("Material Skin")]
+ public MaterialButtonType Type
+ {
+ get { return type; }
+ set { type = value; preProcessIcons(); Invalidate(); }
+ }
+
+ [Category("Material Skin")]
+ ///
+ /// Gets or sets a value indicating button density
+ ///
+ public MaterialButtonDensity Density
+ {
+ get { return _density; }
+ set
+ {
+ _density = value;
+ if (_density== MaterialButtonDensity.Dense)
+ Size = new Size(Size.Width, HEIGHTDENSE);
+ else
+ Size = new Size(Size.Width, HEIGHTDEFAULT);
+ Invalidate();
+ }
+ }
+
+ public enum CharacterCasingEnum
+ {
+ Normal,
+ Lower,
+ Upper,
+ Title
+ }
+
+ public CharacterCasingEnum _cc;
+ [Category("Behavior"), DefaultValue(CharacterCasingEnum.Upper), Description("Change capitalization of Text property")]
+ public CharacterCasingEnum CharacterCasing
+ {
+ get => _cc;
+ set
+ {
+ _cc = value;
+ Invalidate();
+ }
+ }
+ protected override void InitLayout()
+ {
+ base.InitLayout();
+ Invalidate();
+ LocationChanged += (sender, e) => { if (DrawShadows) Parent?.Invalidate(); };
+ }
+
+ protected override void OnParentChanged(EventArgs e)
+ {
+ base.OnParentChanged(e);
+ if (drawShadows && Parent != null) AddShadowPaintEvent(Parent, drawShadowOnParent);
+ if (_oldParent != null) RemoveShadowPaintEvent(_oldParent, drawShadowOnParent);
+ _oldParent = Parent;
+ }
+
+ private Control _oldParent;
+
+ protected override void OnVisibleChanged(EventArgs e)
+ {
+ base.OnVisibleChanged(e);
+ if (Parent == null) return;
+ if (Visible)
+ AddShadowPaintEvent(Parent, drawShadowOnParent);
+ else
+ RemoveShadowPaintEvent(Parent, drawShadowOnParent);
+ }
+
+ protected override void OnEnabledChanged(EventArgs e)
+ {
+ base.OnEnabledChanged(e);
+ Invalidate();
+ }
+
private bool _shadowDrawEventSubscribed = false;
-
- private void AddShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
- {
- if (_shadowDrawEventSubscribed) return;
- control.Paint += shadowPaintEvent;
- control.Invalidate();
- _shadowDrawEventSubscribed = true;
+
+ private void AddShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
+ {
+ if (_shadowDrawEventSubscribed) return;
+ control.Paint += shadowPaintEvent;
+ control.Invalidate();
+ _shadowDrawEventSubscribed = true;
+ }
+
+ private void RemoveShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
+ {
+ if (!_shadowDrawEventSubscribed) return;
+ control.Paint -= shadowPaintEvent;
+ control.Invalidate();
+ _shadowDrawEventSubscribed = false;
+ }
+
+ private readonly AnimationManager _hoverAnimationManager = null;
+ private readonly AnimationManager _focusAnimationManager = null;
+ private readonly AnimationManager _animationManager = null;
+
+ ///
+ /// Defines the _textSize
+ ///
+ private SizeF _textSize;
+
+ ///
+ /// Defines the _icon
+ ///
+ private Image _icon;
+
+ private bool drawShadows;
+ private bool highEmphasis;
+ private bool useAccentColor;
+ private MaterialButtonType type;
+ private MaterialButtonDensity _density;
+
+ [Category("Material Skin")]
+ ///
+ /// Gets or sets the Icon
+ ///
+ public Image Icon
+ {
+ get { return _icon; }
+ set
+ {
+ _icon = value;
+ preProcessIcons();
+
+ if (AutoSize)
+ {
+ Refresh();
+ }
+
+ Invalidate();
+ }
+ }
+
+ [DefaultValue(true)]
+ public override bool AutoSize
+ {
+ get => base.AutoSize;
+ set => base.AutoSize = value;
+ }
+
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public MaterialButton()
+ {
+ DrawShadows = true;
+ HighEmphasis = true;
+ UseAccentColor = false;
+ Type = MaterialButtonType.Contained;
+ Density = MaterialButtonDensity.Default;
+ NoAccentTextColor = Color.Empty;
+ CharacterCasing = CharacterCasingEnum.Upper;
+
+ _animationManager = new AnimationManager(false)
+ {
+ Increment = 0.03,
+ AnimationType = AnimationType.EaseOut
+ };
+ _hoverAnimationManager = new AnimationManager
+ {
+ Increment = 0.12,
+ AnimationType = AnimationType.Linear
+ };
+ _focusAnimationManager = new AnimationManager
+ {
+ Increment = 0.12,
+ AnimationType = AnimationType.Linear
+ };
+ SkinManager.ColorSchemeChanged += sender =>
+ {
+ preProcessIcons();
+ };
+
+ SkinManager.ThemeChanged += sender =>
+ {
+ preProcessIcons();
+ };
+
+ _hoverAnimationManager.OnAnimationProgress += sender => Invalidate();
+ _focusAnimationManager.OnAnimationProgress += sender => Invalidate();
+ _animationManager.OnAnimationProgress += sender => Invalidate();
+
+ AutoSizeMode = AutoSizeMode.GrowAndShrink;
+ AutoSize = true;
+ Margin = new Padding(4, 6, 4, 6);
+ Padding = new Padding(0);
+ }
+
+ ///
+ /// Gets or sets the Text
+ ///
+ public override string Text
+ {
+ get { return base.Text; }
+ set
+ {
+ base.Text = value;
+ if (!String.IsNullOrEmpty(value))
+ _textSize = CreateGraphics().MeasureString(value.ToUpper(), SkinManager.getFontByType(MaterialSkinManager.fontType.Button, RightToLeft));
+ else
+ {
+ _textSize.Width = 0;
+ _textSize.Height = 0;
+ }
+
+ if (AutoSize)
+ {
+ Refresh();
+ }
+
+ Invalidate();
+ }
+ }
+
+ private void drawShadowOnParent(object sender, PaintEventArgs e)
+ {
+ if (Parent == null)
+ {
+ RemoveShadowPaintEvent((Control)sender, drawShadowOnParent);
+ return;
+ }
+
+ if (!DrawShadows || Type != MaterialButtonType.Contained || Parent == null) return;
+
+ // paint shadow on parent
+ Graphics gp = e.Graphics;
+ Rectangle rect = new Rectangle(Location, ClientRectangle.Size);
+ gp.SmoothingMode = SmoothingMode.AntiAlias;
+ DrawHelper.DrawSquareShadow(gp, rect);
+ }
+
+ private void preProcessIcons()
+ {
+ if (Icon == null) return;
+
+ int newWidth, newHeight;
+ //Resize icon if greater than ICON_SIZE
+ if (Icon.Width> ICON_SIZE || Icon.Height > ICON_SIZE)
+ {
+ //calculate aspect ratio
+ float aspect = Icon.Width / (float)Icon.Height;
+
+ //calculate new dimensions based on aspect ratio
+ newWidth = (int)(ICON_SIZE * aspect);
+ newHeight = (int)(newWidth / aspect);
+
+ //if one of the two dimensions exceed the box dimensions
+ if (newWidth > ICON_SIZE || newHeight > ICON_SIZE)
+ {
+ //depending on which of the two exceeds the box dimensions set it as the box dimension and calculate the other one based on the aspect ratio
+ if (newWidth > newHeight)
+ {
+ newWidth = ICON_SIZE;
+ newHeight = (int)(newWidth / aspect);
+ }
+ else
+ {
+ newHeight = ICON_SIZE;
+ newWidth = (int)(newHeight * aspect);
+ }
+ }
+ }
+ else
+ {
+ newWidth = Icon.Width;
+ newHeight = Icon.Height;
+ }
+
+ Bitmap IconResized = new Bitmap(Icon, newWidth, newHeight);
+
+ // Calculate lightness and color
+ float l = (SkinManager.Theme == MaterialSkinManager.Themes.LIGHT & (highEmphasis == false | Enabled == false | Type != MaterialButtonType.Contained)) ? 0f : 1.5f;
+
+ // Create matrices
+ float[][] matrixGray = {
+ new float[] { 0, 0, 0, 0, 0}, // Red scale factor
+ new float[] { 0, 0, 0, 0, 0}, // Green scale factor
+ new float[] { 0, 0, 0, 0, 0}, // Blue scale factor
+ new float[] { 0, 0, 0, Enabled ? .7f : .3f, 0}, // alpha scale factor
+ new float[] { l, l, l, 0, 1}};// offset
+
+
+ ColorMatrix colorMatrixGray = new ColorMatrix(matrixGray);
+
+ ImageAttributes grayImageAttributes = new ImageAttributes();
+
+ // Set color matrices
+ grayImageAttributes.SetColorMatrix(colorMatrixGray, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
+
+ // Image Rect
+ Rectangle destRect = new Rectangle(0, 0, ICON_SIZE, ICON_SIZE);
+
+ // Create a pre-processed copy of the image (GRAY)
+ Bitmap bgray = new Bitmap(destRect.Width, destRect.Height);
+ using (Graphics gGray = Graphics.FromImage(bgray))
+ {
+ gGray.DrawImage(IconResized,
+ new Point[] {
+ new Point(0, 0),
+ new Point(destRect.Width, 0),
+ new Point(0, destRect.Height),
+ },
+ destRect, GraphicsUnit.Pixel, grayImageAttributes);
+ }
+
+ // added processed image to brush for drawing
+ TextureBrush textureBrushGray = new TextureBrush(bgray);
+
+ textureBrushGray.WrapMode = System.Drawing.Drawing2D.WrapMode.Clamp;
+
+ // Translate the brushes to the correct positions
+ var iconRect = new Rectangle(8, (Height/2 - ICON_SIZE / 2), ICON_SIZE, ICON_SIZE);
+
+ textureBrushGray.TranslateTransform(iconRect.X + iconRect.Width / 2 - IconResized.Width / 2,
+ iconRect.Y + iconRect.Height / 2 - IconResized.Height / 2);
+
+ iconsBrushes = textureBrushGray;
+ }
+
+ ///
+ /// The OnPaint
+ ///
+ /// The pevent
+ protected override void OnPaint(PaintEventArgs pevent)
+ {
+ var g = pevent.Graphics;
+
+ g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
+ g.SmoothingMode = SmoothingMode.AntiAlias;
+
+ double hoverAnimProgress = _hoverAnimationManager.GetProgress();
+ double focusAnimProgress = _focusAnimationManager.GetProgress();
+
+ g.Clear(Parent.BackColor);
+
+ // button rectand path
+ RectangleF buttonRectF = new RectangleF(ClientRectangle.Location, ClientRectangle.Size);
+ buttonRectF.X -= 0.5f;
+ buttonRectF.Y -= 0.5f;
+ GraphicsPath buttonPath = DrawHelper.CreateRoundRect(buttonRectF, 4);
+
+ // button shadow (blend with form shadow)
+ DrawHelper.DrawSquareShadow(g, ClientRectangle);
+
+ if (Type == MaterialButtonType.Contained)
+ {
+ // draw button rect
+ // Disabled
+ if (!Enabled)
+ {
+ using (SolidBrush disabledBrush = new SolidBrush(DrawHelper.BlendColor(Parent.BackColor, SkinManager.BackgroundDisabledColor, SkinManager.BackgroundDisabledColor.A)))
+ {
+ g.FillPath(disabledBrush, buttonPath);
+ }
+ }
+ // High emphasis
+ else if (HighEmphasis)
+ {
+ g.FillPath(UseAccentColor ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush, buttonPath);
+ }
+ // Mormal
+ else
+ {
+ using (SolidBrush normalBrush = new SolidBrush(SkinManager.BackgroundColor))
+ {
+ g.FillPath(normalBrush, buttonPath);
+ }
+ }
+ }
+ else
+ {
+ g.Clear(Parent.BackColor);
+ }
+
+ //Hover
+ if (hoverAnimProgress > 0)
+ {
+ using (SolidBrush hoverBrush = new SolidBrush(Color.FromArgb(
+ (int)(HighEmphasis && Type == MaterialButtonType.Contained ? hoverAnimProgress * 80 : hoverAnimProgress * SkinManager.BackgroundHoverColor.A), (UseAccentColor ? (HighEmphasis && Type == MaterialButtonType.Contained ?
+ SkinManager.ColorScheme.AccentColor.Lighten(0.5f) : // Contained with Emphasis - with accent
+ SkinManager.ColorScheme.AccentColor) : // Not Contained Or Low Emphasis - with accent
+ (Type == MaterialButtonType.Contained && HighEmphasis ? SkinManager.ColorScheme.LightPrimaryColor : // Contained with Emphasis without accent
+ SkinManager.ColorScheme.PrimaryColor)).RemoveAlpha()))) // Normal or Emphasis without accent
+ {
+ g.FillPath(hoverBrush, buttonPath);
+ }
+ }
+
+ //Focus
+ if (focusAnimProgress > 0)
+ {
+ using (SolidBrush focusBrush = new SolidBrush(Color.FromArgb(
+ (int)(HighEmphasis && Type == MaterialButtonType.Contained ? focusAnimProgress * 80 : focusAnimProgress * SkinManager.BackgroundFocusColor.A), (UseAccentColor ? (HighEmphasis && Type == MaterialButtonType.Contained ?
+ SkinManager.ColorScheme.AccentColor.Lighten(0.5f) : // Contained with Emphasis - with accent
+ SkinManager.ColorScheme.AccentColor) : // Not Contained Or Low Emphasis - with accent
+ (Type == MaterialButtonType.Contained && HighEmphasis ? SkinManager.ColorScheme.LightPrimaryColor : // Contained with Emphasis without accent
+ SkinManager.ColorScheme.PrimaryColor)).RemoveAlpha()))) // Normal or Emphasis without accent
+ {
+ g.FillPath(focusBrush, buttonPath);
+ }
+ }
+
+ if (Type == MaterialButtonType.Outlined)
+ {
+ using (Pen outlinePen = new Pen(Enabled ? SkinManager.DividersAlternativeColor : SkinManager.DividersColor, 1))
+ {
+ buttonRectF.X += 0.5f;
+ buttonRectF.Y += 0.5f;
+ g.DrawPath(outlinePen, buttonPath);
+ }
+ }
+
+ //Ripple
+ if (_animationManager.IsAnimating())
+ {
+ g.Clip = new Region(buttonRectF);
+ for (var i = 0; i < _animationManager.GetAnimationCount(); i++)
+ {
+ var animationValue = _animationManager.GetProgress(i);
+ var animationSource = _animationManager.GetSource(i);
+
+ using (Brush rippleBrush = new SolidBrush(
+ Color.FromArgb((int)(100 - (animationValue * 100)), // Alpha animation
+ (Type == MaterialButtonType.Contained && HighEmphasis ? (UseAccentColor ?
+ SkinManager.ColorScheme.AccentColor.Lighten(0.5f) : // Emphasis with accent
+ SkinManager.ColorScheme.LightPrimaryColor) : // Emphasis
+ (UseAccentColor ? SkinManager.ColorScheme.AccentColor : // Normal with accent
+ SkinManager.Theme == MaterialSkinManager.Themes.LIGHT ? SkinManager.ColorScheme.PrimaryColor : SkinManager.ColorScheme.LightPrimaryColor))))) // Normal
+ {
+ var rippleSize = (int)(animationValue * Width * 2);
+ g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize));
+ }
+ }
+ g.ResetClip();
+ }
+
+ //Text
+ var textRect = ClientRectangle;
+ if (Icon != null)
+ {
+ textRect.Width -= 8 + ICON_SIZE + 4 + 8; // left padding + icon width + space between Icon and Text + right padding
+ textRect.X += 8 + ICON_SIZE + 4; // left padding + icon width + space between Icon and Text
+ }
+
+ Color textColor = Enabled ? (HighEmphasis ? (Type == MaterialButtonType.Text || Type == MaterialButtonType.Outlined) ?
+ UseAccentColor ? SkinManager.ColorScheme.AccentColor : // Outline or Text and accent and emphasis
+ NoAccentTextColor == Color.Empty ?
+ SkinManager.ColorScheme.PrimaryColor : // Outline or Text and emphasis
+ NoAccentTextColor : // User defined Outline or Text and emphasis
+ SkinManager.ColorScheme.TextColor : // Contained and Emphasis
+ SkinManager.TextHighEmphasisColor) : // Cointained and accent
+ SkinManager.TextDisabledOrHintColor; // Disabled
+
+ using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
+ {
+ NativeText.DrawMultilineTransparentText(
+ CharacterCasing == CharacterCasingEnum.Upper ? base.Text.ToUpper() : CharacterCasing == CharacterCasingEnum.Lower ? base.Text.ToLower() :
+ CharacterCasing == CharacterCasingEnum.Title ? CultureInfo.CurrentCulture.TextInfo.ToTitleCase(base.Text.ToLower()) : base.Text,
+ SkinManager.getLogFontByType(MaterialSkinManager.fontType.Button,RightToLeft),
+ textColor,
+ textRect.Location,
+ textRect.Size,
+ NativeTextRenderer.TextAlignFlags.Center | NativeTextRenderer.TextAlignFlags.Middle);
+ }
+
+ //Icon
+ var iconRect = new Rectangle(8, (Height / 2) - (ICON_SIZE / 2), ICON_SIZE, ICON_SIZE);
+
+ if (string.IsNullOrEmpty(Text))
+ {
+ // Center Icon
+ iconRect.X += 2;
+ }
+
+ if (Icon != null)
+ {
+ g.FillRectangle(iconsBrushes, iconRect);
+ }
+ }
+
+ ///
+ /// The GetPreferredSize
+ ///
+ /// The
+ private Size GetPreferredSize()
+ {
+ return GetPreferredSize(Size);
+ }
+
+ ///
+ /// The GetPreferredSize
+ ///
+ /// The proposedSize
+ /// The
+ public override Size GetPreferredSize(Size proposedSize)
+ {
+ Size s = base.GetPreferredSize(proposedSize);
+
+ // Provides extra space for proper padding for content
+ var extra = 16;
+
+ if (Icon != null)
+ {
+ // 24 is for icon size
+ // 4 is for the space between icon & text
+ extra += ICON_SIZE + 4;
+ }
+
+ if (AutoSize)
+ {
+ s.Width = (int)Math.Ceiling(_textSize.Width);
+ s.Width += extra;
+ s.Height = HEIGHTDEFAULT;
+ }
+ else
+ {
+ s.Width += extra;
+ s.Height = HEIGHTDEFAULT;
+ }
+ if (Icon != null && Text.Length==0 && s.Width < MINIMUMWIDTHICONONLY) s.Width = MINIMUMWIDTHICONONLY;
+ else if (s.Width < MINIMUMWIDTH) s.Width = MINIMUMWIDTH;
+
+ return s;
+ }
+
+ ///
+ /// The OnCreateControl
+ ///
+ protected override void OnCreateControl()
+ {
+ base.OnCreateControl();
+ // before checking DesignMode property, as long as we need see Icon in proper position
+ Resize += (sender, args) => { preProcessIcons(); Invalidate(); };
+
+ if (DesignMode)
+ {
+ return;
+ }
+
+ MouseState = MouseState.OUT;
+ MouseEnter += (sender, args) =>
+ {
+ MouseState = MouseState.HOVER;
+ _hoverAnimationManager.StartNewAnimation(AnimationDirection.In);
+ Invalidate();
+ };
+ MouseLeave += (sender, args) =>
+ {
+ MouseState = MouseState.OUT;
+ _hoverAnimationManager.StartNewAnimation(AnimationDirection.Out);
+ Invalidate();
+ };
+ MouseDown += (sender, args) =>
+ {
+ if (args.Button == MouseButtons.Left)
+ {
+ MouseState = MouseState.DOWN;
+
+ _animationManager.StartNewAnimation(AnimationDirection.In, args.Location);
+ Invalidate();
+ }
+ };
+ MouseUp += (sender, args) =>
+ {
+ MouseState = MouseState.HOVER;
+
+ Invalidate();
+ };
+
+ GotFocus += (sender, args) =>
+ {
+ _focusAnimationManager.StartNewAnimation(AnimationDirection.In);
+ Invalidate();
+ };
+ LostFocus += (sender, args) =>
+ {
+ MouseState = MouseState.OUT;
+ _focusAnimationManager.StartNewAnimation(AnimationDirection.Out);
+ Invalidate();
+ };
+
+ PreviewKeyDown += (object sender, PreviewKeyDownEventArgs e) =>
+ {
+ if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space)
+ {
+ _animationManager.StartNewAnimation(AnimationDirection.In, new Point(ClientRectangle.Width >> 1, ClientRectangle.Height >> 1));
+ Invalidate();
+ }
+ };
}
-
- private void RemoveShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
- {
- if (!_shadowDrawEventSubscribed) return;
- control.Paint -= shadowPaintEvent;
- control.Invalidate();
- _shadowDrawEventSubscribed = false;
- }
-
- private readonly AnimationManager _hoverAnimationManager = null;
- private readonly AnimationManager _animationManager = null;
-
- ///
- /// Defines the _textSize
- ///
- private SizeF _textSize;
-
- ///
- /// Defines the _icon
- ///
- private Image _icon;
-
- private bool drawShadows;
- private bool highEmphasis;
- private bool useAccentColor;
- private MaterialButtonType type;
-
- ///
- /// Gets or sets the Icon
- ///
- public Image Icon
- {
- get { return _icon; }
- set
- {
- _icon = value;
- if (AutoSize)
- {
- Refresh();
- }
-
- Invalidate();
- }
- }
-
- [DefaultValue(true)]
- public override bool AutoSize
- {
- get => base.AutoSize;
- set => base.AutoSize = value;
- }
-
- ///
- /// Initializes a new instance of the class.
- ///
- public MaterialButton()
- {
- DrawShadows = true;
- HighEmphasis = true;
- UseAccentColor = false;
- Type = MaterialButtonType.Contained;
-
- _animationManager = new AnimationManager(false)
- {
- Increment = 0.03,
- AnimationType = AnimationType.EaseOut
- };
- _hoverAnimationManager = new AnimationManager
- {
- Increment = 0.12,
- AnimationType = AnimationType.Linear
- };
-
- _hoverAnimationManager.OnAnimationProgress += sender => Invalidate();
- _animationManager.OnAnimationProgress += sender => Invalidate();
-
- AutoSizeMode = AutoSizeMode.GrowAndShrink;
- AutoSize = true;
- Margin = new Padding(4, 6, 4, 6);
- Padding = new Padding(0);
- }
-
- ///
- /// Gets or sets the Text
- ///
- public override string Text
- {
- get { return base.Text; }
- set
- {
- base.Text = value;
- _textSize = CreateGraphics().MeasureString(value.ToUpper(), SkinManager.getFontByType(MaterialSkinManager.fontType.Button));
- if (AutoSize)
- {
- Refresh();
- }
-
- Invalidate();
- }
- }
-
- private void drawShadowOnParent(object sender, PaintEventArgs e)
- {
- if (Parent == null)
- {
- RemoveShadowPaintEvent((Control)sender, drawShadowOnParent);
- return;
- }
-
- if (!DrawShadows || Type != MaterialButtonType.Contained || Parent == null) return;
-
- // paint shadow on parent
- Graphics gp = e.Graphics;
- Rectangle rect = new Rectangle(Location, ClientRectangle.Size);
- gp.SmoothingMode = SmoothingMode.AntiAlias;
- DrawHelper.DrawSquareShadow(gp, rect);
- }
-
- ///
- /// The OnPaint
- ///
- /// The pevent
- protected override void OnPaint(PaintEventArgs pevent)
- {
- var g = pevent.Graphics;
-
- g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- g.SmoothingMode = SmoothingMode.AntiAlias;
-
- double hoverAnimProgress = _hoverAnimationManager.GetProgress();
-
- g.Clear(Parent.BackColor);
-
- // button rectand path
- RectangleF buttonRectF = new RectangleF(ClientRectangle.Location, ClientRectangle.Size);
- buttonRectF.X -= 0.5f;
- buttonRectF.Y -= 0.5f;
- GraphicsPath buttonPath = DrawHelper.CreateRoundRect(buttonRectF, 4);
-
- // button shadow (blend with form shadow)
- DrawHelper.DrawSquareShadow(g, ClientRectangle);
-
- if (Type == MaterialButtonType.Contained)
- {
- // draw button rect
- // Disabled
- if (!Enabled)
- {
- using (SolidBrush disabledBrush = new SolidBrush(DrawHelper.BlendColor(Parent.BackColor, SkinManager.BackgroundDisabledColor, SkinManager.BackgroundDisabledColor.A)))
- {
- g.FillPath(disabledBrush, buttonPath);
- }
- }
- // High emphasis
- else if (HighEmphasis)
- {
- g.FillPath(UseAccentColor ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush, buttonPath);
- }
- // Mormal
- else
- {
- using (SolidBrush normalBrush = new SolidBrush(SkinManager.BackgroundColor))
- {
- g.FillPath(normalBrush, buttonPath);
- }
- }
- }
- else
- {
- g.Clear(Parent.BackColor);
- }
-
- //Hover
- using (SolidBrush hoverBrush = new SolidBrush(Color.FromArgb(
- (int)(hoverAnimProgress * SkinManager.BackgroundFocusColor.A), (UseAccentColor ? (HighEmphasis && Type == MaterialButtonType.Contained ?
- SkinManager.ColorScheme.AccentColor.Lighten(0.5f) : // Contained with Emphasis - with accent
- SkinManager.ColorScheme.AccentColor) : // Not Contained Or Low Emphasis - with accent
- (Type == MaterialButtonType.Contained && HighEmphasis ? SkinManager.ColorScheme.LightPrimaryColor : // Contained with Emphasis without accent
- SkinManager.ColorScheme.PrimaryColor)).RemoveAlpha()))) // Normal or Emphasis without accent
- {
- g.FillPath(hoverBrush, buttonPath);
- }
-
- if (Type == MaterialButtonType.Outlined)
- {
- using (Pen outlinePen = new Pen(Enabled ? SkinManager.DividersAlternativeColor : SkinManager.DividersColor, 1))
- {
- buttonRectF.X += 0.5f;
- buttonRectF.Y += 0.5f;
- g.DrawPath(outlinePen, buttonPath);
- }
- }
-
- //Ripple
- if (_animationManager.IsAnimating())
- {
- g.Clip = new Region(buttonRectF);
- for (var i = 0; i < _animationManager.GetAnimationCount(); i++)
- {
- var animationValue = _animationManager.GetProgress(i);
- var animationSource = _animationManager.GetSource(i);
-
- using (Brush rippleBrush = new SolidBrush(
- Color.FromArgb((int)(100 - (animationValue * 100)), // Alpha animation
- (Type == MaterialButtonType.Contained && HighEmphasis ? (UseAccentColor ?
- SkinManager.ColorScheme.AccentColor.Lighten(0.5f) : // Emphasis with accent
- SkinManager.ColorScheme.LightPrimaryColor) : // Emphasis
- (UseAccentColor ? SkinManager.ColorScheme.AccentColor : // Normal with accent
- SkinManager.Theme == MaterialSkinManager.Themes.LIGHT ? SkinManager.ColorScheme.PrimaryColor : SkinManager.ColorScheme.LightPrimaryColor))))) // Normal
- {
- var rippleSize = (int)(animationValue * Width * 2);
- g.FillEllipse(rippleBrush, new Rectangle(animationSource.X - rippleSize / 2, animationSource.Y - rippleSize / 2, rippleSize, rippleSize));
- }
- }
- g.ResetClip();
- }
-
- //Icon
- var iconRect = new Rectangle(8, 6, 24, 24);
-
- if (string.IsNullOrEmpty(Text))
- {
- // Center Icon
- iconRect.X += 2;
- }
-
- if (Icon != null)
- {
- g.DrawImage(Icon, iconRect);
- }
-
- //Text
- var textRect = ClientRectangle;
- if (Icon != null)
- {
- textRect.Width -= 8 + 24 + 4 + 8; // left padding + icon width + space between Icon and Text + right padding
- textRect.X += 8 + 24 + 4; // left padding + icon width + space between Icon and Text
- }
-
- Color textColor = Enabled ? (HighEmphasis ? (Type == MaterialButtonType.Text || Type == MaterialButtonType.Outlined) ?
- (UseAccentColor ? SkinManager.ColorScheme.AccentColor : // Outline or Text and accent and emphasis
- SkinManager.ColorScheme.PrimaryColor) : // Outline or Text and emphasis
- SkinManager.ColorScheme.TextColor : // Contained and Emphasis
- SkinManager.TextHighEmphasisColor) : // Cointained and accent
- SkinManager.TextDisabledOrHintColor; // Disabled
-
- using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
- {
- NativeText.DrawTransparentText(Text.ToUpper(), SkinManager.getLogFontByType(MaterialSkinManager.fontType.Button),
- textColor,
- textRect.Location,
- textRect.Size,
- NativeTextRenderer.TextAlignFlags.Center | NativeTextRenderer.TextAlignFlags.Middle);
- }
- }
-
- ///
- /// The GetPreferredSize
- ///
- /// The
- private Size GetPreferredSize()
- {
- return GetPreferredSize(Size);
- }
-
- ///
- /// The GetPreferredSize
- ///
- /// The proposedSize
- /// The
- public override Size GetPreferredSize(Size proposedSize)
- {
- Size s = base.GetPreferredSize(proposedSize);
-
- // Provides extra space for proper padding for content
- var extra = 16;
-
- if (Icon != null)
- {
- // 24 is for icon size
- // 4 is for the space between icon & text
- extra += 24 + 4;
- }
-
- if (AutoSize)
- {
- s.Width = (int)Math.Ceiling(_textSize.Width);
- s.Width += extra;
- s.Height = 36;
- }
- else
- {
- s.Width += extra;
- s.Height = 36;
- }
-
- return s;
- }
-
- ///
- /// The OnCreateControl
- ///
- protected override void OnCreateControl()
- {
- base.OnCreateControl();
- if (DesignMode)
- {
- return;
- }
-
- MouseState = MouseState.OUT;
- MouseEnter += (sender, args) =>
- {
- MouseState = MouseState.HOVER;
- _hoverAnimationManager.StartNewAnimation(AnimationDirection.In);
- Invalidate();
- };
- MouseLeave += (sender, args) =>
- {
- MouseState = MouseState.OUT;
- _hoverAnimationManager.StartNewAnimation(AnimationDirection.Out);
- Invalidate();
- };
- MouseDown += (sender, args) =>
- {
- if (args.Button == MouseButtons.Left)
- {
- MouseState = MouseState.DOWN;
-
- _animationManager.StartNewAnimation(AnimationDirection.In, args.Location);
- Invalidate();
- }
- };
- MouseUp += (sender, args) =>
- {
- MouseState = MouseState.HOVER;
-
- Invalidate();
- };
-
- GotFocus += (sender, args) =>
- {
- _hoverAnimationManager.StartNewAnimation(AnimationDirection.In);
- Invalidate();
- };
- LostFocus += (sender, args) =>
- {
- _hoverAnimationManager.StartNewAnimation(AnimationDirection.Out);
- Invalidate();
- };
-
- KeyDown += (object sender, KeyEventArgs e) =>
- {
- if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Space)
- {
- _animationManager.StartNewAnimation(AnimationDirection.In, new Point(ClientRectangle.Width >> 1, ClientRectangle.Height >> 1));
- Invalidate();
- }
- };
- }
- }
-}
\ No newline at end of file
+ }
+}
diff --git a/MaterialSkin/Controls/MaterialCard.cs b/MaterialSkin/Controls/MaterialCard.cs
index f72aea07..19b6334c 100644
--- a/MaterialSkin/Controls/MaterialCard.cs
+++ b/MaterialSkin/Controls/MaterialCard.cs
@@ -1,118 +1,118 @@
-namespace MaterialSkin.Controls
-{
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
-
- public class MaterialCard : Panel, IMaterialControl
- {
- [Browsable(false)]
- public int Depth { get; set; }
-
- [Browsable(false)]
- public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
-
- [Browsable(false)]
- public MouseState MouseState { get; set; }
-
- public MaterialCard()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
- Paint += new PaintEventHandler(paintControl);
- BackColor = SkinManager.BackgroundColor;
- ForeColor = SkinManager.TextHighEmphasisColor;
- Margin = new Padding(SkinManager.FORM_PADDING);
- Padding = new Padding(SkinManager.FORM_PADDING);
- }
-
- private void drawShadowOnParent(object sender, PaintEventArgs e)
- {
- if (Parent == null)
- {
- RemoveShadowPaintEvent((Control)sender, drawShadowOnParent);
- return;
- }
-
- // paint shadow on parent
- Graphics gp = e.Graphics;
- Rectangle rect = new Rectangle(Location, ClientRectangle.Size);
- gp.SmoothingMode = SmoothingMode.AntiAlias;
- DrawHelper.DrawSquareShadow(gp, rect);
- }
-
- protected override void InitLayout()
- {
- LocationChanged += (sender, e) => { Parent?.Invalidate(); };
- ForeColor = SkinManager.TextHighEmphasisColor;
- }
-
- protected override void OnParentChanged(EventArgs e)
- {
- base.OnParentChanged(e);
- if (Parent != null) AddShadowPaintEvent(Parent, drawShadowOnParent);
- if (_oldParent != null) RemoveShadowPaintEvent(_oldParent, drawShadowOnParent);
- _oldParent = Parent;
- }
-
- private Control _oldParent;
-
- protected override void OnVisibleChanged(EventArgs e)
- {
- base.OnVisibleChanged(e);
- if (Parent == null) return;
- if (Visible)
- AddShadowPaintEvent(Parent, drawShadowOnParent);
- else
- RemoveShadowPaintEvent(Parent, drawShadowOnParent);
- }
-
+namespace MaterialSkin.Controls
+{
+ using System;
+ using System.ComponentModel;
+ using System.Drawing;
+ using System.Drawing.Drawing2D;
+ using System.Windows.Forms;
+
+ public class MaterialCard : Panel, IMaterialControl
+ {
+ [Browsable(false)]
+ public int Depth { get; set; }
+
+ [Browsable(false)]
+ public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
+
+ [Browsable(false)]
+ public MouseState MouseState { get; set; }
+
+ public MaterialCard()
+ {
+ SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
+ Paint += new PaintEventHandler(paintControl);
+ BackColor = SkinManager.BackgroundColor;
+ ForeColor = SkinManager.TextHighEmphasisColor;
+ Margin = new Padding(SkinManager.FORM_PADDING);
+ Padding = new Padding(SkinManager.FORM_PADDING);
+ }
+
+ private void drawShadowOnParent(object sender, PaintEventArgs e)
+ {
+ if (Parent == null)
+ {
+ RemoveShadowPaintEvent((Control)sender, drawShadowOnParent);
+ return;
+ }
+
+ // paint shadow on parent
+ Graphics gp = e.Graphics;
+ Rectangle rect = new Rectangle(Location, ClientRectangle.Size);
+ gp.SmoothingMode = SmoothingMode.AntiAlias;
+ DrawHelper.DrawSquareShadow(gp, rect);
+ }
+
+ protected override void InitLayout()
+ {
+ LocationChanged += (sender, e) => { Parent?.Invalidate(); };
+ ForeColor = SkinManager.TextHighEmphasisColor;
+ }
+
+ protected override void OnParentChanged(EventArgs e)
+ {
+ base.OnParentChanged(e);
+ if (Parent != null) AddShadowPaintEvent(Parent, drawShadowOnParent);
+ if (_oldParent != null) RemoveShadowPaintEvent(_oldParent, drawShadowOnParent);
+ _oldParent = Parent;
+ }
+
+ private Control _oldParent;
+
+ protected override void OnVisibleChanged(EventArgs e)
+ {
+ base.OnVisibleChanged(e);
+ if (Parent == null) return;
+ if (Visible)
+ AddShadowPaintEvent(Parent, drawShadowOnParent);
+ else
+ RemoveShadowPaintEvent(Parent, drawShadowOnParent);
+ }
+
private bool _shadowDrawEventSubscribed = false;
-
- private void AddShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
- {
- if (_shadowDrawEventSubscribed) return;
- control.Paint += shadowPaintEvent;
- control.Invalidate();
- _shadowDrawEventSubscribed = true;
+
+ private void AddShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
+ {
+ if (_shadowDrawEventSubscribed) return;
+ control.Paint += shadowPaintEvent;
+ control.Invalidate();
+ _shadowDrawEventSubscribed = true;
+ }
+
+ private void RemoveShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
+ {
+ if (!_shadowDrawEventSubscribed) return;
+ control.Paint -= shadowPaintEvent;
+ control.Invalidate();
+ _shadowDrawEventSubscribed = false;
+ }
+
+ protected override void OnBackColorChanged(EventArgs e)
+ {
+ base.OnBackColorChanged(e);
+ BackColor = SkinManager.BackgroundColor;
+ }
+
+ private void paintControl(Object sender, PaintEventArgs e)
+ {
+ Graphics g = e.Graphics;
+ g.SmoothingMode = SmoothingMode.AntiAlias;
+
+ g.Clear(Parent.BackColor);
+
+ // card rectangle path
+ RectangleF cardRectF = new RectangleF(ClientRectangle.Location, ClientRectangle.Size);
+ cardRectF.X -= 0.5f;
+ cardRectF.Y -= 0.5f;
+ GraphicsPath cardPath = DrawHelper.CreateRoundRect(cardRectF, 4);
+
+ // button shadow (blend with form shadow)
+ DrawHelper.DrawSquareShadow(g, ClientRectangle);
+
+ // Draw card
+ using (SolidBrush normalBrush = new SolidBrush(BackColor))
+ {
+ g.FillPath(normalBrush, cardPath);
+ }
}
-
- private void RemoveShadowPaintEvent(Control control, PaintEventHandler shadowPaintEvent)
- {
- if (!_shadowDrawEventSubscribed) return;
- control.Paint -= shadowPaintEvent;
- control.Invalidate();
- _shadowDrawEventSubscribed = false;
- }
-
- protected override void OnBackColorChanged(EventArgs e)
- {
- base.OnBackColorChanged(e);
- BackColor = SkinManager.BackgroundColor;
- }
-
- private void paintControl(Object sender, PaintEventArgs e)
- {
- Graphics g = e.Graphics;
- g.SmoothingMode = SmoothingMode.AntiAlias;
-
- g.Clear(Parent.BackColor);
-
- // card rectangle path
- RectangleF cardRectF = new RectangleF(ClientRectangle.Location, ClientRectangle.Size);
- cardRectF.X -= 0.5f;
- cardRectF.Y -= 0.5f;
- GraphicsPath cardPath = DrawHelper.CreateRoundRect(cardRectF, 4);
-
- // button shadow (blend with form shadow)
- DrawHelper.DrawSquareShadow(g, ClientRectangle);
-
- // Draw card
- using (SolidBrush normalBrush = new SolidBrush(BackColor))
- {
- g.FillPath(normalBrush, cardPath);
- }
- }
- }
+ }
}
\ No newline at end of file
diff --git a/MaterialSkin/Controls/MaterialCheckBox.cs b/MaterialSkin/Controls/MaterialCheckBox.cs
index 06e5fb18..7a776912 100644
--- a/MaterialSkin/Controls/MaterialCheckBox.cs
+++ b/MaterialSkin/Controls/MaterialCheckBox.cs
@@ -10,6 +10,7 @@
public class MaterialCheckbox : CheckBox, IMaterialControl
{
+ #region Public properties
[Browsable(false)]
public int Depth { get; set; }
@@ -42,6 +43,11 @@ public bool Ripple
}
}
+ [Browsable(true)]
+ public bool ReadOnly { get; set; }
+ #endregion
+
+ #region Private fields
private readonly AnimationManager _checkAM;
private readonly AnimationManager _rippleAM;
private readonly AnimationManager _hoverAM;
@@ -51,7 +57,12 @@ public bool Ripple
private const int CHECKBOX_SIZE = 18;
private const int CHECKBOX_SIZE_HALF = CHECKBOX_SIZE / 2;
private int _boxOffset;
+ private static readonly Point[] CheckmarkLine = { new Point(3, 8), new Point(7, 12), new Point(14, 5) };
+ private bool hovered = false;
+ private CheckState _oldCheckState;
+ #endregion
+ #region Constructor
public MaterialCheckbox()
{
_checkAM = new AnimationManager
@@ -83,7 +94,9 @@ public MaterialCheckbox()
Height = HEIGHT_RIPPLE;
MouseLocation = new Point(-1, -1);
}
+ #endregion
+ #region Overridden events
protected override void OnSizeChanged(EventArgs e)
{
base.OnSizeChanged(e);
@@ -97,15 +110,13 @@ public override Size GetPreferredSize(Size proposedSize)
using (NativeTextRenderer NativeText = new NativeTextRenderer(CreateGraphics()))
{
- strSize = NativeText.MeasureLogString(Text, SkinManager.getLogFontByType(MaterialSkinManager.fontType.Body1));
+ strSize = NativeText.MeasureLogString(Text, SkinManager.getLogFontByType(MaterialSkinManager.fontType.Body1, RightToLeft));
}
int w = _boxOffset + TEXT_OFFSET + strSize.Width;
return Ripple ? new Size(w, HEIGHT_RIPPLE) : new Size(w, HEIGHT_NO_RIPPLE);
}
- private static readonly Point[] CheckmarkLine = { new Point(3, 8), new Point(7, 12), new Point(14, 5) };
-
protected override void OnPaint(PaintEventArgs pevent)
{
Graphics g = pevent.Graphics;
@@ -115,8 +126,9 @@ protected override void OnPaint(PaintEventArgs pevent)
// clear the control
g.Clear(Parent.BackColor);
- int CHECKBOX_CENTER = _boxOffset + CHECKBOX_SIZE_HALF - 1;
- Point animationSource = new Point(CHECKBOX_CENTER, CHECKBOX_CENTER);
+ int CHECKBOX_CENTER_X = RightToLeft==RightToLeft.Yes?Width - (_boxOffset + CHECKBOX_SIZE_HALF +1) : _boxOffset + CHECKBOX_SIZE_HALF - 1;
+ int CHECKBOX_CENTER_Y = _boxOffset + CHECKBOX_SIZE_HALF - 1;
+ Point animationSource = new Point(CHECKBOX_CENTER_X, CHECKBOX_CENTER_Y);
double animationProgress = _checkAM.GetProgress();
int colorAlpha = Enabled ? (int)(animationProgress * 255.0) : SkinManager.CheckBoxOffDisabledColor.A;
@@ -154,8 +166,9 @@ protected override void OnPaint(PaintEventArgs pevent)
}
}
- Rectangle checkMarkLineFill = new Rectangle(_boxOffset, _boxOffset, (int)(CHECKBOX_SIZE * animationProgress), CHECKBOX_SIZE);
- using (GraphicsPath checkmarkPath = DrawHelper.CreateRoundRect(_boxOffset - 0.5f, _boxOffset - 0.5f, CHECKBOX_SIZE, CHECKBOX_SIZE, 1))
+ var boxOffset_x = RightToLeft == RightToLeft.Yes ? Width - CHECKBOX_SIZE - _boxOffset : _boxOffset;
+ Rectangle checkMarkLineFill = new Rectangle(boxOffset_x , _boxOffset, (int)(CHECKBOX_SIZE * animationProgress), CHECKBOX_SIZE);
+ using (GraphicsPath checkmarkPath = DrawHelper.CreateRoundRect(boxOffset_x - 0.5f, _boxOffset - 0.5f, CHECKBOX_SIZE, CHECKBOX_SIZE, 1))
{
if (Enabled)
{
@@ -177,16 +190,18 @@ protected override void OnPaint(PaintEventArgs pevent)
g.DrawImageUnscaledAndClipped(DrawCheckMarkBitmap(), checkMarkLineFill);
}
-
+ var textAlignFlag = RightToLeft == RightToLeft.Yes ? NativeTextRenderer.TextAlignFlags.Right : NativeTextRenderer.TextAlignFlags.Left;
// draw checkbox text
using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
{
- Rectangle textLocation = new Rectangle(_boxOffset + TEXT_OFFSET, 0, Width - (_boxOffset + TEXT_OFFSET), HEIGHT_RIPPLE);
- NativeText.DrawTransparentText(Text, SkinManager.getLogFontByType(MaterialSkinManager.fontType.Body1),
+ var x = RightToLeft == RightToLeft.Yes ? 0 : _boxOffset + TEXT_OFFSET;
+ var w = RightToLeft == RightToLeft.Yes ? Width - (_boxOffset + TEXT_OFFSET) : Width;
+ Rectangle textLocation = new Rectangle(x, 0, w, HEIGHT_RIPPLE);
+ NativeText.DrawTransparentText(Text, SkinManager.getLogFontByType(MaterialSkinManager.fontType.Body1,RightToLeft),
Enabled ? SkinManager.TextHighEmphasisColor : SkinManager.TextDisabledOrHintColor,
textLocation.Location,
textLocation.Size,
- NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle);
+ textAlignFlag | NativeTextRenderer.TextAlignFlags.Middle);
}
// dispose used paint objects
@@ -194,23 +209,6 @@ protected override void OnPaint(PaintEventArgs pevent)
brush.Dispose();
}
- private Bitmap DrawCheckMarkBitmap()
- {
- Bitmap checkMark = new Bitmap(CHECKBOX_SIZE, CHECKBOX_SIZE);
- Graphics g = Graphics.FromImage(checkMark);
-
- // clear everything, transparent
- g.Clear(Color.Transparent);
-
- // draw the checkmark lines
- using (Pen pen = new Pen(Parent.BackColor, 2))
- {
- g.DrawLines(pen, CheckmarkLine);
- }
-
- return checkMark;
- }
-
public override bool AutoSize
{
get { return base.AutoSize; }
@@ -224,13 +222,6 @@ public override bool AutoSize
}
}
- private bool IsMouseInCheckArea()
- {
- return ClientRectangle.Contains(MouseLocation);
- }
-
- private bool hovered = false;
-
protected override void OnCreateControl()
{
base.OnCreateControl();
@@ -265,6 +256,7 @@ protected override void OnCreateControl()
// _hoverAM.StartNewAnimation(AnimationDirection.In, new object[] { Checked });
// hovered = true;
//}
+ _oldCheckState = CheckState;
};
MouseLeave += (sender, args) =>
@@ -286,6 +278,7 @@ protected override void OnCreateControl()
_rippleAM.SecondaryIncrement = 0;
_rippleAM.StartNewAnimation(AnimationDirection.InOutIn, new object[] { Checked });
}
+ if (ReadOnly) CheckState = _oldCheckState;
};
KeyDown += (sender, args) =>
@@ -295,6 +288,7 @@ protected override void OnCreateControl()
_rippleAM.SecondaryIncrement = 0;
_rippleAM.StartNewAnimation(AnimationDirection.InOutIn, new object[] { Checked });
}
+ if (ReadOnly) CheckState = _oldCheckState;
};
MouseUp += (sender, args) =>
@@ -306,6 +300,7 @@ protected override void OnCreateControl()
_hoverAM.StartNewAnimation(AnimationDirection.Out, new object[] { Checked });
hovered = false;
}
+ if (ReadOnly) CheckState = _oldCheckState;
};
KeyUp += (sender, args) =>
@@ -315,6 +310,7 @@ protected override void OnCreateControl()
MouseState = MouseState.HOVER;
_rippleAM.SecondaryIncrement = 0.08;
}
+ if (ReadOnly) CheckState = _oldCheckState;
};
MouseMove += (sender, args) =>
@@ -323,5 +319,30 @@ protected override void OnCreateControl()
Cursor = IsMouseInCheckArea() ? Cursors.Hand : Cursors.Default;
};
}
+ #endregion
+
+ #region Private events and methods
+ private Bitmap DrawCheckMarkBitmap()
+ {
+ Bitmap checkMark = new Bitmap(CHECKBOX_SIZE, CHECKBOX_SIZE);
+ Graphics g = Graphics.FromImage(checkMark);
+
+ // clear everything, transparent
+ g.Clear(Color.Transparent);
+
+ // draw the checkmark lines
+ using (Pen pen = new Pen(Parent.BackColor, 2))
+ {
+ g.DrawLines(pen, CheckmarkLine);
+ }
+
+ return checkMark;
+ }
+
+ private bool IsMouseInCheckArea()
+ {
+ return ClientRectangle.Contains(MouseLocation);
+ }
+ #endregion
}
}
\ No newline at end of file
diff --git a/MaterialSkin/Controls/MaterialCheckedListBox.cs b/MaterialSkin/Controls/MaterialCheckedListBox.cs
index eabc44ec..81bd372f 100644
--- a/MaterialSkin/Controls/MaterialCheckedListBox.cs
+++ b/MaterialSkin/Controls/MaterialCheckedListBox.cs
@@ -71,6 +71,7 @@ public void Add(string text, bool defaultValue)
Add(cb);
cb.Checked = defaultValue;
cb.Text = text;
+ cb.RightToLeft = RightToLeft.Inherit;
}
public new void Add(MaterialSkin.Controls.MaterialCheckbox value)
diff --git a/MaterialSkin/Controls/MaterialComboBox.cs b/MaterialSkin/Controls/MaterialComboBox.cs
index 6599fe2a..7f2482af 100644
--- a/MaterialSkin/Controls/MaterialComboBox.cs
+++ b/MaterialSkin/Controls/MaterialComboBox.cs
@@ -1,342 +1,405 @@
-namespace MaterialSkin.Controls
-{
- using MaterialSkin.Animations;
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Linq;
- using System.Windows.Forms;
-
- public class MaterialComboBox : ComboBox, IMaterialControl
- {
- // For some reason, even when overriding the AutoSize property, it doesn't appear on the properties panel, so we have to create a new one.
+namespace MaterialSkin.Controls
+{
+ using MaterialSkin.Animations;
+ using System;
+ using System.ComponentModel;
+ using System.Drawing;
+ using System.Linq;
+ using System.Data;
+ using System.Windows.Forms;
+
+ public class MaterialComboBox : ComboBox, IMaterialControl
+ {
+ // For some reason, even when overriding the AutoSize property, it doesn't appear on the properties panel, so we have to create a new one.
[Browsable(true), EditorBrowsable(EditorBrowsableState.Always), Category("Layout")]
- private bool _AutoResize;
-
- public bool AutoResize
- {
- get { return _AutoResize; }
- set
- {
- _AutoResize = value;
- recalculateAutoSize();
- }
- }
-
- //Properties for managing the material design properties
- [Browsable(false)]
- public int Depth { get; set; }
-
- [Browsable(false)]
- public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
-
- [Browsable(false)]
- public MouseState MouseState { get; set; }
-
+ private bool _AutoResize;
+
+ public bool AutoResize
+ {
+ get { return _AutoResize; }
+ set
+ {
+ _AutoResize = value;
+ recalculateAutoSize();
+ }
+ }
+
+ //Properties for managing the material design properties
+ [Browsable(false)]
+ public int Depth { get; set; }
+
+ [Browsable(false)]
+ public MaterialSkinManager SkinManager => MaterialSkinManager.Instance;
+
+ [Browsable(false)]
+ public MouseState MouseState { get; set; }
+
private bool _UseTallSize;
-
- [Category("Material Skin"), DefaultValue(true), Description("Using a larger size enables the hint to always be visible")]
- public bool UseTallSize
- {
- get { return _UseTallSize; }
- set
- {
- _UseTallSize = value;
- setHeightVars();
- Invalidate();
- }
- }
-
- [Category("Material Skin"), DefaultValue(true)]
- public bool UseAccent { get; set; }
-
+
+ [Category("Material Skin"), DefaultValue(true), Description("Using a larger size enables the hint to always be visible")]
+ public bool UseTallSize
+ {
+ get { return _UseTallSize; }
+ set
+ {
+ _UseTallSize = value;
+ setHeightVars();
+ Invalidate();
+ }
+ }
+
+ [Category("Material Skin"), DefaultValue(true)]
+ public bool UseAccent { get; set; }
+
private string _hint = string.Empty;
-
- [Category("Material Skin"), DefaultValue("")]
- public string Hint
- {
- get { return _hint; }
- set
- {
- _hint = value;
- hasHint = !String.IsNullOrEmpty(Hint);
- Invalidate();
- }
- }
-
- private const int TEXT_SMALL_SIZE = 18;
- private const int TEXT_SMALL_Y = 4;
- private const int BOTTOM_PADDING = 3;
- private int HEIGHT = 50;
- private int LINE_Y;
-
- private bool hasHint;
-
- private readonly AnimationManager _animationManager;
-
- public MaterialComboBox()
- {
- SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
-
- // Material Properties
- Hint = "";
- UseAccent = true;
- UseTallSize = true;
- MaxDropDownItems = 4;
-
- Font = SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle2);
- BackColor = SkinManager.BackgroundColor;
- ForeColor = SkinManager.TextHighEmphasisColor;
- DrawMode = DrawMode.OwnerDrawVariable;
- DropDownStyle = ComboBoxStyle.DropDownList;
- DropDownWidth = Width;
-
- // Animations
- _animationManager = new AnimationManager(true)
- {
- Increment = 0.08,
- AnimationType = AnimationType.EaseInOut
- };
- _animationManager.OnAnimationProgress += sender => Invalidate();
-
- DropDownClosed += (sender, args) =>
- {
- MouseState = MouseState.OUT;
- if (SelectedIndex < 0 && !Focused) _animationManager.StartNewAnimation(AnimationDirection.Out);
- };
- LostFocus += (sender, args) =>
- {
- MouseState = MouseState.OUT;
- if (SelectedIndex < 0) _animationManager.StartNewAnimation(AnimationDirection.Out);
- };
- DropDown += (sender, args) =>
- {
- _animationManager.StartNewAnimation(AnimationDirection.In);
- };
- GotFocus += (sender, args) =>
- {
- _animationManager.StartNewAnimation(AnimationDirection.In);
- };
- MouseEnter += (sender, args) =>
- {
- MouseState = MouseState.HOVER;
- Invalidate();
- };
- MouseLeave += (sender, args) =>
- {
- MouseState = MouseState.OUT;
- Invalidate();
- };
- }
-
- protected override void OnPaint(PaintEventArgs pevent)
- {
- Graphics g = pevent.Graphics;
-
- g.Clear(Parent.BackColor);
- g.FillRectangle(Enabled ? Focused ?
- SkinManager.BackgroundFocusBrush : // Focused
- MouseState == MouseState.HOVER ?
- SkinManager.BackgroundHoverBrush : // Hover
- SkinManager.BackgroundAlternativeBrush : // normal
- SkinManager.BackgroundDisabledBrush // Disabled
- , ClientRectangle.X, ClientRectangle.Y, ClientRectangle.Width, LINE_Y);
-
- // Create and Draw the arrow
- System.Drawing.Drawing2D.GraphicsPath pth = new System.Drawing.Drawing2D.GraphicsPath();
- PointF TopRight = new PointF(this.Width - 0.5f - SkinManager.FORM_PADDING, (this.Height >> 1) - 2.5f);
- PointF MidBottom = new PointF(this.Width - 4.5f - SkinManager.FORM_PADDING, (this.Height >> 1) + 2.5f);
- PointF TopLeft = new PointF(this.Width - 8.5f - SkinManager.FORM_PADDING, (this.Height >> 1) - 2.5f);
- pth.AddLine(TopLeft, TopRight);
- pth.AddLine(TopRight, MidBottom);
-
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
- g.FillPath((SolidBrush)(DroppedDown || Focused ? UseAccent ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush : SkinManager.TextHighEmphasisBrush), pth);
- g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
-
- // HintText
- bool userTextPresent = SelectedIndex >= 0;
- Rectangle hintRect = new Rectangle(SkinManager.FORM_PADDING, ClientRectangle.Y, Width, LINE_Y);
- int hintTextSize = 16;
-
- // bottom line base
- g.FillRectangle(SkinManager.DividersAlternativeBrush, 0, LINE_Y, Width, 1);
-
- if (!_animationManager.IsAnimating())
- {
- // No animation
- if (hasHint && UseTallSize && (DroppedDown || Focused || SelectedIndex >= 0))
- {
- // hint text
- hintRect = new Rectangle(SkinManager.FORM_PADDING, TEXT_SMALL_Y, Width, TEXT_SMALL_SIZE);
- hintTextSize = 12;
- }
-
- // bottom line
- if (DroppedDown || Focused)
- {
- g.FillRectangle(UseAccent ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush, 0, LINE_Y, Width, 2);
- }
- }
- else
- {
- // Animate - Focus got/lost
- double animationProgress = _animationManager.GetProgress();
-
- // hint Animation
- if (hasHint && UseTallSize)
- {
- hintRect = new Rectangle(
- SkinManager.FORM_PADDING,
- userTextPresent && !_animationManager.IsAnimating() ? (TEXT_SMALL_Y) : ClientRectangle.Y + (int)((TEXT_SMALL_Y - ClientRectangle.Y) * animationProgress),
- Width,
- userTextPresent && !_animationManager.IsAnimating() ? (TEXT_SMALL_SIZE) : (int)(LINE_Y + (TEXT_SMALL_SIZE - LINE_Y) * animationProgress));
- hintTextSize = userTextPresent && !_animationManager.IsAnimating() ? 12 : (int)(16 + (12 - 16) * animationProgress);
- }
-
- // Line Animation
- int LineAnimationWidth = (int)(Width * animationProgress);
- int LineAnimationX = (Width / 2) - (LineAnimationWidth / 2);
- g.FillRectangle(UseAccent ? SkinManager.ColorScheme.AccentBrush : SkinManager.ColorScheme.PrimaryBrush, LineAnimationX, LINE_Y, LineAnimationWidth, 2);
- }
-
- // Calc text Rect
- Rectangle textRect = new Rectangle(
- SkinManager.FORM_PADDING,
- hasHint && UseTallSize ? (hintRect.Y + hintRect.Height) - 2 : ClientRectangle.Y,
- ClientRectangle.Width - SkinManager.FORM_PADDING * 3 - 8,
- hasHint && UseTallSize ? LINE_Y - (hintRect.Y + hintRect.Height) : LINE_Y);
-
- g.Clip = new Region(textRect);
-
- using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
- {
- // Draw user text
- NativeText.DrawTransparentText(
- Text,
- SkinManager.getLogFontByType(MaterialSkinManager.fontType.Subtitle1),
- Enabled ? SkinManager.TextHighEmphasisColor : SkinManager.TextDisabledOrHintColor,
- textRect.Location,
- textRect.Size,
- NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle);
- }
-
- g.ResetClip();
-
- // Draw hint text
- if (hasHint && (UseTallSize || String.IsNullOrEmpty(Text)))
- {
- using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
- {
- NativeText.DrawTransparentText(
- Hint,
- SkinManager.getTextBoxFontBySize(hintTextSize),
- Enabled ? DroppedDown || Focused ? UseAccent ?
- SkinManager.ColorScheme.AccentColor : // Focus Accent
- SkinManager.ColorScheme.PrimaryColor : // Focus Primary
- SkinManager.TextMediumEmphasisColor : // not focused
- SkinManager.TextDisabledOrHintColor, // Disabled
- hintRect.Location,
- hintRect.Size,
- NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle);
- }
- }
- }
-
- private void CustomMeasureItem(object sender, System.Windows.Forms.MeasureItemEventArgs e)
- {
- e.ItemHeight = HEIGHT - 7;
- }
-
- private void CustomDrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
- {
- if (e.Index < 0 || e.Index > Items.Count || !Focused) return;
-
- Graphics g = e.Graphics;
-
- // Draw the background of the item.
- g.FillRectangle(SkinManager.BackgroundBrush, e.Bounds);
-
- // Hover
- if (e.State.HasFlag(DrawItemState.Focus)) // Focus == hover
- {
- g.FillRectangle(SkinManager.BackgroundHoverBrush, e.Bounds);
- }
-
- string Text = "";
- if (!string.IsNullOrWhiteSpace(DisplayMember))
- {
- Text = Items[e.Index].GetType().GetProperty(DisplayMember).GetValue(Items[e.Index], null).ToString();
- }
- else
- {
- Text = Items[e.Index].ToString();
- }
-
- using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
- {
- NativeText.DrawTransparentText(
- Text,
- SkinManager.getFontByType(MaterialSkinManager.fontType.Subtitle1),
- SkinManager.TextHighEmphasisColor,
- new Point(e.Bounds.Location.X + SkinManager.FORM_PADDING, e.Bounds.Location.Y),
- new Size(e.Bounds.Size.Width - SkinManager.FORM_PADDING * 2, e.Bounds.Size.Height),
- NativeTextRenderer.TextAlignFlags.Left | NativeTextRenderer.TextAlignFlags.Middle); ;
- }
- }
-
- protected override void OnCreateControl()
- {
- base.OnCreateControl();
- MouseState = MouseState.OUT;
- MeasureItem += CustomMeasureItem;
- DrawItem += CustomDrawItem;
- DropDownStyle = ComboBoxStyle.DropDownList;
- DrawMode = DrawMode.OwnerDrawVariable;
- recalculateAutoSize();
- setHeightVars();
- }
-
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- recalculateAutoSize();
- setHeightVars();
- }
-
- private void setHeightVars()
- {
- HEIGHT = UseTallSize ? 50 : 36;
- Size = new Size(Size.Width, HEIGHT);
- LINE_Y = HEIGHT - BOTTOM_PADDING;
- ItemHeight = HEIGHT - 7;
- DropDownHeight = ItemHeight * MaxDropDownItems + 2;
- }
-
- public void recalculateAutoSize()
- {
- if (!AutoResize) return;
-
- int w = DropDownWidth;
- int padding = SkinManager.FORM_PADDING * 3;
- int vertScrollBarWidth = (Items.Count > MaxDropDownItems) ? SystemInformation.VerticalScrollBarWidth : 0;
-
- Graphics g = CreateGraphics();
- using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
- {
- var itemsList = this.Items.Cast