diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644
index 00000000..6049a25d
--- /dev/null
+++ b/CHANGELOG.md
@@ -0,0 +1,80 @@
+
+
+This repo is a fork obtained from https://github.com/leocb/MaterialSkin.git
+ - Revision: e14384f49f142cde712951824f6c461b57a0032b
+ - Author: orapps44 <77468294+orapps44@users.noreply.github.com>
+ - Date: 06/02/2022 21:50:11
+
+
+
+build 2.3.1.4 [2022-02-20]
+-------------------------
+ - Enhancements:
+ - Added support for "UserControl" Containers
+ - Previous versions only supported placing controls like MaterialDialog if the Parent Container was of a type that inherits from Winform (Form class), like MaterialForm or plain Winform. Adding MaterialDialog control to a custom UserControl would generate a runtime exception because MaterialDialog._formOverlay was expecting an "Onwer" of type "Form" which is not the case when using parent containers like UserControls.
+ - Changed class "MaterialDialog" to expect a Parent-container of type "ContainerControl", Form and UserControl classes inherit from ContainControl class.
+ - Affected files:
+ - MaterialDialog.cs
+ - MaterialSkinManager.cs
+
+ - Improved design-mode experience of MaterialDrawer when combined with MaterialTabControl object. Now, during design-time, it's possible to view the drawer and the design impact on it when drawer's and tabcontrol's properties are changed by the user.
+
+ - Improved performance of MaterialDrawer during initialization
+ - Reduced the number of "Redraws" (Pain events) while the MaterialDrawer control is being initialized by its container.
+ - Previously, during MaterialDrawer's initialization, every property set done by the container that would impact drawer's UI would generate a redraw event (paint event).
+ - Now, MaterialDrawer control checks if its container has finish the initialization and if not ignores the redraw. When container invokes control's "InitLayout" method, meaning "end of control's initialization phase, future propertities changes will invoke a redraw action.
+
+
+
+
+build 2.3.1.3 [2022-02-20]
+-------------------------
+ - Code Cleansing:
+ - moved all p/invoke declarations to a new static class "NativeWin" (NativeWin.cs)
+ - there were a significant number of duplicated declarations on several controls
+ - affected files:
+ - NativeTextRenderer.cs
+ - MouseWheelRedirector.cs
+ - MaterialDialog.cs
+ - MaterialForm.cs
+ - MaterialMultiLineTextBox.cs
+ - MaterialMultiLineTextBox2.cs
+ - MaterialScrollBar.cs
+ - MaterialSnackBar.cs
+ - MaterialTextBox.cs
+ - MaterialSkinManager.cs
+
+ - moved several const declarations related to native Window Message IDs to new static class "NativeWin"
+ - affected files:
+ - MouseWheelRedirector.cs
+
+ - moved all possible category's labels to a new static class "CategoryLabels" (Globals.cs) and replaced the Category Labels by the corresponding const string
+ - affected files:
+ - MaterialButton.cs
+ - MaterialCheckBox.cs
+ - MaterialComboBox.cs
+ - MaterialDrawer.cs
+ - MaterialExpansionPanel.cs
+ - MaterialFloatingActionButton.cs
+ - MaterialForm.cs
+ - MaterialLabel.cs
+ - MaterialListBox.cs
+ - MaterialListView.cs
+ - MaterialMaskedTextBox.cs
+ - MaterialMultiLineTextBox.cs
+ - MaterialMultiLineTextBox2.cs
+ - MaterialRadioButton.cs
+ - MaterialScrollBar.cs
+ - MaterialSlider.cs
+ - MaterialSnackBar.cs
+ - MaterialSwitch.cs
+ - MaterialTabSelector.cs
+ - MaterialTextBox.cs
+ - MaterialTextBox2.cs
+
+ - moved several const declarations and enum declarations that were shared among files to a new file Globals.cs
+ - MaterialDrawer.cs
+
+ - Enhancement - compatibility with Msft CLI/C++:
+ - enum value MouseState.OUT (IMaterialControl.cs) renamed to MouseState.OUT_
+ - "OUT" keyword is a reserved word on CLI/C++.
diff --git a/MaterialSkin.sln b/MaterialSkin.sln
index 69f92cb6..af6e6ed1 100644
--- a/MaterialSkin.sln
+++ b/MaterialSkin.sln
@@ -1,4 +1,3 @@
-
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28307.136
@@ -9,6 +8,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MaterialSkin", "MaterialSki
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{17028688-3699-4BC7-849F-A6B0F6E766BC}"
ProjectSection(SolutionItems) = preProject
+ CHANGELOG.md = CHANGELOG.md
README.md = README.md
EndProjectSection
EndProject
diff --git a/MaterialSkin/Controls/MaterialButton.cs b/MaterialSkin/Controls/MaterialButton.cs
index 0dd9d164..9b53f0b3 100644
--- a/MaterialSkin/Controls/MaterialButton.cs
+++ b/MaterialSkin/Controls/MaterialButton.cs
@@ -24,7 +24,7 @@ public class MaterialButton : Button, IMaterialControl
// icons
private TextureBrush iconsBrushes;
-
+
///
/// Gets or sets the Depth
///
@@ -59,14 +59,14 @@ public enum MaterialButtonDensity
[Browsable(false)]
public Color NoAccentTextColor { get; set; }
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
public bool UseAccentColor
{
get { return useAccentColor; }
set { useAccentColor = value; Invalidate(); }
}
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
///
/// Gets or sets a value indicating whether HighEmphasis
///
@@ -77,7 +77,7 @@ public bool HighEmphasis
}
[DefaultValue(true)]
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
[Description("Draw Shadows around control")]
public bool DrawShadows
{
@@ -85,24 +85,24 @@ public bool DrawShadows
set { drawShadows = value; Invalidate(); }
}
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
public MaterialButtonType Type
{
get { return type; }
set { type = value; preProcessIcons(); Invalidate(); }
}
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
///
/// Gets or sets a value indicating button density
///
public MaterialButtonDensity Density
{
get { return _density; }
- set
- {
+ set
+ {
_density = value;
- if (_density== MaterialButtonDensity.Dense)
+ if (_density == MaterialButtonDensity.Dense)
Size = new Size(Size.Width, HEIGHTDENSE);
else
Size = new Size(Size.Width, HEIGHTDEFAULT);
@@ -119,7 +119,7 @@ public enum CharacterCasingEnum
}
public CharacterCasingEnum _cc;
- [Category("Behavior"), DefaultValue(CharacterCasingEnum.Upper), Description("Change capitalization of Text property")]
+ [Category(CategoryLabels.Behavior), DefaultValue(CharacterCasingEnum.Upper), Description("Change capitalization of Text property")]
public CharacterCasingEnum CharacterCasing
{
get => _cc;
@@ -200,7 +200,7 @@ private void RemoveShadowPaintEvent(Control control, PaintEventHandler shadowPai
private MaterialButtonType type;
private MaterialButtonDensity _density;
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
///
/// Gets or sets the Icon
///
@@ -325,7 +325,7 @@ private void preProcessIcons()
int newWidth, newHeight;
//Resize icon if greater than ICON_SIZE
- if (Icon.Width> ICON_SIZE || Icon.Height > ICON_SIZE)
+ if (Icon.Width > ICON_SIZE || Icon.Height > ICON_SIZE)
{
//calculate aspect ratio
float aspect = Icon.Width / (float)Icon.Height;
@@ -399,7 +399,7 @@ private void preProcessIcons()
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);
+ 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);
@@ -534,7 +534,7 @@ protected override void OnPaint(PaintEventArgs pevent)
Color textColor = Enabled ? (HighEmphasis ? (Type == MaterialButtonType.Text || Type == MaterialButtonType.Outlined) ?
UseAccentColor ? SkinManager.ColorScheme.AccentColor : // Outline or Text and accent and emphasis
- NoAccentTextColor == Color.Empty ?
+ 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
@@ -607,7 +607,7 @@ public override Size GetPreferredSize(Size proposedSize)
s.Width += extra;
s.Height = HEIGHTDEFAULT;
}
- if (Icon != null && Text.Length==0 && s.Width < MINIMUMWIDTHICONONLY) s.Width = MINIMUMWIDTHICONONLY;
+ if (Icon != null && Text.Length == 0 && s.Width < MINIMUMWIDTHICONONLY) s.Width = MINIMUMWIDTHICONONLY;
else if (s.Width < MINIMUMWIDTH) s.Width = MINIMUMWIDTH;
return s;
@@ -627,7 +627,7 @@ protected override void OnCreateControl()
return;
}
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
MouseEnter += (sender, args) =>
{
MouseState = MouseState.HOVER;
@@ -636,7 +636,7 @@ protected override void OnCreateControl()
};
MouseLeave += (sender, args) =>
{
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
_hoverAnimationManager.StartNewAnimation(AnimationDirection.Out);
Invalidate();
};
@@ -664,7 +664,7 @@ protected override void OnCreateControl()
};
LostFocus += (sender, args) =>
{
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
_focusAnimationManager.StartNewAnimation(AnimationDirection.Out);
Invalidate();
};
diff --git a/MaterialSkin/Controls/MaterialCheckBox.cs b/MaterialSkin/Controls/MaterialCheckBox.cs
index 82c58c32..5f759310 100644
--- a/MaterialSkin/Controls/MaterialCheckBox.cs
+++ b/MaterialSkin/Controls/MaterialCheckBox.cs
@@ -25,7 +25,7 @@ public class MaterialCheckbox : CheckBox, IMaterialControl
private bool _ripple;
- [Category("Appearance")]
+ [Category(CategoryLabels.Appearance)]
public bool Ripple
{
get { return _ripple; }
@@ -224,7 +224,7 @@ protected override void OnCreateControl()
if (DesignMode) return;
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
GotFocus += (sender, AddingNewEventArgs) =>
{
@@ -258,7 +258,7 @@ protected override void OnCreateControl()
MouseLeave += (sender, args) =>
{
MouseLocation = new Point(-1, -1);
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
//if (Ripple && hovered)
//{
// _hoverAM.StartNewAnimation(AnimationDirection.Out, new object[] { Checked });
diff --git a/MaterialSkin/Controls/MaterialComboBox.cs b/MaterialSkin/Controls/MaterialComboBox.cs
index b9abfdec..84ac95fc 100644
--- a/MaterialSkin/Controls/MaterialComboBox.cs
+++ b/MaterialSkin/Controls/MaterialComboBox.cs
@@ -11,7 +11,7 @@
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")]
+ [Browsable(true), EditorBrowsable(EditorBrowsableState.Always), Category(CategoryLabels.Layout)]
private bool _AutoResize;
public bool AutoResize
@@ -36,7 +36,7 @@ public bool AutoResize
private bool _UseTallSize;
- [Category("Material Skin"), DefaultValue(true), Description("Using a larger size enables the hint to always be visible")]
+ [Category(CategoryLabels.MaterialSkin), DefaultValue(true), Description("Using a taller size enables the hint to always be visible")]
public bool UseTallSize
{
get { return _UseTallSize; }
@@ -48,12 +48,12 @@ public bool UseTallSize
}
}
- [Category("Material Skin"), DefaultValue(true)]
+ [Category(CategoryLabels.MaterialSkin), DefaultValue(true)]
public bool UseAccent { get; set; }
private string _hint = string.Empty;
- [Category("Material Skin"), DefaultValue(""), Localizable(true)]
+ [Category(CategoryLabels.MaterialSkin), DefaultValue(""), Localizable(true)]
public string Hint
{
get { return _hint; }
@@ -120,12 +120,12 @@ public MaterialComboBox()
_animationManager.OnAnimationFinished += sender => _animationManager.SetProgress(0);
DropDownClosed += (sender, args) =>
{
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
if (SelectedIndex < 0 && !Focused) _animationManager.StartNewAnimation(AnimationDirection.Out);
};
LostFocus += (sender, args) =>
{
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
if (SelectedIndex < 0) _animationManager.StartNewAnimation(AnimationDirection.Out);
};
DropDown += (sender, args) =>
@@ -144,7 +144,7 @@ public MaterialComboBox()
};
MouseLeave += (sender, args) =>
{
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
Invalidate();
};
}
@@ -263,7 +263,7 @@ protected override void OnPaint(PaintEventArgs pevent)
NativeText.DrawTransparentText(
Hint,
SkinManager.getTextBoxFontBySize(hintTextSize),
- Enabled ? DroppedDown || Focused ?
+ Enabled ? DroppedDown || Focused ?
SelectedColor : // Focus
SkinManager.TextMediumEmphasisColor : // not focused
SkinManager.TextDisabledOrHintColor, // Disabled
@@ -293,7 +293,7 @@ private void CustomDrawItem(object sender, System.Windows.Forms.DrawItemEventArg
{
g.FillRectangle(SkinManager.BackgroundHoverBrush, e.Bounds);
}
-
+
string Text = "";
if (!string.IsNullOrWhiteSpace(DisplayMember))
{
@@ -328,7 +328,7 @@ private void CustomDrawItem(object sender, System.Windows.Forms.DrawItemEventArg
protected override void OnCreateControl()
{
base.OnCreateControl();
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
MeasureItem += CustomMeasureItem;
DrawItem += CustomDrawItem;
DropDownStyle = ComboBoxStyle.DropDownList;
diff --git a/MaterialSkin/Controls/MaterialDialog.cs b/MaterialSkin/Controls/MaterialDialog.cs
index 609999f9..0687b76a 100644
--- a/MaterialSkin/Controls/MaterialDialog.cs
+++ b/MaterialSkin/Controls/MaterialDialog.cs
@@ -31,22 +31,14 @@ public class MaterialDialog : MaterialForm
///
//public ObservableCollection Buttons { get; set; }
- [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")]
- private static extern IntPtr CreateRoundRectRgn
- (
- int nLeftRect, // x-coordinate of upper-left corner
- int nTopRect, // y-coordinate of upper-left corner
- int nRightRect, // x-coordinate of lower-right corner
- int nBottomRect, // y-coordinate of lower-right corner
- int nWidthEllipse, // width of ellipse
- int nHeightEllipse // height of ellipse
- );
///
/// Constructer Setting up the Layout
///
- public MaterialDialog(Form ParentForm, string Title, string Text, string ValidationButtonText, bool ShowCancelButton, string CancelButtonText, bool UseAccentColor)
+ public MaterialDialog(ContainerControl ParentForm, string Title, string Text, string ValidationButtonText, bool ShowCancelButton, string CancelButtonText, bool UseAccentColor)
{
+ Point locationFromScreen = ParentForm.PointToScreen(Point.Empty);
+
_formOverlay = new Form
{
BackColor = Color.Black,
@@ -59,9 +51,10 @@ public MaterialDialog(Form ParentForm, string Title, string Text, string Validat
FormBorderStyle = FormBorderStyle.None,
Size = new Size(ParentForm.Width, ParentForm.Height),
ShowInTaskbar = false,
- Owner = ParentForm,
+ Owner = null,
+ Tag = ParentForm,
Visible = true,
- Location = new Point(ParentForm.Location.X, ParentForm.Location.Y),
+ Location = locationFromScreen,
Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Bottom,
};
@@ -122,7 +115,7 @@ public MaterialDialog(Form ParentForm, string Title, string Text, string Validat
RectHeight + 9);
Height = _header_Height + TEXT_TOP_PADDING + textRect.Height + TEXT_BOTTOM_PADDING + 52; //560;
- Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 6, 6));
+ Region = System.Drawing.Region.FromHrgn(NativeWin.CreateRoundRectRgn(0, 0, Width, Height, 6, 6));
int _buttonWidth = ((TextRenderer.MeasureText(ValidationButtonText, SkinManager.getFontByType(MaterialSkinManager.fontType.Button))).Width + 32);
Rectangle _validationbuttonBounds = new Rectangle((Width) - BUTTON_PADDING - _buttonWidth, Height - BUTTON_PADDING - BUTTON_HEIGHT, _buttonWidth, BUTTON_HEIGHT);
@@ -145,31 +138,31 @@ public MaterialDialog(Form ParentForm, string Title, string Text, string Validat
//return materialDialogResult;
}
- public MaterialDialog(Form ParentForm) : this(ParentForm, "Title", "Dialog box", "OK", false, "Cancel", false)
+ public MaterialDialog(ContainerControl ParentForm) : this(ParentForm, "Title", "Dialog box", "OK", false, "Cancel", false)
{
}
- public MaterialDialog(Form ParentForm, string Text) : this(ParentForm, "Title", Text, "OK", false, "Cancel", false)
+ public MaterialDialog(ContainerControl ParentForm, string Text) : this(ParentForm, "Title", Text, "OK", false, "Cancel", false)
{
}
- public MaterialDialog(Form ParentForm, string Title, string Text) : this(ParentForm, Title, Text, "OK", false, "Cancel", false)
+ public MaterialDialog(ContainerControl ParentForm, string Title, string Text) : this(ParentForm, Title, Text, "OK", false, "Cancel", false)
{
}
- public MaterialDialog(Form ParentForm, string Title, string Text, string ValidationButtonText) : this(ParentForm, Title, Text, ValidationButtonText, false, "Cancel", false)
+ public MaterialDialog(ContainerControl ParentForm, string Title, string Text, string ValidationButtonText) : this(ParentForm, Title, Text, ValidationButtonText, false, "Cancel", false)
{
}
- public MaterialDialog(Form ParentForm, string Title, string Text, bool ShowCancelButton) : this(ParentForm, Title, Text, "OK", ShowCancelButton, "Cancel", false)
+ public MaterialDialog(ContainerControl ParentForm, string Title, string Text, bool ShowCancelButton) : this(ParentForm, Title, Text, "OK", ShowCancelButton, "Cancel", false)
{
}
- public MaterialDialog(Form ParentForm, string Title, string Text, bool ShowCancelButton, string CancelButtonText) : this(ParentForm, Title, Text, "OK", ShowCancelButton, CancelButtonText, false)
+ public MaterialDialog(ContainerControl ParentForm, string Title, string Text, bool ShowCancelButton, string CancelButtonText) : this(ParentForm, Title, Text, "OK", ShowCancelButton, CancelButtonText, false)
{
}
- public MaterialDialog(Form ParentForm, string Title, string Text, string ValidationButtonText, bool ShowCancelButton, string CancelButtonText) : this(ParentForm, Title, Text, ValidationButtonText, ShowCancelButton, CancelButtonText, false)
+ public MaterialDialog(ContainerControl ParentForm, string Title, string Text, string ValidationButtonText, bool ShowCancelButton, string CancelButtonText) : this(ParentForm, Title, Text, ValidationButtonText, ShowCancelButton, CancelButtonText, false)
{
}
@@ -181,7 +174,7 @@ protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
- Location = new Point(Convert.ToInt32(Owner.Location.X + (Owner.Width / 2) - (Width / 2)), Convert.ToInt32(Owner.Location.Y + (Owner.Height/2) - (Height / 2)));
+ Location = new Point(Convert.ToInt32(_formOverlay.Location.X + (_formOverlay.Width / 2) - (Width / 2)), Convert.ToInt32(_formOverlay.Location.Y + (_formOverlay.Height / 2) - (Height / 2)));
_AnimationManager.StartNewAnimation(AnimationDirection.In);
}
@@ -207,12 +200,12 @@ protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
e.Graphics.Clear(BackColor);
-
+
// Calc title Rect
Rectangle titleRect = new Rectangle(
LEFT_RIGHT_PADDING,
0,
- Width - (2 * LEFT_RIGHT_PADDING) ,
+ Width - (2 * LEFT_RIGHT_PADDING),
_header_Height);
//Draw title
@@ -236,9 +229,9 @@ protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
Rectangle textRect = new Rectangle(
LEFT_RIGHT_PADDING,
- _header_Height+17,
+ _header_Height + 17,
RectWidth,
- RectHeight +19);
+ RectHeight + 19);
//Draw Text
using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
diff --git a/MaterialSkin/Controls/MaterialDrawer.cs b/MaterialSkin/Controls/MaterialDrawer.cs
index 7a2cd6e0..c37b1e8d 100644
--- a/MaterialSkin/Controls/MaterialDrawer.cs
+++ b/MaterialSkin/Controls/MaterialDrawer.cs
@@ -16,7 +16,7 @@ public class MaterialDrawer : Control, IMaterialControl
private bool _showIconsWhenHidden;
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool ShowIconsWhenHidden
{
get
@@ -28,6 +28,10 @@ public bool ShowIconsWhenHidden
if (_showIconsWhenHidden != value)
{
_showIconsWhenHidden = value;
+
+ // control is still under initialization, ignore redraw
+ if (!_controlAddedToContainer) return;
+
UpdateTabRects();
preProcessIcons();
showHideAnimation();
@@ -39,7 +43,7 @@ public bool ShowIconsWhenHidden
private bool _isOpen;
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool IsOpen
{
get
@@ -49,6 +53,10 @@ public bool IsOpen
set
{
_isOpen = value;
+
+ // control is still under initialization, ignore UI change
+ if (!_controlAddedToContainer) return;
+
if (value)
Show();
else
@@ -56,13 +64,13 @@ public bool IsOpen
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool AutoHide { get; set; }
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool AutoShow { get; set; }
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
private bool _useColors;
public bool UseColors
@@ -74,12 +82,16 @@ public bool UseColors
set
{
_useColors = value;
+
+ // control is still under initialization, ignore redraw
+ if (!_controlAddedToContainer) return;
+
preProcessIcons();
Invalidate();
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
private bool _highlightWithAccent;
public bool HighlightWithAccent
@@ -91,12 +103,16 @@ public bool HighlightWithAccent
set
{
_highlightWithAccent = value;
+
+ // control is still under initialization, ignore redraw
+ if (!_controlAddedToContainer) return;
+
preProcessIcons();
Invalidate();
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
private bool _backgroundWithAccent;
public bool BackgroundWithAccent
@@ -108,11 +124,15 @@ public bool BackgroundWithAccent
set
{
_backgroundWithAccent = value;
+
+ // control is still under initialization, ignore redraw
+ if (!_controlAddedToContainer) return;
+
Invalidate();
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public int IndicatorWidth { get; set; }
[Browsable(false)]
@@ -151,7 +171,7 @@ public bool BackgroundWithAccent
private MaterialTabControl _baseTabControl;
- [Category("Behavior")]
+ [Category(CategoryLabels.Behavior)]
public MaterialTabControl BaseTabControl
{
get { return _baseTabControl; }
@@ -184,6 +204,10 @@ public MaterialTabControl BaseTabControl
{
Invalidate();
};
+
+ // control is still under initialization, ignore redraw
+ if (!_controlAddedToContainer) return;
+ Invalidate();
}
}
@@ -302,7 +326,7 @@ private void preProcessIcons()
private List _drawerItemRects;
private List _drawerItemPaths;
- private const int TAB_HEADER_PADDING = 24;
+
private const int BORDER_WIDTH = 7;
private int drawerItemHeight;
@@ -311,6 +335,13 @@ private void preProcessIcons()
private int _lastMouseY;
private int _lastLocationY;
+ ///
+ /// defines if the MaterialDrawer has been added to container's collection of controls
+ /// Used to decide when changes on MaterialDrawer's properties should trigger a Paint event.
+ /// The goal is to reduce the number of "Redraws" (Paint event) while the control is being initialized by its container.
+ ///
+ private bool _controlAddedToContainer = false;
+
public MaterialDrawer()
{
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
@@ -389,10 +420,16 @@ private void MaterialDrawer_MouseWheel(object sender, MouseEventArgs e)
}
}
+ ///
+ /// This method gets called when container adds this object to its collections of controls, ie, ContainerObject.Add({TLMaterialDrawer object})
+ ///
[EditorBrowsable(EditorBrowsableState.Advanced)]
protected override void InitLayout()
{
- drawerItemHeight = TAB_HEADER_PADDING * 2 - SkinManager.FORM_PADDING / 2;
+ // MaterialDrawer has been added to its Container. From now on trigger "Paint" event if properties are changed
+ _controlAddedToContainer = true;
+
+ drawerItemHeight = Globals.TAB_HEADER_PADDING * 2 - SkinManager.FORM_PADDING / 2;
MinWidth = (int)(SkinManager.FORM_PADDING * 1.5 + drawerItemHeight);
_showHideAnimManager.SetProgress(_isOpen ? 0 : 1);
showHideAnimation();
@@ -653,18 +690,18 @@ protected override void OnMouseUp(MouseEventArgs e)
base.OnMouseUp(e);
if (DesignMode)
return;
- MouseState = MouseState.OUT;
+ MouseState = MouseState.OUT_;
}
protected override void OnMouseMove(MouseEventArgs e)
{
if (DesignMode)
return;
-
+
if (e.Button == MouseButtons.Left && e.Y != _lastMouseY && (Location.Y < 0 || Height < (8 + drawerItemHeight) * _drawerItemRects.Count))
{
int diff = e.Y - _lastMouseY;
- if (diff > 0)
+ if (diff > 0)
{
if (Location.Y < 0)
{
@@ -672,7 +709,7 @@ protected override void OnMouseMove(MouseEventArgs e)
Height = Parent.Height + Math.Abs(Location.Y);
}
}
- else
+ else
{
if (Height < (8 + drawerItemHeight) * _drawerItemRects.Count)
{
@@ -682,12 +719,12 @@ protected override void OnMouseMove(MouseEventArgs e)
}
//return;
}
-
+
base.OnMouseMove(e);
if (_drawerItemRects == null)
UpdateTabRects();
-
+
Cursor previousCursor = Cursor;
if (e.Location.X + this.Location.X < BORDER_WIDTH)
@@ -716,7 +753,7 @@ protected override void OnMouseMove(MouseEventArgs e)
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
- if (AutoShow && _isOpen==false)
+ if (AutoShow && _isOpen == false)
{
Show();
}
@@ -766,7 +803,7 @@ private void UpdateTabRects()
{
_drawerItemRects[i] = (new Rectangle(
(int)(SkinManager.FORM_PADDING * 0.75) - (ShowIconsWhenHidden ? Location.X : 0),
- (TAB_HEADER_PADDING * 2) * i + (int)(SkinManager.FORM_PADDING >> 1),
+ (Globals.TAB_HEADER_PADDING * 2) * i + (int)(SkinManager.FORM_PADDING >> 1),
(Width + (ShowIconsWhenHidden ? Location.X : 0)) - (int)(SkinManager.FORM_PADDING * 1.5) - 1,
drawerItemHeight));
diff --git a/MaterialSkin/Controls/MaterialExpansionPanel.cs b/MaterialSkin/Controls/MaterialExpansionPanel.cs
index ce998b65..79e3e091 100644
--- a/MaterialSkin/Controls/MaterialExpansionPanel.cs
+++ b/MaterialSkin/Controls/MaterialExpansionPanel.cs
@@ -29,20 +29,20 @@ public class MaterialExpansionPanel : Panel, IMaterialControl
private const int _footerHeight = 68;
private const int _footerButtonHeight = 36;
private const int _minHeight = 200;
- private int _headerHeight ;
+ private int _headerHeight;
- private bool _collapse ;
+ private bool _collapse;
private bool _useAccentColor;
private int _expandHeight;
-
-
+
+
private string _titleHeader;
private string _descriptionHeader;
private string _validationButtonText;
private string _cancelButtonText;
-
-
-
+
+
+
private bool _showValidationButtons;
private bool _showCollapseExpand;
private bool _drawShadows;
@@ -77,7 +77,7 @@ private enum ButtonState
[Browsable(false)]
public MouseState MouseState { get; set; }
- [Category("Material Skin"), DefaultValue(false), DisplayName("Use Accent Color")]
+ [Category(CategoryLabels.MaterialSkin), DefaultValue(false), DisplayName("Use Accent Color")]
public bool UseAccentColor
{
get { return _useAccentColor; }
@@ -86,7 +86,7 @@ public bool UseAccentColor
[DefaultValue(false)]
[Description("Collapses the control when set to true")]
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
public bool Collapse
{
get { return _collapse; }
@@ -99,7 +99,7 @@ public bool Collapse
}
[DefaultValue("Title")]
- [Category("Material Skin"), DisplayName("Title")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Title")]
[Description("Title to show in expansion panel's header")]
public string Title
{
@@ -112,7 +112,7 @@ public string Title
}
[DefaultValue("Description")]
- [Category("Material Skin"), DisplayName("Description")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Description")]
[Description("Description to show in expansion panel's header")]
public string Description
{
@@ -125,7 +125,7 @@ public string Description
}
[DefaultValue(true)]
- [Category("Material Skin"), DisplayName("Draw Shadows")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Draw Shadows")]
[Description("Draw Shadows around control")]
public bool DrawShadows
{
@@ -134,7 +134,7 @@ public bool DrawShadows
}
[DefaultValue(240)]
- [Category("Material Skin"), DisplayName("Expand Height")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Expand Height")]
[Description("Define control height when expanded")]
public int ExpandHeight
{
@@ -143,7 +143,7 @@ public int ExpandHeight
}
[DefaultValue(true)]
- [Category("Material Skin"), DisplayName("Show collapse/expand")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Show collapse/expand")]
[Description("Show collapse/expand indicator")]
public bool ShowCollapseExpand
{
@@ -152,7 +152,7 @@ public bool ShowCollapseExpand
}
[DefaultValue(true)]
- [Category("Material Skin"), DisplayName("Show validation buttons")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Show validation buttons")]
[Description("Show save/cancel button")]
public bool ShowValidationButtons
{
@@ -161,7 +161,7 @@ public bool ShowValidationButtons
}
[DefaultValue("SAVE")]
- [Category("Material Skin"), DisplayName("Validation button text")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Validation button text")]
[Description("Set Validation button text")]
public string ValidationButtonText
{
@@ -170,7 +170,7 @@ public string ValidationButtonText
}
[DefaultValue("CANCEL")]
- [Category("Material Skin"), DisplayName("Cancel button text")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Cancel button text")]
[Description("Set Cancel button text")]
public string CancelButtonText
{
@@ -179,7 +179,7 @@ public string CancelButtonText
}
[DefaultValue(false)]
- [Category("Material Skin"), DisplayName("Validation button enable")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Validation button enable")]
[Description("Enable validation button")]
public bool ValidationButtonEnable
{
@@ -193,19 +193,19 @@ public bool ValidationButtonEnable
#region "Events"
- [Category("Action")]
+ [Category(CategoryLabels.Action)]
[Description("Fires when Save button is clicked")]
public event EventHandler SaveClick;
- [Category("Action")]
+ [Category(CategoryLabels.Action)]
[Description("Fires when Cancel button is clicked")]
public event EventHandler CancelClick;
- [Category("Disposition")]
+ [Category(CategoryLabels.Disposition)]
[Description("Fires when Panel Collapse")]
public event EventHandler PanelCollapse;
- [Category("Disposition")]
+ [Category(CategoryLabels.Disposition)]
[Description("Fires when Panel Expand")]
public event EventHandler PanelExpand;
@@ -231,9 +231,9 @@ public MaterialExpansionPanel()
ForeColor = SkinManager.TextHighEmphasisColor;
Padding = new Padding(24, 64, 24, 16);
- Margin = new Padding( 3, 16, 3, 16);
+ Margin = new Padding(3, 16, 3, 16);
Size = new Size(480, ExpandHeight);
-
+
//CollapseOrExpand();
_validationButton = new MaterialButton
@@ -254,18 +254,18 @@ public MaterialExpansionPanel()
Text = "CANCEL"
};
- if (!Controls.Contains(_validationButton) )
+ if (!Controls.Contains(_validationButton))
{
Controls.Add(_validationButton);
}
- if (!Controls.Contains(_cancelButton) )
+ if (!Controls.Contains(_cancelButton))
{
Controls.Add(_cancelButton);
}
_validationButton.Click += _validationButton_Click;
_cancelButton.Click += _cancelButton_Click;
-
+
UpdateRects();
}
@@ -383,7 +383,7 @@ protected override void OnResize(EventArgs e)
UpdateRects();
if (Parent != null)
- {
+ {
RemoveShadowPaintEvent(Parent, drawShadowOnParent);
AddShadowPaintEvent(Parent, drawShadowOnParent);
}
@@ -435,7 +435,7 @@ protected override void OnMouseDown(MouseEventArgs e)
return;
}
- base.OnMouseDown(e);
+ base.OnMouseDown(e);
}
protected override void OnMouseLeave(EventArgs e)
@@ -484,7 +484,7 @@ protected override void OnPaint(PaintEventArgs e)
expansionPanelBorderRectF.X -= 0.5f;
expansionPanelBorderRectF.Y -= 0.5f;
GraphicsPath expansionPanelBoarderPath = DrawHelper.CreateRoundRect(expansionPanelBorderRectF, 2);
-
+
g.FillPath(SkinManager.ExpansionPanelFocusBrush, expansionPanelBoarderPath);
}
else
@@ -517,13 +517,13 @@ protected override void OnPaint(PaintEventArgs e)
}
if (!String.IsNullOrEmpty(_descriptionHeader))
- {
+ {
//Draw description header text
Rectangle headerDescriptionRect = new Rectangle(
headerRect.Right + _expansionPanelDefaultPadding,
(_headerHeight - _textHeaderHeight) / 2,
- _expandcollapseBounds.Left - (headerRect.Right + _expansionPanelDefaultPadding ) - _expansionPanelDefaultPadding,
+ _expandcollapseBounds.Left - (headerRect.Right + _expansionPanelDefaultPadding) - _expansionPanelDefaultPadding,
_textHeaderHeight);
using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
@@ -539,7 +539,7 @@ protected override void OnPaint(PaintEventArgs e)
}
}
- if (_showCollapseExpand==true)
+ if (_showCollapseExpand == true)
{
using (var formButtonsPen = new Pen(_useAccentColor && Enabled ? SkinManager.ColorScheme.AccentColor : SkinManager.TextDisabledOrHintColor, 2))
{
diff --git a/MaterialSkin/Controls/MaterialFloatingActionButton.cs b/MaterialSkin/Controls/MaterialFloatingActionButton.cs
index ea48cb50..afdf31fc 100644
--- a/MaterialSkin/Controls/MaterialFloatingActionButton.cs
+++ b/MaterialSkin/Controls/MaterialFloatingActionButton.cs
@@ -27,12 +27,12 @@ public class MaterialFloatingActionButton : Button, IMaterialControl
private Boolean _mouseHover = false;
[DefaultValue(true)]
- [Category("Material Skin"), DisplayName("Draw Shadows")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Draw Shadows")]
[Description("Draw Shadows around control")]
public bool DrawShadows { get; set; }
[DefaultValue(false)]
- [Category("Material Skin"), DisplayName("Size Mini")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Size Mini")]
[Description("Set control size to default or mini")]
public bool Mini
{
@@ -45,10 +45,10 @@ public bool Mini
}
}
- private bool _mini ;
+ private bool _mini;
[DefaultValue(false)]
- [Category("Material Skin"), DisplayName("Animate Show HideButton")]
+ [Category(CategoryLabels.MaterialSkin), DisplayName("Animate Show HideButton")]
public bool AnimateShowHideButton
{
get { return _animateShowButton; }
@@ -58,7 +58,7 @@ public bool AnimateShowHideButton
private bool _animateShowButton;
[DefaultValue(false)]
- [Category("Material Skin")]
+ [Category(CategoryLabels.MaterialSkin)]
[Description("Define icon to display")]
public Image Icon
{
@@ -187,10 +187,10 @@ protected override void OnPaint(PaintEventArgs pevent)
DrawHelper.DrawRoundShadow(g, fabBounds);
// draw fab
- g.FillEllipse(Enabled ? _mouseHover ?
- new SolidBrush(SkinManager.ColorScheme.AccentColor.Lighten(0.25f)) :
+ g.FillEllipse(Enabled ? _mouseHover ?
+ new SolidBrush(SkinManager.ColorScheme.AccentColor.Lighten(0.25f)) :
SkinManager.ColorScheme.AccentBrush :
- new SolidBrush(DrawHelper.BlendColor(SkinManager.ColorScheme.AccentColor, SkinManager.SwitchOffDisabledThumbColor, 197)),
+ new SolidBrush(DrawHelper.BlendColor(SkinManager.ColorScheme.AccentColor, SkinManager.SwitchOffDisabledThumbColor, 197)),
fabBounds);
if (_animationManager.IsAnimating())
@@ -263,7 +263,7 @@ protected override void OnMouseLeave(EventArgs e)
protected override void OnResize(EventArgs e)
{
- base.OnResize(e);
+ base.OnResize(e);
if (DrawShadows && Parent != null)
{
diff --git a/MaterialSkin/Controls/MaterialForm.cs b/MaterialSkin/Controls/MaterialForm.cs
index e777a3cc..05eabb42 100644
--- a/MaterialSkin/Controls/MaterialForm.cs
+++ b/MaterialSkin/Controls/MaterialForm.cs
@@ -9,9 +9,9 @@ namespace MaterialSkin.Controls
using System.Runtime.InteropServices;
using System.Windows.Forms;
- #if NETFRAMEWORK
+#if NETFRAMEWORK
using System.Runtime.Remoting.Channels;
- #endif
+#endif
public class MaterialForm : Form, IMaterialControl
{
@@ -25,10 +25,10 @@ public class MaterialForm : Form, IMaterialControl
[Browsable(false)]
public MouseState MouseState { get; set; }
- [Category("Layout")]
+ [Category(CategoryLabels.Layout)]
public bool Sizable { get; set; }
- [Category("Material Skin"), Browsable(true), DisplayName("Form Style"), DefaultValue(FormStyles.ActionBar_40)]
+ [Category(CategoryLabels.MaterialSkin), Browsable(true), DisplayName("Form Style"), DefaultValue(FormStyles.ActionBar_40)]
public FormStyles FormStyle
{
get => _formStyle;
@@ -41,7 +41,7 @@ public FormStyles FormStyle
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerShowIconsWhenHidden
{
get => _drawerShowIconsWhenHidden;
@@ -58,27 +58,27 @@ public bool DrawerShowIconsWhenHidden
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public int DrawerWidth { get; set; }
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerAutoHide
{
get => _drawerAutoHide;
set => drawerControl.AutoHide = _drawerAutoHide = value;
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerAutoShow
{
get => _drawerAutoShow;
set => drawerControl.AutoShow = _drawerAutoShow = value;
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public int DrawerIndicatorWidth { get; set; }
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerIsOpen
{
get => _drawerIsOpen;
@@ -95,7 +95,7 @@ public bool DrawerIsOpen
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerUseColors
{
get => _drawerUseColors;
@@ -112,7 +112,7 @@ public bool DrawerUseColors
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerHighlightWithAccent
{
get => _drawerHighlightWithAccent;
@@ -129,7 +129,7 @@ public bool DrawerHighlightWithAccent
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public bool DrawerBackgroundWithAccent
{
get => _backgroundWithAccent;
@@ -146,7 +146,7 @@ public bool DrawerBackgroundWithAccent
}
}
- [Category("Drawer")]
+ [Category(CategoryLabels.Drawer)]
public MaterialTabControl DrawerTabControl { get; set; }
public override string Text
@@ -222,133 +222,7 @@ private enum ButtonState
None
}
- ///
- /// Window Messages
- ///
- ///
- private enum WM
- {
- ///
- /// WM_NCCALCSIZE
- ///
- NonClientCalcSize = 0x0083,
- ///
- /// WM_NCACTIVATE
- ///
- NonClientActivate = 0x0086,
- ///
- /// WM_NCLBUTTONDOWN
- ///
- NonClientLeftButtonDown = 0x00A1,
- ///
- /// WM_SYSCOMMAND
- ///
- SystemCommand = 0x0112,
- ///
- /// WM_MOUSEMOVE
- ///
- MouseMove = 0x0200,
- ///
- /// WM_LBUTTONDOWN
- ///
- LeftButtonDown = 0x0201,
- ///
- /// WM_LBUTTONUP
- ///
- LeftButtonUp = 0x0202,
- ///
- /// WM_LBUTTONDBLCLK
- ///
- LeftButtonDoubleClick = 0x0203,
- ///
- /// WM_RBUTTONDOWN
- ///
- RightButtonDown = 0x0204,
- }
- ///
- /// Hit Test Results
- ///
- ///
- private enum HT
- {
- ///
- /// HTNOWHERE - Nothing under cursor
- ///
- None = 0,
- ///
- /// HTCAPTION - Titlebar
- ///
- Caption = 2,
- ///
- /// HTLEFT - Left border
- ///
- Left = 10,
- ///
- /// HTRIGHT - Right border
- ///
- Right = 11,
- ///
- /// HTTOP - Top border
- ///
- Top = 12,
- ///
- /// HTTOPLEFT - Top left corner
- ///
- TopLeft = 13,
- ///
- /// HTTOPRIGHT - Top right corner
- ///
- TopRight = 14,
- ///
- /// HTBOTTOM - Bottom border
- ///
- Bottom = 15,
- ///
- /// HTBOTTOMLEFT - Bottom left corner
- ///
- BottomLeft = 16,
- ///
- /// HTBOTTOMRIGHT - Bottom right corner
- ///
- BottomRight = 17,
- }
-
- ///
- /// Window Styles
- ///
- ///
- private enum WS
- {
- ///
- /// WS_MINIMIZEBOX - Allow minimizing from taskbar
- ///
- MinimizeBox = 0x20000,
- ///
- /// WS_SIZEFRAME - Required for Aero Snapping
- ///
- SizeFrame = 0x40000,
- ///
- /// WS_SYSMENU - Trigger the creation of the system menu
- ///
- SysMenu = 0x80000,
- }
-
- ///
- /// Track Popup Menu Flags
- ///
- ///
- private enum TPM
- {
- ///
- /// TPM_LEFTALIGN
- ///
- LeftAlign = 0x0000,
- ///
- /// TPM_RETURNCMD
- ///
- ReturnCommand = 0x0100,
- }
#endregion
#region Constants
@@ -429,7 +303,7 @@ public MaterialForm()
SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw, true);
FormStyle = FormStyles.ActionBar_40;
- Padding = new Padding(PADDING_MINIMUM, STATUS_BAR_HEIGHT+ ACTION_BAR_HEIGHT, PADDING_MINIMUM, PADDING_MINIMUM); //Keep space for resize by mouse
+ Padding = new Padding(PADDING_MINIMUM, STATUS_BAR_HEIGHT + ACTION_BAR_HEIGHT, PADDING_MINIMUM, PADDING_MINIMUM); //Keep space for resize by mouse
_clickAnimManager = new AnimationManager()
{
@@ -441,8 +315,9 @@ public MaterialForm()
// Drawer
Shown += (sender, e) =>
{
- if (DesignMode || IsDisposed)
- return;
+ //Disabled to improve design mode experience
+ //if (DesignMode || IsDisposed)
+ // return;
AddDrawerOverlayForm();
};
}
@@ -692,44 +567,44 @@ private void ResizeForm(ResizeDirection direction)
switch (direction)
{
case ResizeDirection.BottomLeft:
- dir = (int)HT.BottomLeft;
+ dir = (int)NativeWin.HT.BottomLeft;
Cursor = Cursors.SizeNESW;
break;
case ResizeDirection.Left:
- dir = (int)HT.Left;
+ dir = (int)NativeWin.HT.Left;
Cursor = Cursors.SizeWE;
break;
case ResizeDirection.Right:
- dir = (int)HT.Right;
+ dir = (int)NativeWin.HT.Right;
break;
case ResizeDirection.BottomRight:
- dir = (int)HT.BottomRight;
+ dir = (int)NativeWin.HT.BottomRight;
break;
case ResizeDirection.Bottom:
- dir = (int)HT.Bottom;
+ dir = (int)NativeWin.HT.Bottom;
break;
case ResizeDirection.Top:
- dir = (int)HT.Top;
+ dir = (int)NativeWin.HT.Top;
break;
case ResizeDirection.TopLeft:
- dir = (int)HT.TopLeft;
+ dir = (int)NativeWin.HT.TopLeft;
break;
case ResizeDirection.TopRight:
- dir = (int)HT.TopRight;
+ dir = (int)NativeWin.HT.TopRight;
break;
}
- ReleaseCapture();
+ NativeWin.ReleaseCapture();
if (dir != -1)
{
- SendMessage(Handle, (int)WM.NonClientLeftButtonDown, dir, 0);
+ NativeWin.SendMessage(Handle, (int)NativeWin.WM.NonClientLeftButtonDown, dir, 0);
}
}
@@ -790,7 +665,7 @@ protected override CreateParams CreateParams
get
{
var par = base.CreateParams;
- par.Style |= (int)WS.MinimizeBox | (int)WS.SysMenu;
+ par.Style |= (int)NativeWin.WS.MinimizeBox | (int)NativeWin.WS.SysMenu;
return par;
}
}
@@ -801,19 +676,19 @@ protected override void OnCreateControl()
// Sets the Window Style for having a Size Frame after the form is created
// This prevents unexpected sizing while still allowing for Aero Snapping
- var flags = GetWindowLongPtr(Handle, -16).ToInt64();
- SetWindowLongPtr(Handle, -16, (IntPtr)(flags | (int)WS.SizeFrame));
+ var flags = NativeWin.GetWindowLongPtr(Handle, -16).ToInt64();
+ NativeWin.SetWindowLongPtr(Handle, -16, (IntPtr)(flags | (int)NativeWin.WS.SizeFrame));
}
protected override void WndProc(ref Message m)
{
- var message = (WM)m.Msg;
+ var message = (NativeWin.WM)m.Msg;
// Prevent the base class from receiving the message
- if (message == WM.NonClientCalcSize) return;
+ if (message == NativeWin.WM.NonClientCalcSize) return;
// https://docs.microsoft.com/en-us/windows/win32/winmsg/wm-ncactivate?redirectedfrom=MSDN#parameters
// "If this parameter is set to -1, DefWindowProc does not repaint the nonclient area to reflect the state change."
- if (message == WM.NonClientActivate)
+ if (message == NativeWin.WM.NonClientActivate)
{
m.Result = new IntPtr(-1);
return;
@@ -828,7 +703,7 @@ protected override void WndProc(ref Message m)
!(_minButtonBounds.Contains(cursorPos) || _maxButtonBounds.Contains(cursorPos) || _xButtonBounds.Contains(cursorPos));
// Drawer
- if (DrawerTabControl != null && (message == WM.LeftButtonDown || message == WM.LeftButtonDoubleClick) && _drawerIconRect.Contains(cursorPos))
+ if (DrawerTabControl != null && (message == NativeWin.WM.LeftButtonDown || message == NativeWin.WM.LeftButtonDoubleClick) && _drawerIconRect.Contains(cursorPos))
{
drawerControl.Toggle();
_clickAnimManager.SetProgress(0);
@@ -836,18 +711,18 @@ protected override void WndProc(ref Message m)
_animationSource = cursorPos;
}
// Double click to maximize
- else if (message == WM.LeftButtonDoubleClick && isOverCaption)
- {
+ else if (message == NativeWin.WM.LeftButtonDoubleClick && isOverCaption)
+ {
Maximized = !Maximized;
}
// Treat the Caption as if it was Non-Client
- else if (message == WM.LeftButtonDown && isOverCaption)
+ else if (message == NativeWin.WM.LeftButtonDown && isOverCaption)
{
- ReleaseCapture();
- SendMessage(Handle, (int)WM.NonClientLeftButtonDown, (int)HT.Caption, 0);
+ NativeWin.ReleaseCapture();
+ NativeWin.SendMessage(Handle, (int)NativeWin.WM.NonClientLeftButtonDown, (int)NativeWin.HT.Caption, 0);
}
// Default context menu
- else if (message == WM.RightButtonDown)
+ else if (message == NativeWin.WM.RightButtonDown)
{
if (_statusBarBounds.Contains(cursorPos) && !_minButtonBounds.Contains(cursorPos) &&
!_maxButtonBounds.Contains(cursorPos) && !_xButtonBounds.Contains(cursorPos))
@@ -857,11 +732,13 @@ protected override void WndProc(ref Message m)
base.ContextMenuStrip = null;
// Show default system menu when right clicking titlebar
- var id = TrackPopupMenuEx(GetSystemMenu(Handle, false), (int)TPM.LeftAlign | (int)TPM.ReturnCommand, Cursor.Position.X, Cursor.Position.Y, Handle, IntPtr.Zero);
+ var id = NativeWin.TrackPopupMenuEx(NativeWin.GetSystemMenu(Handle, false),
+ (int)NativeWin.TPM.LeftAlign | (int)NativeWin.TPM.ReturnCommand,
+ Cursor.Position.X, Cursor.Position.Y, Handle, IntPtr.Zero);
// Pass the command as a WM_SYSCOMMAND message
- SendMessage(Handle, (int)WM.SystemCommand, id, 0);
-
+ NativeWin.SendMessage(Handle, (int)NativeWin.WM.SystemCommand, id, 0);
+
// restore user defined ContextMenuStrip
base.ContextMenuStrip = user_cms;
}
@@ -980,7 +857,7 @@ protected override void OnMouseUp(MouseEventArgs e)
UpdateButtons(e.Button, e.Location, true);
base.OnMouseUp(e);
- ReleaseCapture();
+ NativeWin.ReleaseCapture();
}
protected override void OnPaint(PaintEventArgs e)
@@ -1177,7 +1054,7 @@ protected override void OnPaint(PaintEventArgs e)
//Form title
using (NativeTextRenderer NativeText = new NativeTextRenderer(g))
{
- Rectangle textLocation = new Rectangle(DrawerTabControl != null ? TITLE_LEFT_PADDING : TITLE_LEFT_PADDING - (ICON_SIZE + (ACTION_BAR_PADDING*2)), STATUS_BAR_HEIGHT, ClientSize.Width, ACTION_BAR_HEIGHT);
+ Rectangle textLocation = new Rectangle(DrawerTabControl != null ? TITLE_LEFT_PADDING : TITLE_LEFT_PADDING - (ICON_SIZE + (ACTION_BAR_PADDING * 2)), STATUS_BAR_HEIGHT, ClientSize.Width, ACTION_BAR_HEIGHT);
NativeText.DrawTransparentText(Text, SkinManager.getLogFontByType(MaterialSkinManager.fontType.H6),
SkinManager.ColorScheme.TextColor,
textLocation.Location,
@@ -1187,58 +1064,6 @@ protected override void OnPaint(PaintEventArgs e)
}
}
#endregion
-
- #region Low Level Windows Methods
- ///
- /// Provides a single method to call either the 32-bit or 64-bit method based on the size of an for getting the
- /// Window Style flags.
- /// GetWindowLongPtr
- ///
- private static IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex)
- {
- if (IntPtr.Size == 8)
- return GetWindowLongPtr64(hWnd, nIndex);
- else
- return GetWindowLong(hWnd, nIndex);
- }
-
- ///
- /// Provides a single method to call either the 32-bit or 64-bit method based on the size of an for setting the
- /// Window Style flags.
- /// SetWindowLongPtr
- ///
- private static IntPtr SetWindowLongPtr(IntPtr hWnd, int nIndex, IntPtr dwNewLong)
- {
- if (IntPtr.Size == 8)
- return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
- else
- return SetWindowLong(hWnd, nIndex, dwNewLong.ToInt32());
- }
-
- [DllImport("user32.dll", EntryPoint = "GetWindowLong")]
- private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex);
-
- [DllImport("user32.dll", EntryPoint = "GetWindowLongPtr")]
- private static extern IntPtr GetWindowLongPtr64(IntPtr hWnd, int nIndex);
-
- [DllImport("user32.dll", EntryPoint = "SetWindowLong")]
- private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
-
- [DllImport("user32.dll", EntryPoint = "SetWindowLongPtr")]
- private static extern IntPtr SetWindowLongPtr64(IntPtr hWnd, int nIndex, IntPtr dwNewLong);
-
- [DllImport("user32.dll")]
- private static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
-
- [DllImport("user32.dll")]
- private static extern bool ReleaseCapture();
-
- [DllImport("user32.dll")]
- private static extern int TrackPopupMenuEx(IntPtr hmenu, uint fuFlags, int x, int y, IntPtr hwnd, IntPtr lptpm);
-
- [DllImport("user32.dll")]
- private static extern IntPtr GetSystemMenu(IntPtr hWnd, bool bRevert);
- #endregion
}
public class MaterialDrawerForm : Form
diff --git a/MaterialSkin/Controls/MaterialLabel.cs b/MaterialSkin/Controls/MaterialLabel.cs
index 767d2448..0493d06d 100644
--- a/MaterialSkin/Controls/MaterialLabel.cs
+++ b/MaterialSkin/Controls/MaterialLabel.cs
@@ -32,18 +32,18 @@ public override ContentAlignment TextAlign
}
}
- [Category("Material Skin"),
- DefaultValue(false)]
+ [Category(CategoryLabels.MaterialSkin),
+ DefaultValue(false)]
public bool HighEmphasis { get; set; }
- [Category("Material Skin"),
- DefaultValue(false)]
+ [Category(CategoryLabels.MaterialSkin),
+ DefaultValue(false)]
public bool UseAccent { get; set; }
private MaterialSkinManager.fontType _fontType = MaterialSkinManager.fontType.Body1;
- [Category("Material Skin"),
- DefaultValue(typeof(MaterialSkinManager.fontType), "Body1")]
+ [Category(CategoryLabels.MaterialSkin),
+ DefaultValue(typeof(MaterialSkinManager.fontType), "Body1")]
public MaterialSkinManager.fontType FontType
{
get
diff --git a/MaterialSkin/Controls/MaterialListBox.cs b/MaterialSkin/Controls/MaterialListBox.cs
index 940b3d3a..115ef5b1 100644
--- a/MaterialSkin/Controls/MaterialListBox.cs
+++ b/MaterialSkin/Controls/MaterialListBox.cs
@@ -39,7 +39,7 @@ public class MaterialListBox : Control, IMaterialControl
private MaterialScrollBar _scrollBar;
private object _selectedValue;
- private bool _updating=false;
+ private bool _updating = false;
private int _itemHeight;
private bool _showBorder;
private Color _borderColor;
@@ -84,24 +84,24 @@ public enum MaterialItemDensity
private bool useAccentColor;
- [Category("Material Skin"), DefaultValue(false), DisplayName("Use Accent Color")]
+ [Category(CategoryLabels.MaterialSkin), DefaultValue(false), DisplayName("Use Accent Color")]
public bool UseAccentColor
{
get { return useAccentColor; }
- set { useAccentColor = value; _scrollBar.UseAccentColor = value; Invalidate(); }
+ set { useAccentColor = value; _scrollBar.UseAccentColor = value; Invalidate(); }
}
[TypeConverter(typeof(CollectionConverter))]
[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Editor(typeof(MaterialItemCollectionEditor), typeof(UITypeEditor))]
- [Category("Material Skin"), Description("Gets the items of the ListBox.")]
+ [Category(CategoryLabels.MaterialSkin), Description("Gets the items of the ListBox.")]
public ObservableCollection Items => _items;
[Browsable(false)]
- [Category("Material Skin"), Description("Gets a collection containing the currently selected items in the ListBox.")]
+ [Category(CategoryLabels.MaterialSkin), Description("Gets a collection containing the currently selected items in the ListBox.")]
public List