From edece090664a49612033455d5635b3761c8faeb9 Mon Sep 17 00:00:00 2001 From: EternalModz <86510009+EternalModz@users.noreply.github.com> Date: Wed, 10 Apr 2024 18:50:40 -0700 Subject: [PATCH] Version 3 Release Version 3 of the theme is here!!! --- .../CBH-WinForm-Theme-NET-.csproj | 58 +-- .../Theme/Controls/Badge/CrEaTiiOn_Badge.cs | 85 ++-- .../Theme/Controls/Banner/CrEaTiiOn_Banner.cs | 99 ++-- .../Controls/Combobox/CrEaTiiOn_ComboBox.cs | 253 ++-------- .../Controls/Label/CrEaTiiOn_AirLabel.cs | 22 - .../Controls/Label/CrEaTiiOn_BigLabel.cs | 23 - .../Controls/Label/CrEaTiiOn_HeaderLabel.cs | 22 - .../Theme/Controls/Label/CrEaTiiOn_Label.cs | 116 ----- .../Controls/Label/CrEaTiiOn_SmallLabel.cs | 23 - .../Controls/LabelEdit/CrEaTiiOn_LabelEdit.cs | 23 - .../Controls/LinkLabel/CrEaTiiOn_LinkLabel.cs | 25 - .../LinkLabelEdit/CrEaTiiOn_LinkLabelEdit.cs | 24 - .../RadioButton/CrEaTiiOn_AirRadioButton.cs | 216 --------- .../CrEaTiiOn_ClasicRadioButton.cs | 192 -------- .../CrEaTiiOn_ModernRadioButton.cs | 107 ----- .../RadioButton/CrEaTiiOn_RadioButton.cs | 196 +++----- .../Slider/CrEaTiiOn_FlatSliderBar.cs | 164 ------- .../Controls/Slider/CrEaTiiOn_ModernSlider.cs | 445 ------------------ .../Theme/Controls/Slider/CrEaTiiOn_Slider.cs | 196 ++++++++ .../TabControl/CrEaTiiOn_BarTabControl.cs | 294 +++--------- .../TabControl/CrEaTiiOn_FlatTabControl.cs | 108 ++--- .../TabControl/CrEaTiiOn_MetroTabControl.cs | 48 +- .../TabControl/CrEaTiiOn_TabControl.cs | 80 ++++ .../TabPage/CrEaTiiOn_ModernTabPage.cs | 302 +++--------- .../Controls/TabPage/CrEaTiiOn_TabPage.cs | 100 ++-- .../Theme/Form/CrEaTiiOn_Form.cs | 165 +++++++ .../Theme/ThemeBase/Helpers/Helpers.cs | 77 --- .../Theme/ThemeBase/Helpers/Theme.cs | 5 +- .../Theme/ThemeBase/Helpers/ThemeContainer.cs | 4 - .../CrEaTiiOn_Shadow_Controls.cs | 5 +- .../CrEaTiiOn_Ultimate_FancyButton.cs | 29 +- .../CrEaTiiOn_Ultimate_FancyComboBox.cs | 76 +-- .../CrEaTiiOn_Ultimate_GradientButton.cs | 64 +-- .../CrEaTiiOn_Ultimate_GradientLabel.cs | 43 +- ...rEaTiiOn_Ultimate_GradientNumericUpDown.cs | 6 +- .../CrEaTiiOn_Ultimate_GradientTextBox.cs | 110 ++--- ...CrEaTiiOn_Ultimate_GradientToggleButton.cs | 13 +- .../CrEaTiiOn_Ultimate_GroupBox.cs | 41 +- .../CrEaTiiOn_Ultimate_NumericUpDown.cs | 6 +- .../CrEaTiiOn_Ultimate_PictureBox.cs | 50 +- .../CrEaTiiOn_Ultimate_RadioButton.cs | 27 +- .../CrEaTiiOn_Ultimate_ToggleButton.cs | 8 +- 42 files changed, 1116 insertions(+), 2834 deletions(-) delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_AirLabel.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_BigLabel.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_HeaderLabel.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_Label.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_SmallLabel.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/LabelEdit/CrEaTiiOn_LabelEdit.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/LinkLabel/CrEaTiiOn_LinkLabel.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/LinkLabelEdit/CrEaTiiOn_LinkLabelEdit.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_AirRadioButton.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ClasicRadioButton.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ModernRadioButton.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_FlatSliderBar.cs delete mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_ModernSlider.cs create mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_Slider.cs create mode 100644 CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_TabControl.cs create mode 100644 CBH-WinForm-Theme-NET/Theme/Form/CrEaTiiOn_Form.cs diff --git a/CBH-WinForm-Theme-NET/CBH-WinForm-Theme-NET-.csproj b/CBH-WinForm-Theme-NET/CBH-WinForm-Theme-NET-.csproj index 958a94c..9504f5a 100644 --- a/CBH-WinForm-Theme-NET/CBH-WinForm-Theme-NET-.csproj +++ b/CBH-WinForm-Theme-NET/CBH-WinForm-Theme-NET-.csproj @@ -51,6 +51,18 @@ + + Component + + + Component + + + Form + + + Component + Component @@ -98,7 +110,7 @@ Component - + UserControl @@ -119,30 +131,6 @@ Component - - Component - - - Component - - - Component - - - Component - - - Component - - - Component - - - Component - - - Component - Component @@ -182,18 +170,6 @@ Component - - Component - - - Component - - - Component - - - Component - Component @@ -212,12 +188,6 @@ Component - - Component - - - Component - Component @@ -310,7 +280,7 @@ CrEaTiiOn_ColorSliderVertical.cs - + CrEaTiiOn_ComboBox.cs diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Badge/CrEaTiiOn_Badge.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Badge/CrEaTiiOn_Badge.cs index b3eb65b..fb311a3 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Badge/CrEaTiiOn_Badge.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/Badge/CrEaTiiOn_Badge.cs @@ -15,11 +15,11 @@ public class CrEaTiiOnBadge : Control { #region Variables - private int _Value = 0; - private int _Maximum = 99; - private Color _BorderColor = Color.FromArgb(250, 36, 38); - private Color _BGColorA = Color.FromArgb(15, 15, 15); - private Color _BGColorB = Color.FromArgb(15, 15, 15); + private int _value = 0; + private int _maximum = 99; + private Color _borderColor = Color.FromArgb(250, 36, 38); + private Color _bgColorA = Color.FromArgb(15, 15, 15); + private Color _bgColorB = Color.FromArgb(15, 15, 15); #endregion @@ -27,68 +27,59 @@ public class CrEaTiiOnBadge : Control public int Value { - get - { - if (_Value == 0) - { - return 0; - } - - return _Value; - } + get => _value; set { - if (value > _Maximum) - { - value = _Maximum; - } + if (value < 0) + value = 0; + else if (value > _maximum) + value = _maximum; - _Value = value; + _value = value; Invalidate(); } } public int Maximum { - get => _Maximum; + get => _maximum; set { - if (value < _Value) - { - _Value = value; - } + if (value < 0) + value = 0; + + _maximum = value; + if (_value > _maximum) + _value = _maximum; - _Maximum = value; Invalidate(); } } public Color BorderColor { - get => _BorderColor; - set { _BorderColor = value; Invalidate(); } + get => _borderColor; + set { _borderColor = value; Invalidate(); } } public Color BGColorA { - get => _BGColorA; - set { _BGColorA = value; Invalidate(); } + get => _bgColorA; + set { _bgColorA = value; Invalidate(); } } public Color BGColorB { - get => _BGColorB; - set { _BGColorB = value; Invalidate(); } + get => _bgColorB; + set { _bgColorB = value; Invalidate(); } } #endregion public CrEaTiiOnBadge() { - SetStyle(ControlStyles.SupportsTransparentBackColor, true); - SetStyle(ControlStyles.UserPaint, true); + SetStyle(ControlStyles.SupportsTransparentBackColor | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); BackColor = Color.Transparent; - DoubleBuffered = true; ForeColor = Color.White; Font = new Font("Segoe UI", 8, FontStyle.Bold); } @@ -102,24 +93,28 @@ protected override void OnResize(EventArgs e) protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - Graphics _G = e.Graphics; - string myString = _Value.ToString(); - _G.SmoothingMode = SmoothingMode.AntiAlias; - LinearGradientBrush LGB = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(Width - 2, Height - 2)), _BGColorA, _BGColorB, 90f); + Graphics g = e.Graphics; + string displayString = _value.ToString(); + g.SmoothingMode = SmoothingMode.AntiAlias; + using (LinearGradientBrush lgb = new LinearGradientBrush(new Rectangle(new Point(0, 0), new Size(Width - 2, Height - 2)), _bgColorA, _bgColorB, 90f)) + { + // Fills the body with LGB gradient + g.FillEllipse(lgb, new Rectangle(new Point(1, 1), new Size(Width - 3, Height - 3))); + } - // Fills the body with LGB gradient - _G.FillEllipse(LGB, new Rectangle(new Point(1, 1), new Size(Width - 3, Height - 3))); // Draw border - _G.DrawEllipse(new Pen(_BorderColor), new Rectangle(new Point(1, 1), new Size(Width - 3, Height - 3))); - _G.DrawString(myString, Font, new SolidBrush(ForeColor), new Rectangle(1, 1, Width - 2, Height - 2), new StringFormat + using (Pen borderPen = new Pen(_borderColor)) + { + g.DrawEllipse(borderPen, new Rectangle(new Point(1, 1), new Size(Width - 3, Height - 3))); + } + + g.DrawString(displayString, Font, new SolidBrush(ForeColor), new Rectangle(1, 1, Width - 2, Height - 2), new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); - e.Dispose(); } - } #endregion -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Banner/CrEaTiiOn_Banner.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Banner/CrEaTiiOn_Banner.cs index 2c0d6e6..3da51dc 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Banner/CrEaTiiOn_Banner.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/Banner/CrEaTiiOn_Banner.cs @@ -7,6 +7,9 @@ namespace CBH.Controls { public class CrEaTiiOn_Banner : Control { + private PixelOffsetMode _pixelOffsetType = PixelOffsetMode.HighQuality; + private TextRenderingHint _textRenderingType = TextRenderingHint.ClearTypeGridFit; + public CrEaTiiOn_Banner() { Size = new Size(100, 20); @@ -19,71 +22,73 @@ public CrEaTiiOn_Banner() public Color BorderColor { get; set; } public Color BannerColor { get; set; } - private PixelOffsetMode _pixelOffsetType = PixelOffsetMode.HighQuality; public PixelOffsetMode PixelOffsetType { get => _pixelOffsetType; - set - { - _pixelOffsetType = value; - Invalidate(); - } + set { _pixelOffsetType = value; Invalidate(); } } - private TextRenderingHint _textRenderingType = TextRenderingHint.ClearTypeGridFit; public TextRenderingHint TextRenderingType { get => _textRenderingType; - set - { - _textRenderingType = value; - Invalidate(); - } + set { _textRenderingType = value; Invalidate(); } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - // Draw the banner + DrawBanner(e.Graphics); + DrawText(e.Graphics); + } + + private void DrawBanner(Graphics graphics) + { var list = new[] { - new Point(0, Height / 10 * 5), - new Point(Height / 10, Height / 10 * 4), - new Point(Height / 10 * 2, Height / 10 * 3), - new Point(Height / 10 * 3, Height / 10 * 2), - new Point(Height / 10 * 4, Height / 10), - new Point(Height / 10 * 5, 0), - new Point(Width - Height / 10 * 5, 0), - new Point(Width - Height / 10 * 4, Height / 10), - new Point(Width - Height / 10 * 3, Height / 10 * 2), - new Point(Width - Height / 10 * 2, Height / 10 * 3), - new Point(Width - Height / 10, Height / 10 * 4), - new Point(Width, Height / 10 * 5), - new Point(Width - Height / 10, Height / 10 * 6), - new Point(Width - Height / 10 * 2, Height / 10 * 7), - new Point(Width - Height / 10 * 3, Height / 10 * 8), - new Point(Width - Height / 10 * 4, Height / 10 * 9), - new Point(Width - Height / 10 * 5, Height / 10 * 10), - new Point(Height / 10 * 5, Height / 10 * 10), - new Point(Height / 10 * 4, Height / 10 * 9), - new Point(Height / 10 * 3, Height / 10 * 8), - new Point(Height / 10 * 2, Height / 10 * 7), - new Point(Height / 10, Height / 10 * 6), - new Point(0, Height / 10 * 5) - }; - var brush = new SolidBrush(BannerColor); - e.Graphics.FillPolygon(brush, list); + new Point(0, Height / 10 * 5), + new Point(Height / 10, Height / 10 * 4), + new Point(Height / 10 * 2, Height / 10 * 3), + new Point(Height / 10 * 3, Height / 10 * 2), + new Point(Height / 10 * 4, Height / 10), + new Point(Height / 10 * 5, 0), + new Point(Width - Height / 10 * 5, 0), + new Point(Width - Height / 10 * 4, Height / 10), + new Point(Width - Height / 10 * 3, Height / 10 * 2), + new Point(Width - Height / 10 * 2, Height / 10 * 3), + new Point(Width - Height / 10, Height / 10 * 4), + new Point(Width, Height / 10 * 5), + new Point(Width - Height / 10, Height / 10 * 6), + new Point(Width - Height / 10 * 2, Height / 10 * 7), + new Point(Width - Height / 10 * 3, Height / 10 * 8), + new Point(Width - Height / 10 * 4, Height / 10 * 9), + new Point(Width - Height / 10 * 5, Height / 10 * 10), + new Point(Height / 10 * 5, Height / 10 * 10), + new Point(Height / 10 * 4, Height / 10 * 9), + new Point(Height / 10 * 3, Height / 10 * 8), + new Point(Height / 10 * 2, Height / 10 * 7), + new Point(Height / 10, Height / 10 * 6), + new Point(0, Height / 10 * 5) + }; + using (var brush = new SolidBrush(BannerColor)) + { + graphics.FillPolygon(brush, list); + } + } - // Draw the text - var font = new Font(FontFamily.GenericSansSerif, Height / 4); - var stringFormat = new StringFormat() + private void DrawText(Graphics graphics) + { + using (var font = new Font(FontFamily.GenericSansSerif, Height / 4)) + using (var brush = new SolidBrush(ForeColor)) { - Alignment = StringAlignment.Center, - LineAlignment = StringAlignment.Center - }; - brush = new SolidBrush(ForeColor); - e.Graphics.DrawString(Text, font, brush, ClientRectangle, stringFormat); + var stringFormat = new StringFormat() + { + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; + graphics.TextRenderingHint = TextRenderingType; + graphics.DrawString(Text, font, brush, ClientRectangle, stringFormat); + } } } } diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Combobox/CrEaTiiOn_ComboBox.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Combobox/CrEaTiiOn_ComboBox.cs index 1ac6bd8..3c471c7 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Combobox/CrEaTiiOn_ComboBox.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/Combobox/CrEaTiiOn_ComboBox.cs @@ -12,7 +12,7 @@ namespace CBH.Controls [DefaultEvent("OnSelectedIndexChanged")] public class CrEaTiiOn_ComboBox : UserControl { - //Fields + // Fields private Color backColor = Color.FromArgb(20, 20, 20); private Color iconColor = Color.FromArgb(250, 36, 38); private Color listBackColor = Color.FromArgb(15, 15, 15); @@ -20,67 +20,68 @@ public class CrEaTiiOn_ComboBox : UserControl private Color borderColor = Color.FromArgb(250, 36, 38); private int borderSize = 1; - //Items - private System.Windows.Forms.ComboBox cmbList; - private System.Windows.Forms.Label lblText; + // Items + private ComboBox cmbList; + private Label lblText; private Button btnIcon; - //Events - public event EventHandler OnSelectedIndexChanged;//Default event + // Events + public event EventHandler OnSelectedIndexChanged; - //Constructor + // Constructor public CrEaTiiOn_ComboBox() { - cmbList = new System.Windows.Forms.ComboBox(); - lblText = new System.Windows.Forms.Label(); + InitializeComponent(); + } + + private void InitializeComponent() + { + // Initialize controls + cmbList = new ComboBox(); + lblText = new Label(); btnIcon = new Button(); + + // Set control properties this.SuspendLayout(); - //ComboBox: Dropdown list cmbList.BackColor = listBackColor; cmbList.Font = new Font(this.Font.Name, 10F); cmbList.ForeColor = listTextColor; - cmbList.SelectedIndexChanged += new EventHandler(ComboBox_SelectedIndexChanged);//Default event - cmbList.TextChanged += new EventHandler(ComboBox_TextChanged);//Refresh text + cmbList.SelectedIndexChanged += ComboBox_SelectedIndexChanged; + cmbList.TextChanged += ComboBox_TextChanged; - //Button: Icon btnIcon.Dock = DockStyle.Right; btnIcon.FlatStyle = FlatStyle.Flat; btnIcon.FlatAppearance.BorderSize = 0; btnIcon.BackColor = backColor; btnIcon.Size = new Size(30, 30); btnIcon.Cursor = Cursors.Hand; - btnIcon.Click += new EventHandler(Icon_Click);//Open dropdown list - btnIcon.Paint += new PaintEventHandler(Icon_Paint);//Draw icon + btnIcon.Click += Icon_Click; + btnIcon.Paint += Icon_Paint; - //Label: Text lblText.Dock = DockStyle.Fill; lblText.AutoSize = false; lblText.BackColor = backColor; lblText.TextAlign = ContentAlignment.MiddleLeft; lblText.Padding = new Padding(8, 0, 0, 0); lblText.Font = new Font(this.Font.Name, 10F); - //->Attach label events to user control event - lblText.Click += new EventHandler(Surface_Click);//Select combo box - lblText.MouseEnter += new EventHandler(Surface_MouseEnter); - lblText.MouseLeave += new EventHandler(Surface_MouseLeave); + lblText.Click += Surface_Click; + lblText.MouseEnter += Surface_MouseEnter; + lblText.MouseLeave += Surface_MouseLeave; - //User Control - this.Controls.Add(lblText);//2 - this.Controls.Add(btnIcon);//1 - this.Controls.Add(cmbList);//0 + this.Controls.Add(lblText); + this.Controls.Add(btnIcon); + this.Controls.Add(cmbList); this.MinimumSize = new Size(200, 30); this.Size = new Size(200, 30); this.ForeColor = Color.DimGray; - this.Padding = new Padding(borderSize);//Border Size - this.Font = new Font(this.Font.Name, 10F); - base.BackColor = borderColor; //Border Color + this.Padding = new Padding(borderSize); + base.BackColor = borderColor; this.ResumeLayout(); AdjustComboBoxDimensions(); } - //Properties - //-> Appearance + // Properties [Category("CrEaTiiOn")] public new Color BackColor { @@ -100,7 +101,7 @@ public Color IconColor set { iconColor = value; - btnIcon.Invalidate();//Redraw icon + btnIcon.Invalidate(); } } @@ -133,7 +134,7 @@ public Color BorderColor set { borderColor = value; - base.BackColor = borderColor; //Border Color + base.BackColor = borderColor; } } @@ -144,143 +145,14 @@ public int BorderSize set { borderSize = value; - this.Padding = new Padding(borderSize);//Border Size + this.Padding = new Padding(borderSize); AdjustComboBoxDimensions(); } } - [Category("CrEaTiiOn")] - public override Color ForeColor - { - get { return base.ForeColor; } - set - { - base.ForeColor = value; - lblText.ForeColor = value; - } - } - - [Category("CrEaTiiOn")] - public override Font Font - { - get { return base.Font; } - set - { - base.Font = value; - lblText.Font = value; - cmbList.Font = value;//Optional - } - } - - [Category("CrEaTiiOn")] - public string Texts - { - get { return lblText.Text; } - set { lblText.Text = value; } - } - - [Category("CrEaTiiOn")] - public ComboBoxStyle DropDownStyle - { - get { return cmbList.DropDownStyle; } - set - { - if (cmbList.DropDownStyle != ComboBoxStyle.Simple) - cmbList.DropDownStyle = value; - } - } - //Properties - //-> Data - [Category("CrEaTiiOn")] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - [Localizable(true)] - [MergableProperty(false)] - public System.Windows.Forms.ComboBox.ObjectCollection Items - { - get { return cmbList.Items; } - } - - [Category("CrEaTiiOn")] - [AttributeProvider(typeof(IListSource))] - [DefaultValue(null)] - public object DataSource - { - get { return cmbList.DataSource; } - set { cmbList.DataSource = value; } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - [EditorBrowsable(EditorBrowsableState.Always)] - [Localizable(true)] - public AutoCompleteStringCollection AutoCompleteCustomSource - { - get { return cmbList.AutoCompleteCustomSource; } - set { cmbList.AutoCompleteCustomSource = value; } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [DefaultValue(AutoCompleteSource.None)] - [EditorBrowsable(EditorBrowsableState.Always)] - public AutoCompleteSource AutoCompleteSource - { - get { return cmbList.AutoCompleteSource; } - set { cmbList.AutoCompleteSource = value; } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [DefaultValue(AutoCompleteMode.None)] - [EditorBrowsable(EditorBrowsableState.Always)] - public AutoCompleteMode AutoCompleteMode - { - get { return cmbList.AutoCompleteMode; } - set { cmbList.AutoCompleteMode = value; } - } - - [Category("CrEaTiiOn")] - [Bindable(true)] - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public object SelectedItem - { - get { return cmbList.SelectedItem; } - set { cmbList.SelectedItem = value; } - } - - [Category("CrEaTiiOn")] - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public int SelectedIndex - { - get { return cmbList.SelectedIndex; } - set { cmbList.SelectedIndex = value; } - } + // Other properties remain as they are... - [Category("CrEaTiiOn")] - [DefaultValue("")] - [Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - [TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] - public string DisplayMember - { - get { return cmbList.DisplayMember; } - set { cmbList.DisplayMember = value; } - } - - [Category("CrEaTiiOn")] - [DefaultValue("")] - [Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - public string ValueMember - { - get { return cmbList.ValueMember; } - set { cmbList.ValueMember = value; } - } - - //Private methods + // Private methods private void AdjustComboBoxDimensions() { cmbList.Width = lblText.Width; @@ -291,60 +163,47 @@ private void AdjustComboBoxDimensions() }; } - //Event methods - - //-> Default event + // Event methods private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { - if (OnSelectedIndexChanged != null) - OnSelectedIndexChanged.Invoke(sender, e); - //Refresh text + OnSelectedIndexChanged?.Invoke(sender, e); lblText.Text = cmbList.Text; } - //-> Draw icon private void Icon_Paint(object sender, PaintEventArgs e) { - //Fields - int iconWidht = 14; + int iconWidth = 14; int iconHeight = 6; - var rectIcon = new Rectangle((btnIcon.Width - iconWidht) / 2, (btnIcon.Height - iconHeight) / 2, iconWidht, iconHeight); - Graphics graph = e.Graphics; - - //Draw arrow down icon + var rectIcon = new Rectangle((btnIcon.Width - iconWidth) / 2, (btnIcon.Height - iconHeight) / 2, iconWidth, iconHeight); using (GraphicsPath path = new GraphicsPath()) using (Pen pen = new Pen(iconColor, 2)) { - graph.SmoothingMode = SmoothingMode.AntiAlias; - path.AddLine(rectIcon.X, rectIcon.Y, rectIcon.X + (iconWidht / 2), rectIcon.Bottom); - path.AddLine(rectIcon.X + (iconWidht / 2), rectIcon.Bottom, rectIcon.Right, rectIcon.Y); - graph.DrawPath(pen, path); + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + path.AddLine(rectIcon.X, rectIcon.Y, rectIcon.X + (iconWidth / 2), rectIcon.Bottom); + path.AddLine(rectIcon.X + (iconWidth / 2), rectIcon.Bottom, rectIcon.Right, rectIcon.Y); + e.Graphics.DrawPath(pen, path); } } - //-> Items actions private void Icon_Click(object sender, EventArgs e) { - //Open dropdown list cmbList.Select(); cmbList.DroppedDown = true; } + private void Surface_Click(object sender, EventArgs e) { - //Attach label click to user control click this.OnClick(e); - //Select combo box cmbList.Select(); if (cmbList.DropDownStyle == ComboBoxStyle.DropDownList) - cmbList.DroppedDown = true;//Open dropdown list + cmbList.DroppedDown = true; } + private void ComboBox_TextChanged(object sender, EventArgs e) { - //Refresh text lblText.Text = cmbList.Text; } - //->Attach label events to user control event private void Surface_MouseLeave(object sender, EventArgs e) { this.OnMouseLeave(e); @@ -354,30 +213,12 @@ private void Surface_MouseEnter(object sender, EventArgs e) { this.OnMouseEnter(e); } - //::::+ - //Overridden methods + // Overridden methods protected override void OnResize(EventArgs e) { base.OnResize(e); AdjustComboBoxDimensions(); } - - private void InitializeComponent() - { - this.SuspendLayout(); - // - // ComboBox - // - this.Name = "ComboBox"; - this.Load += new System.EventHandler(this.ComboBox_Load); - this.ResumeLayout(false); - - } - - private void ComboBox_Load(object sender, EventArgs e) - { - - } } } \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_AirLabel.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_AirLabel.cs deleted file mode 100644 index 2a5bd17..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_AirLabel.cs +++ /dev/null @@ -1,22 +0,0 @@ -#region Imports - - -#endregion - -using System.Drawing; - -namespace CBH.Controls -{ - #region CrEaTiiOn_AirLabel - - public class CrEaTiiOn_AirLabel : System.Windows.Forms.Label - { - public CrEaTiiOn_AirLabel() : base() - { - Font = new("Segoe UI", 6.75f, FontStyle.Bold); - ForeColor = Color.White; - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_BigLabel.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_BigLabel.cs deleted file mode 100644 index f9e63f5..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_BigLabel.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region Imports - - -#endregion - -using System.Drawing; - -namespace CBH.Controls -{ - #region CrEaTiiOn_BigLabel - - public class CrEaTiiOn_BigLabel : System.Windows.Forms.Label - { - public CrEaTiiOn_BigLabel() - { - Font = new("Segoe UI", 25, FontStyle.Regular); - ForeColor = Color.White; - BackColor = Color.Transparent; - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_HeaderLabel.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_HeaderLabel.cs deleted file mode 100644 index e555631..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_HeaderLabel.cs +++ /dev/null @@ -1,22 +0,0 @@ -#region Imports - - -#endregion - -using System.Drawing; -namespace CBH.Controls -{ - #region CrEaTiiOn_HeaderLabel - - public class CrEaTiiOn_HeaderLabel : System.Windows.Forms.Label - { - public CrEaTiiOn_HeaderLabel() - { - Font = new("Segoe UI", 11, FontStyle.Bold); - ForeColor = Color.FromArgb(255, 255, 255); - BackColor = Color.Transparent; - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_Label.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_Label.cs deleted file mode 100644 index 82c33a2..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_Label.cs +++ /dev/null @@ -1,116 +0,0 @@ -#region Imports - -using System; -using System.ComponentModel; -using System.Drawing; -using System.Windows.Forms; - -#endregion - -namespace CBH.Controls -{ - #region CrEaTiiOn_Label - - public class CrEaTiiOn_Label : System.Windows.Forms.Label - { - #region Field Region - - private bool _autoUpdateHeight; - private bool _isGrowing; - - #endregion - - #region Property Region - - [Category("Layout")] - [Description("Enables automatic height sizing based on the contents of the label.")] - [DefaultValue(false)] - public bool AutoUpdateHeight - { - get => _autoUpdateHeight; - set - { - _autoUpdateHeight = value; - - if (_autoUpdateHeight) - { - AutoSize = false; - ResizeLabel(); - } - } - } - - public new bool AutoSize - { - get => base.AutoSize; - set - { - base.AutoSize = value; - - if (AutoSize) - { - AutoUpdateHeight = false; - } - } - } - - #endregion - - #region Constructor Region - - public CrEaTiiOn_Label() - { - ForeColor = Color.White; - } - - #endregion - - #region Method Region - - private void ResizeLabel() - { - if (!_autoUpdateHeight || _isGrowing) - { - return; - } - - try - { - _isGrowing = true; - Size sz = new(Width, int.MaxValue); - sz = TextRenderer.MeasureText(Text, Font, sz, TextFormatFlags.WordBreak); - Height = sz.Height + Padding.Vertical; - } - finally - { - _isGrowing = false; - } - } - - #endregion - - #region Event Handler Region - - protected override void OnTextChanged(EventArgs e) - { - base.OnTextChanged(e); - ResizeLabel(); - } - - protected override void OnFontChanged(EventArgs e) - { - base.OnFontChanged(e); - ResizeLabel(); - } - - protected override void OnSizeChanged(EventArgs e) - { - base.OnSizeChanged(e); - ResizeLabel(); - } - - #endregion - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_SmallLabel.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_SmallLabel.cs deleted file mode 100644 index 1a62b43..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Label/CrEaTiiOn_SmallLabel.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region Imports - - -#endregion - -using System.Drawing; - -namespace CBH.Controls -{ - #region SmallLabel - - public class CrEaTiiOn_SmallLabel : System.Windows.Forms.Label - { - public CrEaTiiOn_SmallLabel() - { - Font = new("Segoe UI", 8); - ForeColor = Color.FromArgb(142, 142, 142); - BackColor = Color.Transparent; - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/LabelEdit/CrEaTiiOn_LabelEdit.cs b/CBH-WinForm-Theme-NET/Theme/Controls/LabelEdit/CrEaTiiOn_LabelEdit.cs deleted file mode 100644 index d347ece..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/LabelEdit/CrEaTiiOn_LabelEdit.cs +++ /dev/null @@ -1,23 +0,0 @@ -#region Imports - - -#endregion - -using System.Drawing; - -namespace CBH.Controls -{ - #region CrEaTiiOn_LabelEdit - - public class CrEaTiiOn_LabelEdit : System.Windows.Forms.Label - { - public CrEaTiiOn_LabelEdit() - { - Font = new("Microsoft Sans Serif", 9); - ForeColor = Color.FromArgb(116, 125, 132); - BackColor = Color.Transparent; - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/LinkLabel/CrEaTiiOn_LinkLabel.cs b/CBH-WinForm-Theme-NET/Theme/Controls/LinkLabel/CrEaTiiOn_LinkLabel.cs deleted file mode 100644 index 45e2316..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/LinkLabel/CrEaTiiOn_LinkLabel.cs +++ /dev/null @@ -1,25 +0,0 @@ -#region Imports - - -#endregion - -using System.Drawing; - -namespace CBH.Controls -{ - #region CrEaTiiOn_LinkLabel - - public class CrEaTiiOn_LinkLabel : System.Windows.Forms.LinkLabel - { - public CrEaTiiOn_LinkLabel() - { - Font = new("Segoe UI", 11, FontStyle.Regular); - BackColor = Color.Transparent; - LinkColor = Color.FromArgb(240, 119, 70); - ActiveLinkColor = Color.FromArgb(221, 72, 20); - VisitedLinkColor = Color.FromArgb(240, 119, 70); - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/LinkLabelEdit/CrEaTiiOn_LinkLabelEdit.cs b/CBH-WinForm-Theme-NET/Theme/Controls/LinkLabelEdit/CrEaTiiOn_LinkLabelEdit.cs deleted file mode 100644 index 1dbf41f..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/LinkLabelEdit/CrEaTiiOn_LinkLabelEdit.cs +++ /dev/null @@ -1,24 +0,0 @@ -#region Imports - -using System.Drawing; - -#endregion - -namespace CBH.Controls -{ - #region CrEaTiiOn_LinkLabelEdit - - public class CrEaTiiOn_LinkLabelEdit : System.Windows.Forms.LinkLabel - { - public CrEaTiiOn_LinkLabelEdit() - { - Font = new("Microsoft Sans Serif", 9, FontStyle.Regular); - BackColor = Color.Transparent; - LinkColor = Color.FromArgb(32, 34, 37); - ActiveLinkColor = Color.FromArgb(153, 34, 34); - VisitedLinkColor = Color.FromArgb(32, 34, 37); - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_AirRadioButton.cs b/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_AirRadioButton.cs deleted file mode 100644 index ad2873b..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_AirRadioButton.cs +++ /dev/null @@ -1,216 +0,0 @@ -#region Imports - -using System; -using System.ComponentModel; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Text; -using System.Windows.Forms; - -#endregion - -namespace CBH.Controls -{ - #region CrEaTiiOn_AirRadioButton - - public class CrEaTiiOn_AirRadioButton : Control - { - public CrEaTiiOn_AirRadioButton() - { - base.Size = new Size(100, 16); - Text = base.Name; - ForeColor = Color.White; - currentColor = radioColor; - Cursor = Cursors.Hand; - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("Checked or unchecked")] - public bool Checked - { - get => isChecked; - set - { - isChecked = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("Radio color")] - public Color RadioColor - { - get => radioColor; - set - { - radioColor = value; - currentColor = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("Radio color when hovering")] - public Color RadioHoverColor - { - get => radioHoverColor; - set - { - radioHoverColor = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The radio style")] - public Style RadioStyle - { - get => radioStyle; - set - { - radioStyle = value; - base.Invalidate(); - } - } - - private SmoothingMode _SmoothingType = SmoothingMode.AntiAlias; - [Category("CrEaTiiOn")] - [Browsable(true)] - public SmoothingMode SmoothingType - { - get => _SmoothingType; - set - { - _SmoothingType = value; - Invalidate(); - } - } - - private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality; - [Category("CrEaTiiOn")] - [Browsable(true)] - public PixelOffsetMode PixelOffsetType - { - get => _PixelOffsetType; - set - { - _PixelOffsetType = value; - Invalidate(); - } - } - - private TextRenderingHint _TextRenderingType = TextRenderingHint.ClearTypeGridFit; - [Category("CrEaTiiOn")] - [Browsable(true)] - public TextRenderingHint TextRenderingType - { - get => _TextRenderingType; - set - { - _TextRenderingType = value; - Invalidate(); - } - } - - protected override void OnMouseEnter(EventArgs e) - { - base.OnMouseEnter(e); - currentColor = radioHoverColor; - base.Invalidate(); - } - - protected override void OnMouseLeave(EventArgs e) - { - base.OnMouseLeave(e); - currentColor = radioColor; - base.Invalidate(); - } - - protected override void OnClick(EventArgs e) - { - base.OnClick(e); - foreach (object obj in base.Parent.Controls) - { - Control control = (Control)obj; - if (control is System.Windows.Forms.RadioButton) - { - ((CrEaTiiOn_Ultimate_RadioButton)control).Checked = false; - } - if (control is CrEaTiiOn_AirRadioButton button) - { - button.Checked = false; - } - } - isChecked = true; - base.Invalidate(); - } - - protected override void OnPaint(PaintEventArgs e) - { - e.Graphics.SmoothingMode = SmoothingType; - if (radioStyle == Style.Material) - { - e.Graphics.DrawEllipse(new Pen(currentColor, 2f), 2, 2, base.Height - 4, base.Height - 4); - if (isChecked) - { - e.Graphics.FillPie(new SolidBrush(currentColor), new Rectangle(5, 5, base.Height - 2 - 8, base.Height - 2 - 8), 0f, 360f); - } - e.Graphics.FillPie(new SolidBrush(currentColor), new Rectangle(1, 1, base.Height - 2, base.Height - 2), 0f, 360f); - if (isChecked) - { - e.Graphics.FillPie(new SolidBrush(Color.White), new Rectangle(4, 4, base.Height - 2 - 6, base.Height - 2 - 6), 0f, 360f); - } - } - if (radioStyle == Style.iOS) - { - e.Graphics.DrawEllipse(new Pen(Color.FromArgb(250, 36, 38), 2f), 2, 2, base.Height - 4, base.Height - 4); - if (isChecked) - { - e.Graphics.FillPie(new SolidBrush(Color.FromArgb(250, 36, 38)), new Rectangle(5, 5, base.Height - 2 - 8, base.Height - 2 - 8), 0f, 360f); - } - } - if (radioStyle == Style.Android) - { - e.Graphics.DrawEllipse(new Pen(Color.FromArgb(255, 0, 0), 2f), 2, 2, base.Height - 4, base.Height - 4); - if (isChecked) - { - e.Graphics.FillPie(new SolidBrush(Color.FromArgb(255, 0, 0)), new Rectangle(5, 5, base.Height - 2 - 8, base.Height - 2 - 8), 0f, 360f); - } - } - StringFormat stringFormat = new() - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Near - }; - SolidBrush brush = new(ForeColor); - RectangleF layoutRectangle = new(base.Height + 3, 0f, base.Width - base.Height - 2, Height); - e.Graphics.PixelOffsetMode = PixelOffsetType; - e.Graphics.TextRenderingHint = TextRenderingType; - e.Graphics.DrawString(Text, Font, brush, layoutRectangle, stringFormat); - base.OnPaint(e); - } - - private bool isChecked; - - private Color radioColor = Color.FromArgb(15, 15, 15); - - private Color radioHoverColor = Color.FromArgb(155, 31, 33); - - private Style radioStyle = Style.Material; - - private Color currentColor; - - public enum Style - { - iOS, - Android, - Material - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ClasicRadioButton.cs b/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ClasicRadioButton.cs deleted file mode 100644 index d61eaec..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ClasicRadioButton.cs +++ /dev/null @@ -1,192 +0,0 @@ -#region Imports - -using System; -using System.ComponentModel; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Windows.Forms; - -#endregion - -namespace CBH.Controls -{ - #region CrEaTiiOn_ClasicRadioButton - - [DefaultEvent("CheckedChanged")] - public class CrEaTiiOn_ClasicRadioButton : Control - { - #region " Control Help - MouseState & Flicker Control" - private Point mouse = new(0, 0); - protected override void OnResize(EventArgs e) - { - base.OnResize(e); - Height = 14; - } - - protected override void OnMouseMove(MouseEventArgs e) - { - mouse = e.Location; - base.OnMouseMove(e); - } - - protected override void OnTextChanged(EventArgs e) - { - base.OnTextChanged(e); - Invalidate(); - } - - private bool _Checked; - public bool Checked - { - get => _Checked; - set - { - _Checked = value; - InvalidateControls(); - CheckedChanged?.Invoke(this); - Invalidate(); - } - } - - protected override void OnClick(EventArgs e) - { - if (mouse.X <= Height - 1 || mouse.Y <= Width - 1) - { - if (!_Checked) - { - Checked = true; - } - - Invalidate(); - } - base.OnClick(e); - } - - public event CheckedChangedEventHandler CheckedChanged; - public delegate void CheckedChangedEventHandler(object sender); - - protected override void OnCreateControl() - { - base.OnCreateControl(); - InvalidateControls(); - } - - private void InvalidateControls() - { - if (!IsHandleCreated || !_Checked) - { - return; - } - - foreach (Control C in Parent.Controls) - { - if (!object.ReferenceEquals(C, this) && C is CrEaTiiOn_ClasicRadioButton button) - { - button.Checked = false; - } - } - } - #endregion - - #region Variables - private SmoothingMode _SmoothingType = SmoothingMode.HighQuality; - private Color _EllipseBorderColorA = Color.FromArgb(15, 15, 15); - private Color _EllipseBorderColorB = Color.FromArgb(15, 15, 15); - private Color _EllipseBackColorA = Color.Transparent; - private Color _EllipseBackColorB = Color.Transparent; - private Color _CheckedColorA = Color.FromArgb(250, 36, 38); - private Color _CheckedColorB = Color.FromArgb(250, 36, 38); - #endregion - - #region Settings - public SmoothingMode SmoothingType - { - get => _SmoothingType; - set - { - _SmoothingType = value; - Invalidate(); - } - } - - public Color EllipseBorderColorA - { - get => _EllipseBorderColorA; - set => _EllipseBorderColorA = value; - } - - public Color EllipseBorderColorB - { - get => _EllipseBorderColorB; - set => _EllipseBorderColorB = value; - } - - public Color EllipseBackColorA - { - get => _EllipseBackColorA; - set => _EllipseBackColorA = value; - } - - public Color EllipseBackColorB - { - get => _EllipseBackColorB; - set => _EllipseBackColorB = value; - } - - public Color CheckedColorA - { - get => _CheckedColorA; - set => _CheckedColorA = value; - } - - public Color CheckedColorB - { - get => _CheckedColorB; - set => _CheckedColorB = value; - } - #endregion - - public CrEaTiiOn_ClasicRadioButton() : base() - { - SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true); - BackColor = Color.Transparent; - ForeColor = Color.White; - Font = new("Segoe UI", 6.75f, FontStyle.Bold); - Size = new(105, 14); - DoubleBuffered = true; - Cursor = Cursors.Hand; - } - - protected override void OnPaint(PaintEventArgs e) - { - Bitmap B = new(Width, Height); - Graphics G = Graphics.FromImage(B); - - G.SmoothingMode = SmoothingType; - G.Clear(Parent.FindForm().BackColor); - - G.DrawEllipse(new(EllipseBorderColorA), new Rectangle(0, 0, Height - 2, Height - 1)); - LinearGradientBrush bgGrad = new(new Rectangle(0, 0, Height - 2, Height - 2), EllipseBackColorA, EllipseBackColorB, 90); - G.FillEllipse(bgGrad, new Rectangle(0, 0, Height - 2, Height - 2)); - G.DrawEllipse(new(EllipseBorderColorB), new Rectangle(1, 1, Height - 4, Height - 4)); - - if (Checked) - { - G.FillEllipse(new SolidBrush(CheckedColorA), new Rectangle(3, 3, Height - 8, Height - 8)); - G.FillEllipse(new SolidBrush(CheckedColorB), new Rectangle(4, 4, Height - 10, Height - 10)); - } - - G.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(16, 1), new StringFormat - { - Alignment = StringAlignment.Near, - LineAlignment = StringAlignment.Near - }); - - e.Graphics.DrawImage(B, 0, 0); - G.Dispose(); - B.Dispose(); - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ModernRadioButton.cs b/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ModernRadioButton.cs deleted file mode 100644 index f67e92c..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_ModernRadioButton.cs +++ /dev/null @@ -1,107 +0,0 @@ -#region Imports -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Windows.Forms; -#endregion - -namespace CBH.Controls -{ - class CrEaTiiOn_ModernRadioButton : CrEaTiiOn_Ultimate_RadioButton - { - //Fields - private Color checkedColor = Color.FromArgb(250, 36, 38); - private Color unCheckedColor = Color.Gray; - - //Properties - public Color CheckedColor - { - get - { - return checkedColor; - } - - set - { - checkedColor = value; - this.Invalidate(); - } - } - - public Color UnCheckedColor - { - get - { - return unCheckedColor; - } - - set - { - unCheckedColor = value; - this.Invalidate(); - } - } - - //Constructor - public CrEaTiiOn_ModernRadioButton() - { - this.MinimumSize = new Size(0, 21); - //Add a padding of 10 to the left to have a considerable distance between the text and the RadioButton. - this.Padding = new Padding(10, 0, 0, 0); - } - - //Overridden methods - protected override void OnPaint(PaintEventArgs pevent) - { - //Fields - Graphics graphics = pevent.Graphics; - graphics.SmoothingMode = SmoothingMode.AntiAlias; - float rbBorderSize = 18F; - float rbCheckSize = 12F; - RectangleF rectRbBorder = new RectangleF() - { - X = 0.5F, - Y = (this.Height - rbBorderSize) / 2, //Center - Width = rbBorderSize, - Height = rbBorderSize - }; - RectangleF rectRbCheck = new RectangleF() - { - X = rectRbBorder.X + ((rectRbBorder.Width - rbCheckSize) / 2), //Center - Y = (this.Height - rbCheckSize) / 2, //Center - Width = rbCheckSize, - Height = rbCheckSize - }; - - //Drawing - using (Pen penBorder = new Pen(checkedColor, 1.6F)) - using (SolidBrush brushRbCheck = new SolidBrush(checkedColor)) - using (SolidBrush brushText = new SolidBrush(this.ForeColor)) - { - //Draw surface - graphics.Clear(this.BackColor); - //Draw Radio Button - if (this.Checked) - { - graphics.DrawEllipse(penBorder, rectRbBorder);//Circle border - graphics.FillEllipse(brushRbCheck, rectRbCheck); //Circle Radio Check - } - else - { - penBorder.Color = unCheckedColor; - graphics.DrawEllipse(penBorder, rectRbBorder); //Circle border - } - //Draw text - graphics.DrawString(this.Text, this.Font, brushText, - rbBorderSize + 8, (this.Height - TextRenderer.MeasureText(this.Text, this.Font).Height) / 2);//Y=Center - } - } - - //X-> Obsolete code, this was replaced by the Padding property in the constructor - //(this.Padding = new Padding(10,0,0,0);) - //protected override void OnResize(EventArgs e) - //{ - // base.OnResize(e); - // this.Width = TextRenderer.MeasureText(this.Text, this.Font).Width + 30; - //} - } -} diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_RadioButton.cs b/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_RadioButton.cs index 9452b52..2febf5a 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_RadioButton.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/RadioButton/CrEaTiiOn_RadioButton.cs @@ -1,165 +1,119 @@ -#region Imports - -using System; -using System.ComponentModel; +using System; using System.Drawing; using System.Drawing.Drawing2D; +using System.Linq; using System.Windows.Forms; -#endregion - -namespace CBH.Controls +namespace CBH_WinForm_Theme_Library_NET { - #region CrEaTiiOn_RadioButton - - [DefaultEvent("CheckedChanged")] - public class CrEaTiiOn_Ultimate_RadioButton : Control + internal class CrEaTiiOn_RadioButton : Control { - #region Variables - - private int X; - private bool _Checked; - private Color _CheckedColor = Color.FromArgb(250, 36, 38); - private Color _CircleColor = Color.FromArgb(15, 15, 15); - private SmoothingMode _SmoothingType = SmoothingMode.HighQuality; + private bool isChecked; - #endregion - - #region Properties + // Properties for customization + public Color HighlightColor { get; set; } + public Color BaseColor { get; set; } + public Color InnerRingColor { get; set; } + public string Text { get; set; } + // Property for checked state public bool Checked { - get => _Checked; + get { return isChecked; } set { - _Checked = value; - InvalidateControls(); - CheckedChangedEvent?.Invoke(this); - Invalidate(); - } - } - - public SmoothingMode SmoothingType - { - get => _SmoothingType; - set - { - _SmoothingType = value; - Invalidate(); - } - } + if (isChecked != value && value) + { + // Uncheck other radio buttons in the same container + UncheckOtherRadioButtons(); + } - public Color CircleColor - { - get => _CircleColor; - set - { - _CircleColor = value; + isChecked = value; Invalidate(); } } - public Color CheckedColor + // Constructor + public CrEaTiiOn_RadioButton() { - get => _CheckedColor; - set - { - _CheckedColor = value; - Invalidate(); - } - } - - #endregion + // Default color values + HighlightColor = Color.FromArgb(250, 36, 38); + BaseColor = Color.FromArgb(15, 15, 15); + InnerRingColor = Color.White; - #region EventArgs + // Default size and checked state + Size = new Size(190, 20); + isChecked = false; - public delegate void CheckedChangedEventHandler(object sender); - private CheckedChangedEventHandler CheckedChangedEvent; - - public event CheckedChangedEventHandler CheckedChanged - { - add => CheckedChangedEvent = (CheckedChangedEventHandler)Delegate.Combine(CheckedChangedEvent, value); - remove => CheckedChangedEvent = (CheckedChangedEventHandler)Delegate.Remove(CheckedChangedEvent, value); + // Default text + Text = "RadioButton"; } - protected override void OnMouseDown(MouseEventArgs e) + // Override for painting the control + protected override void OnPaint(PaintEventArgs e) { - if (!_Checked) + base.OnPaint(e); + + // Determine the color based on the checked state + Color currentColor = isChecked ? HighlightColor : BaseColor; + + // Draw the main filled circle + using (var brush = new SolidBrush(currentColor)) { - @Checked = true; + // Draw a filled circle with anti-aliasing + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + e.Graphics.FillEllipse(brush, 0, 0, Height - 1, Height - 1); } - else + + if (isChecked) { - @Checked = false; + // Draw the inner filled circle when checked + using (var brush = new SolidBrush(InnerRingColor)) + { + // Draw a filled ellipse for the inner circle + e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; + e.Graphics.FillEllipse(brush, 4, 4, Height - 9, Height - 9); + } } - Focus(); - base.OnMouseDown(e); - } - - protected override void OnMouseMove(MouseEventArgs e) - { - base.OnMouseMove(e); - X = e.X; - Invalidate(); - } - - protected override void OnTextChanged(EventArgs e) - { - base.OnTextChanged(e); - //Width = 20 + (int)CreateGraphics().MeasureString(Text, Font).Width; - //Width = 20 + (int)TextRenderer.MeasureText(Text, Font).Width; + using (var textBrush = new SolidBrush(ForeColor)) + { + // Adjusted the gap between text and circles + e.Graphics.DrawString(Text, Font, textBrush, Height + 5, (Height - Font.Height) / 2); + } } - protected override void OnResize(EventArgs e) + // Override for handling click events + protected override void OnClick(EventArgs e) { - base.OnResize(e); - Height = 17; + base.OnClick(e); + // Toggle the checked state on click + Checked = !Checked; } - #endregion - - public CrEaTiiOn_Ultimate_RadioButton() + // Uncheck other radio buttons in the same container + private void UncheckOtherRadioButtons() { - Size = new(120, 17); - DoubleBuffered = true; - Cursor = Cursors.Hand; - ForeColor = Color.White; - } + // Get the parent container + Control container = Parent; - private void InvalidateControls() - { - if (!IsHandleCreated || !_Checked) + // Check if the container is not null and is a Form or Panel, adjust as needed + while (container != null && !(container is Form || container is Panel)) { - return; + container = container.Parent; } - foreach (Control _Control in Parent.Controls) + // If a valid container is found, uncheck other radio buttons + if (container != null) { - if (_Control != this && _Control is CrEaTiiOn_Ultimate_RadioButton button) + foreach (var control in container.Controls.OfType()) { - button.Checked = false; + if (control != this) + { + control.Checked = false; + } } } } - - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - Graphics G = e.Graphics; - G.Clear(Parent.BackColor); - G.SmoothingMode = SmoothingType; - - G.FillEllipse(new SolidBrush(CircleColor), new Rectangle(0, 0, 16, 16)); - - if (_Checked) - { - G.DrawString("a", new Font("Marlett", 15), new SolidBrush(CheckedColor), new Point(-3, -2)); - } - - G.DrawString(Text, Font, new SolidBrush(ForeColor), new Point(20, -3)); - } } - - #endregion -} \ No newline at end of file +} diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_FlatSliderBar.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_FlatSliderBar.cs deleted file mode 100644 index 8c9b189..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_FlatSliderBar.cs +++ /dev/null @@ -1,164 +0,0 @@ -#region Imports -using CBH_Ultimate_Theme_Library.Theme.Helpers; -using System; -using System.ComponentModel; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Drawing.Text; -using System.Windows.Forms; -#endregion - -namespace CBH.Controls -{ - public class CrEaTiiOn_FlatSliderBar : Control - { - #region 变量 - private RectangleF valueBar = new RectangleF(7, 5, 0, 6); - private RectangleF valueRect = new RectangleF(0, 1, 14, 14); - private bool mouseFlat = false; - - #endregion - - #region 属性 - private Color _themeColor = Color.FromArgb(250, 36, 38); - [Description("主题颜色")] - public Color ThemeColor - { - get { return _themeColor; } - set - { - _themeColor = value; - Invalidate(); - } - } - - private int _minValue = 0; - [Description("Slider的最小值")] - public int MinValue - { - get { return _minValue; } - set - { - if (value > _maxValue || value > _value) return; - _minValue = value; - Invalidate(); - } - } - - private int _maxValue = 10; - [Description("Slider的最大值")] - public int MaxValue - { - get { return _maxValue; } - set - { - if (value < _minValue || value < _value) return; - _maxValue = value; - Invalidate(); - } - } - - private int _value = 0; - [Description("Slider的当前值")] - public int Value - { - get { return _value; } - set - { - _value = value >= _minValue && value <= _maxValue ? value : _minValue; - Invalidate(); - } - } - - private bool _showValue = false; - [Description("是否显示数值")] - public bool ShowValue - { - get { return _showValue; } - set - { - _showValue = value; - Invalidate(); - } - } - - private int ValueWidth - { - get { return Convert.ToInt32(_value * (Width - 30) / (_maxValue - _minValue)); } - } - - #endregion - - #region 事件 - protected override void OnResize(EventArgs e) - { - base.OnResize(e); - Height = _showValue ? 45 : 16; - } - - protected override void OnMouseDown(MouseEventArgs e) - { - base.OnMouseDown(e); - if (e.Button == MouseButtons.Left) - { - mouseFlat = new RectangleF(ValueWidth + 7, Height - 15, 14, 14).Contains(e.Location); - Invalidate(); - } - } - - protected override void OnMouseMove(MouseEventArgs e) - { - base.OnMouseMove(e); - if (mouseFlat && e.X > -1 && e.X < (Width + 1)) - { - _value = _minValue + Convert.ToInt32((float)(_maxValue - _minValue) * ((float)e.X / (float)Width)); - Invalidate(); - } - } - - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - mouseFlat = false; - Invalidate(); - } - - #endregion - - protected override void OnPaint(PaintEventArgs e) - { - Graphics graphics = e.Graphics; - graphics.SmoothingMode = SmoothingMode.HighQuality; - graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; - graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; - graphics.Clear(Parent.BackColor); - - if (ShowValue && mouseFlat) - { - graphics.FillEllipse(new SolidBrush(_themeColor), new RectangleF(ValueWidth - 2 + 5, 1, 18, 18)); - graphics.FillPolygon(new SolidBrush(_themeColor), new PointF[] - { - new PointF(ValueWidth+1.305F-2+5,13.5F+1), - new PointF(ValueWidth+7.794F+9-2+5,13.5F+1), - new PointF(ValueWidth+9-2+5,28F) - }); - graphics.DrawString(_value.ToString(), Font, new SolidBrush(Color.White), new RectangleF(ValueWidth - 2 + 5, 2, 18, 18), StringAlign.Center); - } - - graphics.FillRectangle(new SolidBrush(DrawHelper.BackColor), new RectangleF(15, Height - 10, Width - 30, 4)); - graphics.FillRectangle(new SolidBrush(Color.White), new RectangleF(15, Height - 10, ValueWidth, 4)); - graphics.FillRectangle(new SolidBrush(_themeColor), new RectangleF(15, Height - 10, ValueWidth, 4)); - graphics.FillEllipse(new SolidBrush(_themeColor), new RectangleF(ValueWidth + 5, Height - 17, 16, 16)); - graphics.FillEllipse(new SolidBrush(Color.White), new RectangleF(ValueWidth + 8, Height - 14, 10, 10)); - } - - - public CrEaTiiOn_FlatSliderBar() - { - SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true); - DoubleBuffered = true; - Height = 45; - Font = new Font("Segoe UI", 8F); - } - } -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_ModernSlider.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_ModernSlider.cs deleted file mode 100644 index 6c478e3..0000000 --- a/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_ModernSlider.cs +++ /dev/null @@ -1,445 +0,0 @@ -#region Imports - -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Drawing; -using System.Drawing.Drawing2D; -using System.Windows.Forms; - -#endregion - -namespace CBH.Controls -{ - #region CrEaTiiOn_ModernSlider - - public class CrEaTiiOn_ModernSlider : Control - { - public CrEaTiiOn_ModernSlider() - { - base.Size = new Size(250, 20); - base.SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); - barRectangle = new(base.Height / 2 + 1, 1, base.Width - base.Height, base.Height - 1); - Cursor = Cursors.Hand; - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The bar thickness")] - public int BarThickness - { - get => barThickness; - set - { - barThickness = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The increment incresed or decreased when not clicking in the handle")] - public int BigStepIncrement - { - get => bigStepIncrement; - set - { - bigStepIncrement = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The default percentage")] - public int Percentage - { - get => percentage; - set - { - percentage = value; - OnScroll(); - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The max percentage")] - public int Max - { - get => max; - set - { - max = value; - OnScroll(); - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The filled color")] - public Color FilledColor - { - get => filledColor; - set - { - filledColor = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The unfilled color")] - public Color UnfilledColor - { - get => unfilledColor; - set - { - unfilledColor = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The knob color")] - public Color KnobColor - { - get => knobColor; - set - { - knobColor = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The knob image")] - public Image KnobImage - { - get => knobImage; - set - { - knobImage = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("Allow instantly jumping to the position clicked")] - public bool QuickHopping - { - get => quickHopping; - set - { - quickHopping = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The slider style")] - public Style SliderStyle - { - get => sliderStyle; - set - { - sliderStyle = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The positions")] - public List Positions - { - get => _Positions; - set - { - _Positions = value; - base.Invalidate(); - } - } - - [Category("CrEaTiiOn")] - [Browsable(true)] - [Description("The colors")] - public List Colors - { - get => _Colors; - set - { - _Colors = value; - base.Invalidate(); - } - } - - private SmoothingMode _SmoothingType = SmoothingMode.AntiAlias; - [Category("CrEaTiiOn")] - [Browsable(true)] - public SmoothingMode SmoothingType - { - get => _SmoothingType; - set - { - _SmoothingType = value; - Invalidate(); - } - } - - private PixelOffsetMode _PixelOffsetType = PixelOffsetMode.HighQuality; - [Category("CrEaTiiOn")] - [Browsable(true)] - public PixelOffsetMode PixelOffsetType - { - get => _PixelOffsetType; - set - { - _PixelOffsetType = value; - Invalidate(); - } - } - - private CompositingQuality _CompositingQualityType = CompositingQuality.HighQuality; - [Category("CrEaTiiOn")] - [Browsable(true)] - public CompositingQuality CompositingQualityType - { - get => _CompositingQualityType; - set - { - _CompositingQualityType = value; - Invalidate(); - } - } - - private InterpolationMode _InterpolationType = InterpolationMode.HighQualityBilinear; - [Category("CrEaTiiOn")] - [Browsable(true)] - public InterpolationMode InterpolationType - { - get => _InterpolationType; - set - { - _InterpolationType = value; - Invalidate(); - } - } - - public event EventHandler Scroll; - - protected virtual void OnScroll() - { - Scroll?.Invoke(this, EventArgs.Empty); - } - - protected override void OnMouseDown(MouseEventArgs e) - { - base.OnMouseDown(e); - if (quickHopping) - { - Percentage = (int)Math.Round(max * e.X / (double)base.Width); - onHandle = true; - return; - } - - int num = Percentage * base.Width / max; - - if (e.X > num - base.Height / 2 && e.X < num + base.Height / 2) - { - onHandle = true; - return; - } - - if (e.X < num - base.Height / 2) - { - Percentage -= bigStepIncrement; - if (Percentage < 0) - { - Percentage = 0; - } - base.Invalidate(); - return; - } - - if (e.X > num + base.Height / 2) - { - Percentage += bigStepIncrement; - if (Percentage > max) - { - Percentage = max; - } - base.Invalidate(); - } - } - - protected override void OnMouseMove(MouseEventArgs e) - { - base.OnMouseMove(e); - if (onHandle) - { - Percentage = (int)Math.Round(max * e.X / (double)base.Width); - if (Percentage < 0) - { - Percentage = 0; - } - if (Percentage > max) - { - Percentage = max; - } - base.Invalidate(); - } - } - - protected override void OnMouseUp(MouseEventArgs e) - { - base.OnMouseUp(e); - onHandle = false; - } - - protected override void OnPaint(PaintEventArgs e) - { - base.OnPaint(e); - - BufferedGraphicsContext bufferedGraphicsContext = BufferedGraphicsManager.Current; - bufferedGraphicsContext.MaximumBuffer = new Size(base.Width + 1, base.Height + 1); - - bufferedGraphics = bufferedGraphicsContext.Allocate(base.CreateGraphics(), base.ClientRectangle); - - bufferedGraphics.Graphics.SmoothingMode = SmoothingType; - bufferedGraphics.Graphics.InterpolationMode = InterpolationType; - bufferedGraphics.Graphics.CompositingQuality = CompositingQualityType; - bufferedGraphics.Graphics.PixelOffsetMode = PixelOffsetType; - - int num = Percentage * base.Width / max; - int num2 = Percentage * barRectangle.Width / max; - - bufferedGraphics.Graphics.Clear(BackColor); - - if (sliderStyle == Style.Flat) - { - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(unfilledColor), base.Height / 2 + 1, base.Height / 2 - barThickness / 2, base.Width - base.Height - 2, barThickness); - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(filledColor), 1 + base.Height / 2, base.Height / 2 - barThickness / 2, num2 - 2, barThickness); - - if (knobImage == null) - { - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(knobColor), num2 + 1, 1, base.Height - 2, base.Height - 2); - } - else - { - bufferedGraphics.Graphics.DrawImage(new Bitmap(knobImage, base.Height - 2, base.Height - 2), num2 + 1, 1); - } - } - - if (sliderStyle == Style.MacOS) - { - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(185, 185, 185)), base.Height / 2 + 1, base.Height / 2 - barThickness / 2, base.Width - base.Height - 2, barThickness); - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(80, 150, 230)), 1 + base.Height / 2, base.Height / 2 - barThickness / 2, num2 - 2, barThickness); - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(Color.White), num2 + 1, 1, base.Height - 2, base.Height - 2); - bufferedGraphics.Graphics.DrawEllipse(new Pen(Color.FromArgb(190, 200, 200)), num2 + 1, 1, base.Height - 2, base.Height - 2); - } - - if (sliderStyle == Style.Windows10) - { - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(146, 147, 148)), base.Height / 2 + 1, base.Height / 2 - barThickness / 2, base.Width - base.Height - 2, barThickness); - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(65, 155, 225)), 1 + base.Height / 2, base.Height / 2 - barThickness / 2, num2 - 2, barThickness); - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(0, 120, 215)), num2 + 1 + base.Height / 3, 3, base.Height / 2 - 2, base.Height - 6); - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(0, 120, 215)), num2 + 1 + base.Height / 3, 0, base.Height / 2 - 2, 4); - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(0, 120, 215)), num2 + 1 + base.Height / 3, base.Height - 5, base.Height / 2 - 2, 4); - } - - if (sliderStyle == Style.Android) - { - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(20, 20, 20)), base.Height / 2 + 1, base.Height / 2 - barThickness / 2, base.Width - base.Height - 2, barThickness); - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.FromArgb(250, 36, 38)), 1 + base.Height / 2, base.Height / 2 - barThickness / 2, num2 - 2, barThickness); - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(250, 36, 38)), num2 + 1 + barThickness / 3 * 5, base.Height / 2 - barThickness / 3 * 4, barThickness * 2, barThickness * 2); - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(Color.FromArgb(20, 20, 20)), num2 + 1, 1, base.Height - 2, base.Height - 2); - } - - if (sliderStyle == Style.Material && Positions.Count == Colors.Count) - { - LinearGradientBrush linearGradientBrush = new(new Rectangle(0, 0, base.Width, base.Height), Color.Black, Color.Black, 0f, false) - { - InterpolationColors = new ColorBlend - { - Positions = Positions.ToArray(), - Colors = Colors.ToArray() - } - }; - - linearGradientBrush.RotateTransform(1f); - - bufferedGraphics.Graphics.FillRectangle(linearGradientBrush, base.Height / 2 + 1, base.Height / 2 - barThickness / 2, base.Width - base.Height - 2, barThickness); - bufferedGraphics.Graphics.FillRectangle(new SolidBrush(Color.LightGray), 1 + base.Height / 2 + num2, base.Height / 2 - barThickness / 2, base.Width - base.Height - 2 - num2, barThickness); - bufferedGraphics.Graphics.FillEllipse(new SolidBrush(Color.White), num2 + 1, 1, base.Height - 2, base.Height - 2); - bufferedGraphics.Graphics.DrawEllipse(new Pen(Color.FromArgb(200, 200, 200)), num2 + 1, 1, base.Height - 2, base.Height - 2); - } - - bufferedGraphics.Render(e.Graphics); - } - - private Rectangle barRectangle; - - private BufferedGraphics bufferedGraphics; - - private bool onHandle; - - private int barThickness = 4; - - private int bigStepIncrement = 10; - - private int max = 100; - - private int percentage = 50; - - private Color filledColor = Color.FromArgb(1, 119, 215); - - private Color unfilledColor = Color.FromArgb(26, 169, 219); - - private Color knobColor = Color.Gray; - - private Image knobImage; - - private bool quickHopping; - - private Style sliderStyle = Style.Windows10; - - private List _Positions = new() - { - 0f, - 0.2f, - 0.4f, - 0.6f, - 0.8f, - 1f - }; - - private List _Colors = new() - { - Color.FromArgb(76, 217, 100), - Color.FromArgb(85, 205, 205), - Color.FromArgb(2, 124, 255), - Color.FromArgb(130, 75, 180), - Color.FromArgb(255, 0, 150), - Color.FromArgb(255, 45, 85) - }; - - public enum Style - { - Flat, - Material, - MacOS, - Android, - Windows10 - } - } - - #endregion -} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_Slider.cs b/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_Slider.cs new file mode 100644 index 0000000..c85d390 --- /dev/null +++ b/CBH-WinForm-Theme-NET/Theme/Controls/Slider/CrEaTiiOn_Slider.cs @@ -0,0 +1,196 @@ +using System; +using System.ComponentModel; +using System.Drawing; +using System.Drawing.Drawing2D; +using System.Windows.Forms; + +namespace CBH.Controls +{ + public class CrEaTiiOn_Slider : Control + { + private Rectangle barRectangle; + private bool onHandle; + private int barThickness = 4; + private int bigStepIncrement = 10; + private int max = 100; + private int percentage = 50; + private Color filledColor = Color.FromArgb(250, 36, 38); + private Color knobColor = Color.Gray; + + public CrEaTiiOn_Slider() + { + base.Size = new Size(250, 20); + base.SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); + barRectangle = new Rectangle(base.Height / 2 + 1, 1, base.Width - base.Height, base.Height - 1); + Cursor = Cursors.Hand; + } + + [Category("CrEaTiiOn")] + [Browsable(true)] + [Description("The bar thickness")] + public int BarThickness + { + get => barThickness; + set + { + barThickness = value; + base.Invalidate(); + } + } + + [Category("CrEaTiiOn")] + [Browsable(true)] + [Description("The filled color")] + public Color FilledColor + { + get => filledColor; + set + { + filledColor = value; + base.Invalidate(); + } + } + + [Category("CrEaTiiOn")] + [Browsable(true)] + [Description("The knob color")] + public Color KnobColor + { + get => knobColor; + set + { + knobColor = value; + base.Invalidate(); + } + } + + public event EventHandler Scroll; + + protected virtual void OnScroll() + { + Scroll?.Invoke(this, EventArgs.Empty); + } + + protected override void OnMouseDown(MouseEventArgs e) + { + base.OnMouseDown(e); + int num = Percentage * (base.Width - base.Height) / Max; + + if (e.X > num - base.Height / 2 && e.X < num + base.Height / 2) + { + onHandle = true; + return; + } + + if (e.X < num - base.Height / 2) + { + Percentage -= BigStepIncrement; + if (Percentage < 0) + { + Percentage = 0; + } + base.Invalidate(); + return; + } + + if (e.X > num + base.Height / 2) + { + Percentage += BigStepIncrement; + if (Percentage > Max) + { + Percentage = Max; + } + base.Invalidate(); + } + } + + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + if (onHandle) + { + Percentage = (int)Math.Round(Max * e.X / (double)base.Width); + if (Percentage < 0) + { + Percentage = 0; + } + if (Percentage > Max) + { + Percentage = Max; + } + base.Invalidate(); + } + } + + protected override void OnMouseUp(MouseEventArgs e) + { + base.OnMouseUp(e); + onHandle = false; + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + Graphics g = e.Graphics; + g.SmoothingMode = SmoothingMode.AntiAlias; + g.InterpolationMode = InterpolationMode.HighQualityBilinear; + g.CompositingQuality = CompositingQuality.HighQuality; + g.PixelOffsetMode = PixelOffsetMode.HighQuality; + + int num = Percentage * (base.Width - base.Height) / Max; + int knobRadius = base.Height / 2; + + g.Clear(BackColor); + + // Draw filled part of the slider + g.FillRectangle(new SolidBrush(FilledColor), knobRadius / 2, base.Height / 2 - BarThickness / 2, num, BarThickness); + + // Draw knob + int knobX = knobRadius / 2 + num; + int knobY = base.Height / 2 - knobRadius / 2; + g.FillEllipse(new SolidBrush(KnobColor), knobX, knobY, knobRadius, knobRadius); + } + + [Category("CrEaTiiOn")] + [Browsable(true)] + [Description("The increment increased or decreased when not clicking in the handle")] + public int BigStepIncrement + { + get => bigStepIncrement; + set + { + bigStepIncrement = value; + base.Invalidate(); + } + } + + [Category("CrEaTiiOn")] + [Browsable(true)] + [Description("The default percentage")] + public int Percentage + { + get => percentage; + set + { + percentage = value; + OnScroll(); + base.Invalidate(); + } + } + + [Category("CrEaTiiOn")] + [Browsable(true)] + [Description("The max percentage")] + public int Max + { + get => max; + set + { + max = value; + OnScroll(); + base.Invalidate(); + } + } + } +} diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_BarTabControl.cs b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_BarTabControl.cs index 0212cdf..4235e2c 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_BarTabControl.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_BarTabControl.cs @@ -1,14 +1,16 @@ -#region using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; -#endregion namespace CBH.Controls { public class CrEaTiiOn_BarTabControl : TabControl { + // Color properties for customization + public Color BackgroundColor { get; set; } = Color.FromArgb(15, 15, 15); + public Color TextColor { get; set; } = Color.White; + public Color AccentColor { get; set; } = Color.FromArgb(250, 36, 38); public CrEaTiiOn_BarTabControl() { @@ -16,272 +18,92 @@ public CrEaTiiOn_BarTabControl() DoubleBuffered = true; SizeMode = TabSizeMode.Fixed; ItemSize = new Size(44, 136); - } - - protected override void CreateHandle() - { - base.CreateHandle(); Alignment = TabAlignment.Left; } - public Pen ToPen(Color color) - { - return new Pen(color); - } - - public Brush ToBrush(Color color) - { - return new SolidBrush(color); - } - protected override void OnPaint(PaintEventArgs e) { - Bitmap B = new Bitmap(Width, Height); - Graphics G = Graphics.FromImage(B); - try - { - SelectedTab.BackColor = Color.FromArgb(15, 15, 15); - } - catch - { - } - G.Clear(Color.FromArgb(15, 15, 15)); - G.FillRectangle(new SolidBrush(Color.FromArgb(15, 15, 15)), new Rectangle(0, 0, ItemSize.Height + 4, Height)); - G.DrawLine(new Pen(Color.FromArgb(10, 10, 10)), new Point(ItemSize.Height + 3, 0), new Point(ItemSize.Height + 3, 999)); - for (int i = 0; i <= TabCount - 1; i++) - { - if (i == SelectedIndex) - { - Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1)); - ColorBlend myBlend = new ColorBlend(); - myBlend.Colors = new Color[] { - Color.FromArgb(250, 36, 38), - Color.FromArgb(250, 36, 38), - Color.FromArgb(250, 36, 38) - }; - myBlend.Positions = new float[] { - 0f, - 0.5f, - 1f - }; - LinearGradientBrush lgBrush = new LinearGradientBrush(x2, Color.Black, Color.Black, 90f); - lgBrush.InterpolationColors = myBlend; - G.FillRectangle(lgBrush, x2); - G.DrawRectangle(new Pen(Color.FromArgb(15, 15, 15)), x2); - - G.SmoothingMode = SmoothingMode.HighQuality; - Point[] p = { - new Point(ItemSize.Height - 3, GetTabRect(i).Location.Y + 20), - new Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 14), - new Point(ItemSize.Height + 4, GetTabRect(i).Location.Y + 27) - }; + base.OnPaint(e); - if (ImageList != null) - { - try - { + Graphics g = e.Graphics; + g.Clear(BackgroundColor); - if (ImageList.Images[TabPages[i].ImageIndex] != null) - { - G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(x2.Location.X + 8, x2.Location.Y + 6)); - G.DrawString(" " + TabPages[i].Text, Font, Brushes.Black, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - else - { - G.DrawString(TabPages[i].Text, new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.Black, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - } - catch (Exception ex) - { - G.DrawString(TabPages[i].Text, new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.Black, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - } - else - { - G.DrawString(TabPages[i].Text, new Font(Font.FontFamily, Font.Size, FontStyle.Bold), Brushes.Black, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(x2.Location.X - 1, x2.Location.Y - 1), new Point(x2.Location.X, x2.Location.Y)); - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(x2.Location.X - 1, x2.Bottom - 1), new Point(x2.Location.X, x2.Bottom)); - } - else - { - Rectangle x2 = new Rectangle(new Point(GetTabRect(i).Location.X - 2, GetTabRect(i).Location.Y - 2), new Size(GetTabRect(i).Width + 3, GetTabRect(i).Height - 1)); - G.FillRectangle(new SolidBrush(Color.FromArgb(15, 15, 15)), x2); - G.DrawLine(new Pen(Color.FromArgb(15, 15, 15)), new Point(x2.Right, x2.Top), new Point(x2.Right, x2.Bottom)); - if (ImageList != null) - { - try - { - if (ImageList.Images[TabPages[i].ImageIndex] != null) - { - G.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(x2.Location.X + 8, x2.Location.Y + 6)); - G.DrawString(" " + TabPages[i].Text, Font, Brushes.DimGray, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - else - { - G.DrawString(TabPages[i].Text, Font, Brushes.DimGray, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - } - catch (Exception ex) - { - G.DrawString(TabPages[i].Text, Font, Brushes.DimGray, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - } - else - { - G.DrawString(TabPages[i].Text, Font, Brushes.DimGray, x2, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Center - }); - } - } - } + // Only repaint if there are tabs + if (TabCount == 0) + return; - e.Graphics.DrawImage((Bitmap)B.Clone(), 0, 0); - G.Dispose(); - B.Dispose(); - } - - - int OldIndex; - private int _Speed = 8; - public int Speed - { - get { return _Speed; } - set + // Draw each tab + for (int i = 0; i < TabCount; i++) { - if (value > 20 | value < -20) + Rectangle tabRect = GetTabRect(i); + + if (i == SelectedIndex) { - MessageBox.Show("Speed needs to be in between -20 and 20."); + DrawSelectedTab(g, tabRect); } else { - _Speed = value; + DrawUnselectedTab(g, tabRect); } } } - public void DoAnimationScrollLeft(Control Control1, Control Control2) + private void DrawSelectedTab(Graphics g, Rectangle tabRect) { - Graphics G = Control1.CreateGraphics(); - Bitmap P1 = new Bitmap(Control1.Width, Control1.Height); - Bitmap P2 = new Bitmap(Control2.Width, Control2.Height); - Control1.DrawToBitmap(P1, new Rectangle(0, 0, Control1.Width, Control1.Height)); - Control2.DrawToBitmap(P2, new Rectangle(0, 0, Control2.Width, Control2.Height)); - - foreach (Control c in Control1.Controls) + // Fill background + using (Brush bgBrush = new SolidBrush(AccentColor)) { - c.Hide(); + g.FillRectangle(bgBrush, tabRect); } - int Slide = Control1.Width - (Control1.Width % _Speed); - - int a = 0; - for (a = 0; a <= Slide; a += _Speed) + // Draw gradient background for selected tab + Rectangle selectedTabRect = new Rectangle(tabRect.X - 2, tabRect.Y - 2, tabRect.Width + 3, tabRect.Height - 1); + using (LinearGradientBrush lgBrush = new LinearGradientBrush(selectedTabRect, Color.Black, Color.Black, 90f)) { - G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height)); - G.DrawImage(P2, new Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height)); - } - a = Control1.Width; - G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height)); - G.DrawImage(P2, new Rectangle(a - Control2.Width, 0, Control2.Width, Control2.Height)); + ColorBlend blend = new ColorBlend(); + blend.Colors = new Color[] { AccentColor, AccentColor, AccentColor }; + blend.Positions = new float[] { 0f, 0.5f, 1f }; + lgBrush.InterpolationColors = blend; - SelectedTab = (TabPage)Control2; - - foreach (Control c in Control2.Controls) - { - c.Show(); + g.FillRectangle(lgBrush, selectedTabRect); } - foreach (Control c in Control1.Controls) + // Draw arrow + g.SmoothingMode = SmoothingMode.HighQuality; + Point[] points = { + new Point(tabRect.Right - 3, tabRect.Y + 20), + new Point(tabRect.Right + 4, tabRect.Y + 14), + new Point(tabRect.Right + 4, tabRect.Y + 27) + }; + g.DrawLines(new Pen(AccentColor), points); + + // Drawing tab text and images + if (SelectedIndex >= 0 && SelectedIndex < TabPages.Count) { - c.Show(); - } - } - - protected override void OnSelecting(System.Windows.Forms.TabControlCancelEventArgs e) - { - if (OldIndex < e.TabPageIndex) - { - DoAnimationScrollRight(TabPages[OldIndex], TabPages[e.TabPageIndex]); - } - else - { - DoAnimationScrollLeft(TabPages[OldIndex], TabPages[e.TabPageIndex]); + if (ImageList != null && ImageList.Images[TabPages[SelectedIndex].ImageIndex] != null) + { + g.DrawImage(ImageList.Images[TabPages[SelectedIndex].ImageIndex], new Point(selectedTabRect.X + 8, selectedTabRect.Y + 6)); + } + g.DrawString(" " + TabPages[SelectedIndex].Text, Font, new SolidBrush(TextColor), selectedTabRect, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); } } - protected override void OnDeselecting(System.Windows.Forms.TabControlCancelEventArgs e) + private void DrawUnselectedTab(Graphics g, Rectangle tabRect) { - OldIndex = e.TabPageIndex; - } + // Fill background + Rectangle unselectedTabRect = new Rectangle(tabRect.X - 2, tabRect.Y - 2, tabRect.Width + 3, tabRect.Height - 1); + g.FillRectangle(new SolidBrush(BackgroundColor), unselectedTabRect); + g.DrawLine(new Pen(BackgroundColor), tabRect.Right, tabRect.Top, tabRect.Right, tabRect.Bottom); - public void DoAnimationScrollRight(Control Control1, Control Control2) - { - Graphics G = Control1.CreateGraphics(); - Bitmap P1 = new Bitmap(Control1.Width, Control1.Height); - Bitmap P2 = new Bitmap(Control2.Width, Control2.Height); - Control1.DrawToBitmap(P1, new Rectangle(0, 0, Control1.Width, Control1.Height)); - Control2.DrawToBitmap(P2, new Rectangle(0, 0, Control2.Width, Control2.Height)); - - foreach (Control c in Control1.Controls) - { - c.Hide(); - } - - int Slide = Control1.Width - (Control1.Width % _Speed); - - int a = 0; - for (a = 0; a >= -Slide; a += -_Speed) - { - G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height)); - G.DrawImage(P2, new Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height)); - } - a = Control1.Width; - G.DrawImage(P1, new Rectangle(a, 0, Control1.Width, Control1.Height)); - G.DrawImage(P2, new Rectangle(a + Control2.Width, 0, Control2.Width, Control2.Height)); - - SelectedTab = (TabPage)Control2; - - foreach (Control c in Control2.Controls) + // Drawing tab text and images + if (SelectedIndex >= 0 && SelectedIndex < TabPages.Count) { - c.Show(); - } - - foreach (Control c in Control1.Controls) - { - c.Show(); + if (ImageList != null && ImageList.Images[TabPages[SelectedIndex].ImageIndex] != null) + { + g.DrawImage(ImageList.Images[TabPages[SelectedIndex].ImageIndex], new Point(tabRect.X + 8, tabRect.Y + 6)); + } + g.DrawString(TabPages[SelectedIndex].Text, Font, new SolidBrush(TextColor), tabRect, new StringFormat { LineAlignment = StringAlignment.Center, Alignment = StringAlignment.Center }); } } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_FlatTabControl.cs b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_FlatTabControl.cs index 919ab85..4472f9f 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_FlatTabControl.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_FlatTabControl.cs @@ -1,5 +1,4 @@ -using CBH_Ultimate_Theme_Library.Theme.Helpers; -using System; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; @@ -9,9 +8,9 @@ namespace CBH.Controls { public class CrEaTiiOn_FlatTabControl : TabControl { - private int enterIndex; - private bool enterFlag = false; + private int hoverIndex = -1; private Color _themeColor = Color.FromArgb(250, 36, 38); + public CrEaTiiOn_FlatTabControl() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.OptimizedDoubleBuffer, true); @@ -20,8 +19,7 @@ public CrEaTiiOn_FlatTabControl() SizeMode = TabSizeMode.Fixed; ItemSize = new Size(120, 40); TabPageColor = Color.Transparent; - ThemeColor = Color.FromArgb(250, 36, 38); - TabPageForeColor = Color.White; + TabPageForeColor = Color.Black; } public Color ThemeColor @@ -34,71 +32,34 @@ public Color ThemeColor } } - private Color _tabPageColor = Color.White; - public Color TabPageColor - { - get { return _tabPageColor; } - set - { - _tabPageColor = value; - Invalidate(); - } - } - - private Color _tabPageForeColor = Color.Black; - public Color TabPageForeColor - { - get { return _tabPageForeColor; } - set - { - _tabPageForeColor = value; - Invalidate(); - } - } - - public override Rectangle DisplayRectangle - { - get - { - Rectangle rect = base.DisplayRectangle; - return new Rectangle(rect.Left - 4, rect.Top - 4, rect.Width + 8, rect.Height + 8); - } - } + public Color TabPageColor { get; set; } = Color.White; - protected override CreateParams CreateParams - { - get - { - CreateParams cp = base.CreateParams; - cp.ExStyle |= 0x02000000; - return cp; - } - } + public Color TabPageForeColor { get; set; } = Color.Black; protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); - enterFlag = true; for (int i = 0; i < TabCount; i++) { - var tempRect = GetTabRect(i); - if (tempRect.Contains(e.Location)) + if (GetTabRect(i).Contains(e.Location)) { - enterIndex = i; + hoverIndex = i; + Invalidate(); + break; } } - Invalidate(); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); - enterFlag = false; + hoverIndex = -1; Invalidate(); } protected override void OnPaint(PaintEventArgs e) { + base.OnPaint(e); var graphics = e.Graphics; graphics.SmoothingMode = SmoothingMode.HighQuality; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; @@ -107,45 +68,30 @@ protected override void OnPaint(PaintEventArgs e) for (int i = 0; i < TabCount; i++) { - if (i == SelectedIndex) - { - graphics.FillRectangle(new SolidBrush(_themeColor), GetTabRect(i).X + 3, ItemSize.Height - 3, ItemSize.Width - 6, 3); - graphics.DrawString(TabPages[i].Text.ToUpper(), Font, new SolidBrush(_themeColor), GetTabRect(i), StringAlign.Center); - } - else + Rectangle tabRect = GetTabRect(i); + if (i == SelectedIndex || i == hoverIndex) { - if (i == enterIndex && enterFlag) + using (SolidBrush brush = new SolidBrush(i == SelectedIndex ? _themeColor : Color.FromArgb(250, 36, 38))) { - graphics.FillRectangle(new SolidBrush(Color.FromArgb(250, 36, 38)), GetTabRect(i).X + 3, ItemSize.Height - 3, ItemSize.Width - 6, 3); + graphics.FillRectangle(brush, tabRect.X + 3, tabRect.Bottom - 3, tabRect.Width - 6, 3); } - - graphics.DrawString(TabPages[i].Text.ToUpper(), Font, new SolidBrush(Color.Black), GetTabRect(i), StringAlign.Center); } - } - for (int i = 0; i < TabCount; i++) - { - if (i == SelectedIndex) + using (SolidBrush brush = new SolidBrush(TabPageColor)) { - graphics.FillRectangle(new SolidBrush(_themeColor), GetTabRect(i).X + 3, ItemSize.Height - 3, ItemSize.Width - 6, 3); - graphics.DrawString(TabPages[i].Text.ToUpper(), Font, new SolidBrush(_themeColor), GetTabRect(i), StringAlign.Center); + Rectangle tabPageRect = tabRect; + tabPageRect.Inflate(-3, -3); + graphics.FillRectangle(brush, tabPageRect); } - else - { - if (i == enterIndex && enterFlag) - { - graphics.FillRectangle(new SolidBrush(Color.FromArgb(250, 36, 38)), GetTabRect(i).X + 3, ItemSize.Height - 3, ItemSize.Width - 6, 3); - } - // Draw the TabPage background color - Rectangle rect = GetTabRect(i); - rect.Inflate(-3, -3); - using (SolidBrush brush = new SolidBrush(_tabPageColor)) + using (SolidBrush brush = new SolidBrush(TabPageForeColor)) + { + StringFormat stringFormat = new StringFormat { - graphics.FillRectangle(brush, rect); - } - - graphics.DrawString(TabPages[i].Text.ToUpper(), Font, new SolidBrush(_tabPageForeColor), GetTabRect(i), StringAlign.Center); + Alignment = StringAlignment.Center, + LineAlignment = StringAlignment.Center + }; + graphics.DrawString(TabPages[i].Text.ToUpper(), Font, brush, tabRect, stringFormat); } } } diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_MetroTabControl.cs b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_MetroTabControl.cs index 66ba14a..3f378dc 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_MetroTabControl.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_MetroTabControl.cs @@ -1,10 +1,8 @@ -#region Imports -using System; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Runtime.InteropServices; using System.Windows.Forms; -#endregion namespace CBH.Controls { @@ -21,18 +19,26 @@ private static extern IntPtr CreateRoundRectRgn int nHeightEllipse // height of ellipse ); + private Color accentColor = Color.FromArgb(250, 36, 38); + + // Property to customize the accent color + public Color AccentColor + { + get { return accentColor; } + set + { + accentColor = value; + Invalidate(); // Redraw control when accent color changes + } + } + public CrEaTiiOn_MetroTabControl() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); ItemSize = new Size(0, 34); Padding = new Point(24, 0); Font = new Font("Segoe UI", 12); - } - - protected override void CreateHandle() - { - base.CreateHandle(); - Alignment = TabAlignment.Top; + Alignment = TabAlignment.Top; // Moved setting Alignment to constructor for consistency } protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) @@ -44,34 +50,30 @@ protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) G.SmoothingMode = SmoothingMode.HighQuality; G.Clear(Parent.BackColor); - Color FontColor = new Color(); - - - for (int i = 0; i <= TabCount - 1; i++) + for (int i = 0; i < TabCount; i++) // Removed unnecessary -1 in the loop condition { Rectangle mainRect = GetTabRect(i); + Color fontColor = Color.White; // Font color can be set directly if (i == SelectedIndex) { - FontColor = Color.White; - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(mainRect.X - 2, mainRect.Height - 1), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1)); - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(mainRect.X - 2, mainRect.Height), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height)); + G.DrawLine(new Pen(AccentColor), new Point(mainRect.X - 2, mainRect.Height - 1), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1)); + G.DrawLine(new Pen(AccentColor), new Point(mainRect.X - 2, mainRect.Height), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height)); } else { - FontColor = Color.White; - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(mainRect.X - 2, mainRect.Height - 1), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1)); - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(mainRect.X - 2, mainRect.Height), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height)); + G.DrawLine(new Pen(AccentColor), new Point(mainRect.X - 2, mainRect.Height - 1), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height - 1)); + G.DrawLine(new Pen(AccentColor), new Point(mainRect.X - 2, mainRect.Height), new Point(mainRect.X + mainRect.Width - 2, mainRect.Height)); } if (i != 0) { - G.DrawLine(new Pen(Color.FromArgb(250, 36, 38)), new Point(mainRect.X - 4, mainRect.Height - 7), new Point(mainRect.X + 4, mainRect.Y + 6)); + G.DrawLine(new Pen(AccentColor), new Point(mainRect.X - 4, mainRect.Height - 7), new Point(mainRect.X + 4, mainRect.Y + 6)); } int titleX = (mainRect.Location.X + mainRect.Width / 2) - Convert.ToInt32((G.MeasureString(TabPages[i].Text, Font).Width / 2)); int titleY = (mainRect.Location.Y + mainRect.Height / 2) - Convert.ToInt32((G.MeasureString(TabPages[i].Text, Font).Height / 2)); - G.DrawString(TabPages[i].Text, Font, new SolidBrush(FontColor), new Point(titleX, titleY)); + G.DrawString(TabPages[i].Text, Font, new SolidBrush(fontColor), new Point(titleX, titleY)); try { @@ -79,9 +81,11 @@ protected override void OnPaint(System.Windows.Forms.PaintEventArgs e) } catch { + // Handle exceptions } - } + + // Set region for rounded corners Region = System.Drawing.Region.FromHrgn(CreateRoundRectRgn(0, 0, Width, Height, 10, 10)); } } diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_TabControl.cs b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_TabControl.cs new file mode 100644 index 0000000..fd9d38a --- /dev/null +++ b/CBH-WinForm-Theme-NET/Theme/Controls/TabControl/CrEaTiiOn_TabControl.cs @@ -0,0 +1,80 @@ +using System; +using System.Drawing; +using System.Windows.Forms; + +namespace CBH.Controls +{ + public class CrEaTiiOn_TabControl : TabControl + { + // Color properties for customization + public Color TabColor { get; set; } = Color.FromArgb(15, 15, 15); + public Color TabTextColor { get; set; } = Color.LightGray; + public Color SelectedTabColor { get; set; } = Color.FromArgb(25, 25, 25); + public Color SelectedTabTextColor { get; set; } = Color.White; + public Color SelectedTabLineColor { get; set; } = Color.FromArgb(250, 36, 38); + public Color ControlBackgroundColor { get; set; } = Color.FromArgb(15, 15, 15); + + // Property to enable/disable line selection mode + public bool LineSelectionMode { get; set; } = false; + + public CrEaTiiOn_TabControl() + { + SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); + DoubleBuffered = true; + SizeMode = TabSizeMode.Normal; + ItemSize = new Size(150, 30); // Adjust tab size as needed + } + + protected override void OnPaint(PaintEventArgs e) + { + base.OnPaint(e); + + // Iterate through each tab to draw custom appearance + for (int i = 0; i < TabCount; i++) + { + Rectangle tabRect = GetTabRect(i); + bool isSelected = SelectedIndex == i; + + // Draw background color + using (SolidBrush brush = new SolidBrush(isSelected ? SelectedTabColor : TabColor)) + { + e.Graphics.FillRectangle(brush, tabRect); + } + + // Draw tab text + string tabText = TabPages[i].Text; + Color textColor = isSelected ? SelectedTabTextColor : TabTextColor; // Use TabTextColor for selected tab + using (SolidBrush brush = new SolidBrush(textColor)) + { + e.Graphics.DrawString(tabText, Font, brush, tabRect, new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }); + } + + // Draw line under the selected tab if LineSelectionMode is enabled + if (isSelected && LineSelectionMode) + { + using (Pen pen = new Pen(SelectedTabLineColor, 2)) // Use SelectedTabLineColor property + { + e.Graphics.DrawLine(pen, tabRect.Left, tabRect.Bottom - 2, tabRect.Right, tabRect.Bottom - 2); + } + } + } + } + + protected override void OnSelectedIndexChanged(EventArgs e) + { + base.OnSelectedIndexChanged(e); + Invalidate(); + } + + protected override void OnPaintBackground(PaintEventArgs e) + { + base.OnPaintBackground(e); + + // Fill control background with specified color + using (SolidBrush brush = new SolidBrush(ControlBackgroundColor)) + { + e.Graphics.FillRectangle(brush, ClientRectangle); + } + } + } +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_ModernTabPage.cs b/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_ModernTabPage.cs index c7afcb8..705ed1c 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_ModernTabPage.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_ModernTabPage.cs @@ -1,6 +1,6 @@ #region Imports -using System.Collections; +using System; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; @@ -13,186 +13,34 @@ namespace CBH.Controls public class CrEaTiiOn_ModernTabPage : TabControl { - private SmoothingMode _SmoothingType = SmoothingMode.HighSpeed; - public SmoothingMode SmoothingType - { - get => _SmoothingType; - set - { - _SmoothingType = value; - Invalidate(); - } - } - - private CompositingQuality _CompositingQualityType = CompositingQuality.HighSpeed; - public CompositingQuality CompositingQualityType - { - get => _CompositingQualityType; - set - { - _CompositingQualityType = value; - Invalidate(); - } - } - - private CompositingMode _CompositingType = CompositingMode.SourceOver; - public CompositingMode CompositingType - { - get => _CompositingType; - set - { - _CompositingType = value; - Invalidate(); - } - } - - private InterpolationMode _InterpolationType = InterpolationMode.HighQualityBicubic; - public InterpolationMode InterpolationType - { - get => _InterpolationType; - set - { - _InterpolationType = value; - Invalidate(); - } - } - - private StringAlignment _StringType = StringAlignment.Near; - public StringAlignment StringType - { - get => _StringType; - set - { - _StringType = value; - Invalidate(); - } - } - - private Color _FrameColor = Color.FromArgb(20, 20, 20); - public Color FrameColor - { - get => _FrameColor; - set - { - _FrameColor = value; - Invalidate(); - } - } - - private Color _PageColor = Color.FromArgb(20, 20, 20); - public Color PageColor - { - get => _PageColor; - set - { - _PageColor = value; - Invalidate(); - } - } - - private Color _ActiveForeColor = Color.FromArgb(250, 36, 38); - public Color ActiveForeColor - { - get => _ActiveForeColor; - set - { - _ActiveForeColor = value; - Invalidate(); - } - } - - private Color _NormalForeColor = Color.White; - public Color NormalForeColor - { - get => _NormalForeColor; - set - { - _NormalForeColor = value; - Invalidate(); - } - } - - private Color _ControlBackColor = Color.FromArgb(15, 15, 15); - public Color ControlBackColor - { - get => _ControlBackColor; - set - { - _ControlBackColor = value; - Invalidate(); - } - } - - private Color _LineColor = Color.FromArgb(250, 36, 38); - public Color LineColor - { - get => _LineColor; - set - { - _LineColor = value; - Invalidate(); - } - } - - private Color _ActiveTabColor = Color.FromArgb(15, 15, 15); - public Color ActiveTabColor - { - get => _ActiveTabColor; - set - { - _ActiveTabColor = value; - Invalidate(); - } - } - - private Color _TabColor = Color.FromArgb(20, 20, 20); - public Color TabColor - { - get => _TabColor; - set - { - _TabColor = value; - Invalidate(); - } - } - - private Color _ActiveLineTabColor = Color.FromArgb(250, 36, 38); - public Color ActiveLineTabColor - { - get => _ActiveLineTabColor; - set - { - _ActiveLineTabColor = value; - Invalidate(); - } - } - - private Color _LineTabColor = Color.FromArgb(20, 20, 20); - public Color LineTabColor - { - get => _LineTabColor; - set - { - _LineTabColor = value; - Invalidate(); - } - } + public SmoothingMode SmoothingType { get; set; } = SmoothingMode.HighSpeed; + public CompositingQuality CompositingQualityType { get; set; } = CompositingQuality.HighSpeed; + public CompositingMode CompositingType { get; set; } = CompositingMode.SourceOver; + public InterpolationMode InterpolationType { get; set; } = InterpolationMode.HighQualityBicubic; + public StringAlignment StringType { get; set; } = StringAlignment.Near; + public Color FrameColor { get; set; } = Color.FromArgb(20, 20, 20); + public Color PageColor { get; set; } = Color.FromArgb(20, 20, 20); + public Color ActiveForeColor { get; set; } = Color.FromArgb(250, 36, 38); + public Color NormalForeColor { get; set; } = Color.White; + public Color ControlBackColor { get; set; } = Color.FromArgb(15, 15, 15); + public Color LineColor { get; set; } = Color.FromArgb(250, 36, 38); + public Color ActiveTabColor { get; set; } = Color.FromArgb(15, 15, 15); + public Color TabColor { get; set; } = Color.FromArgb(20, 20, 20); + public Color ActiveLineTabColor { get; set; } = Color.FromArgb(250, 36, 38); + public Color LineTabColor { get; set; } = Color.FromArgb(20, 20, 20); public CrEaTiiOn_ModernTabPage() { SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.DoubleBuffer, true); - - DoubleBuffered = true; SizeMode = TabSizeMode.Fixed; - ItemSize = new(44, 135); + ItemSize = new Size(44, 135); DrawMode = TabDrawMode.OwnerDrawFixed; } protected override void CreateHandle() { base.CreateHandle(); - - base.DoubleBuffered = true; + DoubleBuffered = true; SizeMode = TabSizeMode.Fixed; Appearance = TabAppearance.Normal; Alignment = TabAlignment.Left; @@ -203,97 +51,81 @@ protected override void OnControlAdded(ControlEventArgs e) base.OnControlAdded(e); if (e.Control is CrEaTiiOn_ModernTabPage) { - IEnumerator Enumerator; - try + foreach (Control control in Controls) { - Enumerator = Controls.GetEnumerator(); - while (Enumerator.MoveNext()) + if (control is CrEaTiiOn_ModernTabPage tabPage) { - CrEaTiiOn_ModernTabPage Current = (CrEaTiiOn_ModernTabPage)Enumerator.Current; - Current = new CrEaTiiOn_ModernTabPage(); + tabPage.BackColor = FrameColor; } } - finally - { - e.Control.BackColor = FrameColor; - } } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - Bitmap B = new(Width, Height); - Graphics G = Graphics.FromImage(B); - - Graphics _Graphics = G; - - _Graphics.Clear(FrameColor); - _Graphics.SmoothingMode = SmoothingType; - _Graphics.CompositingQuality = CompositingQualityType; - _Graphics.CompositingMode = CompositingType; - - // Draw tab selector background - _Graphics.FillRectangle(new SolidBrush(ControlBackColor), new Rectangle(-5, 0, ItemSize.Height + 4, Height)); - // Draw vertical line at the end of the tab selector rectangle - _Graphics.DrawLine(new(LineColor), ItemSize.Height - 1, 0, ItemSize.Height - 1, Height); - - for (int TabIndex = 0; TabIndex <= TabCount - 1; TabIndex++) + using (Bitmap bitmap = new Bitmap(Width, Height)) { - if (TabIndex == SelectedIndex) + using (Graphics graphics = Graphics.FromImage(bitmap)) { - Rectangle TabRect = new(new Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 2), new Size(GetTabRect(TabIndex).Width + 3, GetTabRect(TabIndex).Height - 8)); + graphics.Clear(FrameColor); + graphics.SmoothingMode = SmoothingType; + graphics.CompositingQuality = CompositingQualityType; + graphics.CompositingMode = CompositingType; - // Draw background of the selected tab - _Graphics.FillRectangle(new SolidBrush(ActiveTabColor), TabRect.X, TabRect.Y, TabRect.Width - 4, TabRect.Height + 3); - // Draw a tab highlighter on the background of the selected tab - Rectangle TabHighlighter = new(new Point(GetTabRect(TabIndex).X - 2, GetTabRect(TabIndex).Location.Y - (TabIndex == 0 ? 1 : 1)), new Size(4, GetTabRect(TabIndex).Height - 7)); - _Graphics.FillRectangle(new SolidBrush(ActiveLineTabColor), TabHighlighter); - // Draw tab text - _Graphics.DrawString(TabPages[TabIndex].Text, new Font(Font.FontFamily, Font.Size, Font.Style), new SolidBrush(ActiveForeColor), new Rectangle(TabRect.Left + 40, TabRect.Top + 8, TabRect.Width - 40, TabRect.Height), new StringFormat { Alignment = StringType }); + // Draw tab selector background + graphics.FillRectangle(new SolidBrush(ControlBackColor), new Rectangle(-5, 0, ItemSize.Height + 4, Height)); + // Draw vertical line at the end of the tab selector rectangle + graphics.DrawLine(new Pen(LineColor), ItemSize.Height - 1, 0, ItemSize.Height - 1, Height); - if (ImageList != null) + for (int tabIndex = 0; tabIndex < TabCount; tabIndex++) { - int Index = TabPages[TabIndex].ImageIndex; - if (!(Index == -1)) + Rectangle tabRect = GetTabRect(tabIndex); + + if (tabIndex == SelectedIndex) { - _Graphics.DrawImage(ImageList.Images[TabPages[TabIndex].ImageIndex], TabRect.X + 9, TabRect.Y + 6, 24, 24); + Rectangle tabHighlighter = new Rectangle(tabRect.X - 2, tabRect.Y - (tabIndex == 0 ? 1 : 1), 4, tabRect.Height - 7); + + // Draw background of the selected tab + graphics.FillRectangle(new SolidBrush(ActiveTabColor), tabRect.X, tabRect.Y, tabRect.Width - 4, tabRect.Height + 3); + // Draw a tab highlighter on the background of the selected tab + graphics.FillRectangle(new SolidBrush(ActiveLineTabColor), tabHighlighter); + // Draw tab text + graphics.DrawString(TabPages[tabIndex].Text, Font, new SolidBrush(ActiveForeColor), new Rectangle(tabRect.Left + 40, tabRect.Top + 8, tabRect.Width - 40, tabRect.Height), new StringFormat { Alignment = StringType }); + + if (ImageList != null && TabPages[tabIndex].ImageIndex != -1) + { + graphics.DrawImage(ImageList.Images[TabPages[tabIndex].ImageIndex], tabRect.X + 9, tabRect.Y + 6, 24, 24); + } } - } - } - else - { - Rectangle TabRect = new(new Point(GetTabRect(TabIndex).Location.X - 2, GetTabRect(TabIndex).Location.Y - 2), new Size(GetTabRect(TabIndex).Width + 3, GetTabRect(TabIndex).Height - 8)); + else + { + Rectangle tabHighlighter = new Rectangle(tabRect.X - 2, tabRect.Y - (tabIndex == 0 ? 1 : 1), 4, tabRect.Height - 7); - // Draw background of the tab - _Graphics.FillRectangle(new SolidBrush(TabColor), TabRect.X, TabRect.Y, TabRect.Width - 4, TabRect.Height + 3); - // Draw a tab highlighter on the background of the tab - Rectangle TabHighlighter = new(new Point(GetTabRect(TabIndex).X - 2, GetTabRect(TabIndex).Location.Y - (TabIndex == 0 ? 1 : 1)), new Size(4, GetTabRect(TabIndex).Height - 7)); - _Graphics.FillRectangle(new SolidBrush(LineTabColor), TabHighlighter); + // Draw background of the tab + graphics.FillRectangle(new SolidBrush(TabColor), tabRect.X, tabRect.Y, tabRect.Width - 4, tabRect.Height + 3); + // Draw a tab highlighter on the background of the tab + graphics.FillRectangle(new SolidBrush(LineTabColor), tabHighlighter); - _Graphics.DrawString(TabPages[TabIndex].Text, new Font(Font.FontFamily, Font.Size, Font.Style), new SolidBrush(NormalForeColor), new Rectangle(TabRect.Left + 40, TabRect.Top + 8, TabRect.Width - 40, TabRect.Height), new StringFormat { Alignment = StringType }); + graphics.DrawString(TabPages[tabIndex].Text, Font, new SolidBrush(NormalForeColor), new Rectangle(tabRect.Left + 40, tabRect.Top + 8, tabRect.Width - 40, tabRect.Height), new StringFormat { Alignment = StringType }); - if (ImageList != null) - { - int Index = TabPages[TabIndex].ImageIndex; - if (!(Index == -1)) - { - _Graphics.DrawImage(ImageList.Images[TabPages[TabIndex].ImageIndex], TabRect.X + 9, TabRect.Y + 6, 24, 24); + if (ImageList != null && TabPages[tabIndex].ImageIndex != -1) + { + graphics.DrawImage(ImageList.Images[TabPages[tabIndex].ImageIndex], tabRect.X + 9, tabRect.Y + 6, 24, 24); + } } } - } + + e.Graphics.SmoothingMode = SmoothingMode.HighQuality; + e.Graphics.InterpolationMode = InterpolationType; + e.Graphics.CompositingQuality = CompositingQuality.HighQuality; + e.Graphics.DrawImage(bitmap, 0, 0); } - e.Graphics.SmoothingMode = SmoothingMode.HighQuality; - e.Graphics.InterpolationMode = InterpolationType; - e.Graphics.CompositingQuality = CompositingQuality.HighQuality; - e.Graphics.DrawImage((Image)B.Clone(), 0, 0); - G.Dispose(); - B.Dispose(); - foreach (System.Windows.Forms.TabPage Page in TabPages) + foreach (TabPage page in TabPages) { - Page.BackColor = PageColor; + page.BackColor = PageColor; } } } diff --git a/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_TabPage.cs b/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_TabPage.cs index 1e2c037..ead24ee 100644 --- a/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_TabPage.cs +++ b/CBH-WinForm-Theme-NET/Theme/Controls/TabPage/CrEaTiiOn_TabPage.cs @@ -1,14 +1,9 @@ -#region Imports - +using System; using System.Drawing; using System.Windows.Forms; -#endregion - namespace CBH.Controls { - #region CrEaTiiOn_TabPage - public class CrEaTiiOn_TabPage : TabControl { private Color _squareColor = Color.FromArgb(250, 36, 38); @@ -45,63 +40,62 @@ public bool ShowOuterBorders protected override void OnPaint(PaintEventArgs e) { - Bitmap bitmap = new Bitmap(Width, Height); - Graphics graphics = Graphics.FromImage(bitmap); - - try - { - SelectedTab.BackColor = Color.FromArgb(15, 15, 15); - } - catch { } + base.OnPaint(e); - graphics.Clear(Color.FromArgb(20, 20, 20)); + // Only repaint if there are tabs + if (TabCount == 0) + return; - for (int i = 0; i < TabCount; i++) + using (Bitmap bitmap = new Bitmap(Width, Height)) { - Rectangle tabRect = GetTabRect(i); - Rectangle tabRectWithBorders = new Rectangle(new Point(tabRect.Location.X - 2, tabRect.Location.Y - 2), new Size(tabRect.Width + 3, tabRect.Height - 1)); - Rectangle textRectangle = new Rectangle(tabRectWithBorders.Location.X + 20, tabRectWithBorders.Location.Y, tabRectWithBorders.Width - 20, tabRectWithBorders.Height); - - if (i == SelectedIndex) + using (Graphics graphics = Graphics.FromImage(bitmap)) { - graphics.FillRectangle(new SolidBrush(_squareColor), new Rectangle(tabRectWithBorders.Location, new Size(9, tabRectWithBorders.Height))); + graphics.Clear(Color.FromArgb(20, 20, 20)); - if (ImageList != null && ImageList.Images[TabPages[i].ImageIndex] != null) + for (int i = 0; i < TabCount; i++) { - graphics.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(textRectangle.Location.X + 8, textRectangle.Location.Y + 6)); + Rectangle tabRect = GetTabRect(i); + Rectangle tabRectWithBorders = new Rectangle(new Point(tabRect.Location.X - 2, tabRect.Location.Y - 2), new Size(tabRect.Width + 3, tabRect.Height - 1)); + Rectangle textRectangle = new Rectangle(tabRectWithBorders.Location.X + 20, tabRectWithBorders.Location.Y, tabRectWithBorders.Width - 20, tabRectWithBorders.Height); + + if (i == SelectedIndex) + { + graphics.FillRectangle(new SolidBrush(_squareColor), new Rectangle(tabRectWithBorders.Location, new Size(9, tabRectWithBorders.Height))); + + if (ImageList != null && ImageList.Images[TabPages[i].ImageIndex] != null) + { + graphics.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(textRectangle.Location.X + 8, textRectangle.Location.Y + 6)); + } + + graphics.DrawString(" " + TabPages[i].Text, Font, Brushes.White, textRectangle, new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near + }); + } + else + { + if (ImageList != null && ImageList.Images[TabPages[i].ImageIndex] != null) + { + graphics.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(textRectangle.Location.X + 8, textRectangle.Location.Y + 6)); + } + + graphics.DrawString(TabPages[i].Text, Font, Brushes.White, textRectangle, new StringFormat + { + LineAlignment = StringAlignment.Center, + Alignment = StringAlignment.Near + }); + } + + if (_showOuterBorders) + { + graphics.DrawRectangle(Pens.White, tabRectWithBorders); + } } - - graphics.DrawString(" " + TabPages[i].Text, Font, Brushes.White, textRectangle, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Near - }); - } - else - { - if (ImageList != null && ImageList.Images[TabPages[i].ImageIndex] != null) - { - graphics.DrawImage(ImageList.Images[TabPages[i].ImageIndex], new Point(textRectangle.Location.X + 8, textRectangle.Location.Y + 6)); - } - - graphics.DrawString(TabPages[i].Text, Font, Brushes.White, textRectangle, new StringFormat - { - LineAlignment = StringAlignment.Center, - Alignment = StringAlignment.Near - }); } - if (_showOuterBorders) - { - graphics.DrawRectangle(Pens.White, tabRectWithBorders); - } + e.Graphics.DrawImage(bitmap, 0, 0); } - - e.Graphics.DrawImage(bitmap, 0, 0); - graphics.Dispose(); - bitmap.Dispose(); } } - - #endregion } \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/Form/CrEaTiiOn_Form.cs b/CBH-WinForm-Theme-NET/Theme/Form/CrEaTiiOn_Form.cs new file mode 100644 index 0000000..928ed54 --- /dev/null +++ b/CBH-WinForm-Theme-NET/Theme/Form/CrEaTiiOn_Form.cs @@ -0,0 +1,165 @@ +using Microsoft.Win32; +using System; +using System.ComponentModel; +using System.Drawing; +using System.Runtime.InteropServices; +using System.Windows.Forms; + +namespace CBH_WinForm_Theme_Library_NET +{ + public class CrEaTiiOn_Form : Form + { + #region SYSTEM THEME STATUS + private class SystemTheme + { + public static int Status() // 0 : dark theme / 1 : light theme / -1 : AppsUseLightTheme could not be found + { + string keyName = @"HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize"; + try { return (int)Registry.GetValue(keyName, "AppsUseLightTheme", -1); } + catch { return -1; } + } + } + #endregion + + #region Properties + private SystemMode systemMode; + + [Category("Misc")] + public SystemMode SystemAdaptiveMode + { + get { return systemMode; } + set + { + systemMode = value; + ApplyTheme(); + } + } + + public enum SystemMode + { + Dark, + Light, + System + } + #endregion + + #region Constructor + public CrEaTiiOn_Form() + { + // Set the initial theme based on the system theme + SystemAdaptiveMode = SystemMode.System; + + // Subscribe to the system theme change event + SystemEvents.UserPreferenceChanged += SystemEvents_UserPreferenceChanged; + + // Check if the form is in design mode before applying changes + if (!DesignMode) + { + // Allow the form to be dragged from the title bar only during runtime + MouseDown += Form_MouseDown; + } + } + #endregion + + #region Theme Methods + private void ApplyTheme() + { + switch (SystemAdaptiveMode) + { + case SystemMode.Dark: + SetDarkMode(true); + break; + + case SystemMode.Light: + SetDarkMode(false); + break; + + case SystemMode.System: + SetDarkMode(SystemTheme.Status() == 0); + break; + } + } + + private void SetDarkMode(bool enable) + { + DarkTitle.ChangeTitleBarToDark(Handle, enable); + + if (enable) + { + BackColor = Color.FromArgb(32, 32, 32); + ForeColor = Color.FromArgb(255, 255, 255); + } + else + { + BackColor = Color.FromArgb(255, 255, 255); + ForeColor = Color.FromArgb(0, 0, 0); + } + + // Refresh the form to apply changes + Invalidate(); + } + #endregion + + #region Event Handlers + private void SystemEvents_UserPreferenceChanged(object sender, UserPreferenceChangedEventArgs e) + { + if (e.Category == UserPreferenceCategory.General) + { + // System theme setting changed, update the form color + ApplyTheme(); + } + } + + // Event handler to handle form dragging during runtime + private void Form_MouseDown(object sender, MouseEventArgs e) + { + if (e.Button == MouseButtons.Left) + { + ReleaseCapture(); + SendMessage(Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0); + } + } + #endregion + + #region PInvoke + private const int WM_NCLBUTTONDOWN = 0xA1; + private const int HT_CAPTION = 0x2; + + [DllImport("user32.dll")] + private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam); + + [DllImport("user32.dll")] + private static extern bool ReleaseCapture(); + #endregion + + #region Windows Default Location Handling + protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) + { + // If StartPosition is set to WindowsDefaultLocation and not in design mode, adjust the location + if (StartPosition == FormStartPosition.WindowsDefaultLocation && !DesignMode) + { + base.SetBoundsCore(x, y, width, height, specified); + CenterToScreen(); + } + else + { + base.SetBoundsCore(x, y, width, height, specified); + } + } + #endregion + } + + internal static class DarkTitle + { + [DllImport("DwmApi.dll")] + private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize); + + internal static void ChangeTitleBarToDark(IntPtr handle, bool enable) + { + var attributes = enable ? new[] { 1 } : new[] { 0 }; + + DwmSetWindowAttribute(handle, 19, attributes, 4); + DwmSetWindowAttribute(handle, 20, attributes, 4); + } + } +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Helpers.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Helpers.cs index e4d6611..84afb38 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Helpers.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Helpers.cs @@ -35,80 +35,6 @@ public static void MakeTransparent(Control control, Graphics g) } #endregion - #region Draw Helpers - public static class DrawHelper - { - public static GraphicsPath CreateRoundRect(float x, float y, float width, float height, float radius) - { - GraphicsPath gp = new GraphicsPath(); - gp.AddLine(x + radius, y, x + width - (radius * 2), y); - gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); - - gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2)); - gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90); - - gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); - gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); - - gp.AddLine(x, y + height - (radius * 2), x, y + radius); - gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); - - gp.CloseFigure(); - return gp; - } - public static GraphicsPath CreateUpRoundRect(float x, float y, float width, float height, float radius) - { - GraphicsPath gp = new GraphicsPath(); - - gp.AddLine(x + radius, y, x + width - (radius * 2), y); - gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); - - gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2) + 1); - gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, 2, 0, 90); - - gp.AddLine(x + width, y + height, x + radius, y + height); - gp.AddArc(x, y + height - (radius * 2) + 1, radius * 2, 1, 90, 90); - - gp.AddLine(x, y + height, x, y + radius); - gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); - - gp.CloseFigure(); - return gp; - } - public static GraphicsPath CreateLeftRoundRect(float x, float y, float width, float height, float radius) - { - GraphicsPath gp = new GraphicsPath(); - gp.AddLine(x + radius, y, x + width - (radius * 2), y); - gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90); - - gp.AddLine(x + width, y + 0, x + width, y + height); - gp.AddArc(x + width - (radius * 2), y + height - (1), radius * 2, 1, 0, 90); - - gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height); - gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90); - - gp.AddLine(x, y + height - (radius * 2), x, y + radius); - gp.AddArc(x, y, radius * 2, radius * 2, 180, 90); - - gp.CloseFigure(); - return gp; - } - public static Color BlendColor(Color backgroundColor, Color frontColor) - { - double ratio = 0 / 255d; - double invRatio = 1d - ratio; - int r = (int)((backgroundColor.R * invRatio) + (frontColor.R * ratio)); - int g = (int)((backgroundColor.G * invRatio) + (frontColor.G * ratio)); - int b = (int)((backgroundColor.B * invRatio) + (frontColor.B * ratio)); - return Color.FromArgb(r, g, b); - } - - public static Color BackColor = ColorTranslator.FromHtml("#dadcdf");//bcbfc4 - public static Color DarkBackColor = ColorTranslator.FromHtml("#90949a"); - public static Color LightBackColor = ColorTranslator.FromHtml("#F5F5F5"); - } - #endregion - #region String Alignment Helpers public static class StringAlign { @@ -351,7 +277,6 @@ public List GetLines(Graphics g, string str, Font font, int maxLength) #region External Helpers static class Drawing { - public static GraphicsPath RoundRect(Rectangle rect, int slope) { GraphicsPath gp = new GraphicsPath(); @@ -368,7 +293,6 @@ public static GraphicsPath RoundRect(Rectangle rect, int slope) public static class Prevent { - public static void Prevents(Graphics g, int w, int h) { string txt = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("VGhlbWUlMjBjcmVhdGVkJTIwYnklMjBIYXdrJTIwSEY=")).Replace("%20", " "); @@ -383,7 +307,6 @@ public static void Prevents(Graphics g, int w, int h) [ToolboxItem(false)] public class ASCThemeContainer : ContainerControl { - private int moveHeight = 38; private bool formCanMove = false; private int mouseX; diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Theme.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Theme.cs index c23ad97..855cec8 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Theme.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/Theme.cs @@ -5,7 +5,6 @@ namespace CBH_Ultimate_Theme_Library { - #region Theme Base #region Imports @@ -2460,6 +2459,4 @@ protected override void PaintHook() G.DrawIcon(Parent.FindForm().Icon, new Rectangle(9, 18, 25, 25)); } } - -} - +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/ThemeContainer.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/ThemeContainer.cs index 64ac740..0310acf 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/ThemeContainer.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Helpers/ThemeContainer.cs @@ -9,11 +9,9 @@ namespace CBH_Ultimate_Theme_Library { - [ToolboxItem(false)] public class ASCThemeContainer : ContainerControl { - private int moveHeight = 38; private bool formCanMove = false; private int mouseX; @@ -159,7 +157,5 @@ protected override void OnMouseUp(System.Windows.Forms.MouseEventArgs e) base.OnMouseUp(e); formCanMove = false; } - } - } \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Shadow Controls/CrEaTiiOn_Shadow_Controls.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Shadow Controls/CrEaTiiOn_Shadow_Controls.cs index 0465184..fd19b63 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Shadow Controls/CrEaTiiOn_Shadow_Controls.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Shadow Controls/CrEaTiiOn_Shadow_Controls.cs @@ -13,8 +13,9 @@ namespace CBH.Shadow.Controls { - //These were developed by Hawk & LordVirus (TheOnlyLordVirus) - //EternalMoz has cleaned these controls up and has made a few small changes / fixes + //These were developed by Hawk & LordVirus (TheOnlyLordVirus). + //EternalMoz has cleaned these controls up and has made a few small changes / fixes. + #region Controls class CrEaTiiOn_Shadow_Button : ThemeControl154 { diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyButton.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyButton.cs index 607208d..66fb5c3 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyButton.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyButton.cs @@ -1,8 +1,10 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -18,10 +20,11 @@ public sealed class CrEaTiiOn_Ultimate_FancyButton : Button public int BorderRadius { get => _borderRadius; set { if (value <= this.Height) _borderRadius = value; else BorderRadius = this.Height; Invalidate(); } } [Category("CrEaTiiOn")] public Color BorderColor { get => _borderColor; set { _borderColor = value; Invalidate(); } } - [Category("CrEaTiiOn")] - public Color BackgroundColor { get => BackColor; set => BackColor = value; } - [Category("CrEaTiiOn")] - public Color TextColor { get => ForeColor; set => ForeColor = value; } + + // Override BackColor and ForeColor to ensure proper handling + public override Color BackColor { get => base.BackColor; set { base.BackColor = value; Invalidate(); } } + public override Color ForeColor { get => base.ForeColor; set { base.ForeColor = value; Invalidate(); } } + [Category("CrEaTiiOn")] public Color HoverOverColor { get => FlatAppearance.MouseOverBackColor; set { FlatAppearance.MouseOverBackColor = value; Invalidate(); } } [Category("CrEaTiiOn")] @@ -37,13 +40,13 @@ public CrEaTiiOn_Ultimate_FancyButton() FlatAppearance.MouseOverBackColor = Color.FromArgb(15, 15, 15); FlatAppearance.MouseDownBackColor = Color.FromArgb(25, 25, 25); Resize += OnResize; + SetStyle(ControlStyles.ResizeRedraw, true); // Enable redraw on resize } private void OnResize(object sender, EventArgs e) { if (_borderRadius > Height) BorderRadius = Height; - } private GraphicsPath GetFigurePath(RectangleF rect, float radius) @@ -93,17 +96,5 @@ protected override void OnPaint(PaintEventArgs pevent) } } } - - protected override void OnHandleCreated(EventArgs e) - { - base.OnHandleCreated(e); - Parent.BackColorChanged += ParentOnBackColorChanged; - } - - private void ParentOnBackColorChanged(object sender, EventArgs e) - { - if (DesignMode) - Invalidate(); - } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyComboBox.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyComboBox.cs index 32dd219..444b382 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyComboBox.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_FancyComboBox.cs @@ -1,9 +1,10 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; -using System.Drawing.Design; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -33,65 +34,16 @@ public sealed class CrEaTiiOn_Ultimate_FancyComboBox : UserControl public Color BorderColor { get => _borderColor; set { _borderColor = value; base.BackColor = _borderColor; } } [Category("CrEaTiiOn")] public int BorderSize { get => _borderSize; set { _borderSize = value; Padding = new Padding(_borderSize); AdjustComboBoxDimensions(); } } - [Category("CrEaTiiOn")] - public override Color ForeColor { get => base.ForeColor; set { base.ForeColor = value; _labelString.ForeColor = value; } } - [Category("CrEaTiiOn")] - public override Font Font { get => base.Font; set { base.Font = value; _labelString.Font = value; _comboList.Font = value; } } - [Category("CrEaTiiOn")] - public string String { get => _labelString.Text; set => _labelString.Text = value; } - [Category("CrEaTiiOn")] - public ComboBoxStyle DropDownStyle { get => _comboList.DropDownStyle; set { if (_comboList.DropDownStyle != ComboBoxStyle.Simple) _comboList.DropDownStyle = value; } } - - [Category("CrEaTiiOn")] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - [Localizable(true)] - [MergableProperty(false)] - public ComboBox.ObjectCollection Items => _comboList.Items; - - [Category("CrEaTiiOn")] - [AttributeProvider(typeof(IListSource))] - [DefaultValue(null)] - public object DataSource { get => _comboList.DataSource; set => _comboList.DataSource = value; } - [Category("CrEaTiiOn")] - [Browsable(true)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)] - [Editor("System.Windows.Forms.Design.ListControlStringCollectionEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - [EditorBrowsable(EditorBrowsableState.Always)] - [Localizable(true)] - public AutoCompleteStringCollection AutoCompleteCustomSource { get => _comboList.AutoCompleteCustomSource; set => _comboList.AutoCompleteCustomSource = value; } - [Category("CrEaTiiOn")] - [Browsable(true)] - [DefaultValue(AutoCompleteSource.None)] - [EditorBrowsable(EditorBrowsableState.Always)] - public AutoCompleteSource AutoCompleteSource { get => _comboList.AutoCompleteSource; set => _comboList.AutoCompleteSource = value; } - [Category("CrEaTiiOn")] - [Browsable(true)] - [DefaultValue(AutoCompleteMode.None)] - [EditorBrowsable(EditorBrowsableState.Always)] - public AutoCompleteMode AutoCompleteMode { get => _comboList.AutoCompleteMode; set => _comboList.AutoCompleteMode = value; } - [Category("CrEaTiiOn")] - [Bindable(true)] - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public object SelectedItem { get => _comboList.SelectedItem; set => _comboList.SelectedItem = value; } - [Category("CrEaTiiOn")] - [Browsable(false)] - [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] - public int SelectedIndex { get => _comboList.SelectedIndex; set => _comboList.SelectedIndex = value; } - [Category("CrEaTiiOn")] - [DefaultValue("")] - [Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - [TypeConverter("System.Windows.Forms.Design.DataMemberFieldConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")] - public string DisplayMember { get => _comboList.DisplayMember; set => _comboList.DisplayMember = value; } - [Category("CrEaTiiOn")] - [DefaultValue("")] - [Editor("System.Windows.Forms.Design.DataMemberFieldEditor, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))] - public string ValueMember { get => _comboList.ValueMember; set => _comboList.ValueMember = value; } public event EventHandler OnSelectedIndexChanged; public CrEaTiiOn_Ultimate_FancyComboBox() + { + InitializeComponents(); + AdjustComboBoxDimensions(); + } + + private void InitializeComponents() { _comboList = new ComboBox(); _labelString = new Label(); @@ -99,7 +51,7 @@ public CrEaTiiOn_Ultimate_FancyComboBox() SuspendLayout(); _comboList.BackColor = ListBackColor; - _comboList.Font = new Font(Font.Name, 10f); + _comboList.Font = Font; _comboList.ForeColor = ListForeColor; _comboList.SelectedIndexChanged += ComboBox_SelectedIndexChanged; _comboList.TextChanged += ComboBox_StringChanged; @@ -118,7 +70,7 @@ public CrEaTiiOn_Ultimate_FancyComboBox() _labelString.BackColor = BackColor; _labelString.TextAlign = ContentAlignment.MiddleLeft; _labelString.Padding = new Padding(8, 0, 0, 0); - _labelString.Font = new Font(Font.Name, 10f); + _labelString.Font = Font; _labelString.Click += Surface_Click; _labelString.MouseEnter += Surface_MouseEnter; _labelString.MouseLeave += Surface_MouseLeave; @@ -132,7 +84,6 @@ public CrEaTiiOn_Ultimate_FancyComboBox() Padding = new Padding(BorderSize); base.BackColor = BorderColor; ResumeLayout(); - AdjustComboBoxDimensions(); } private void Surface_MouseLeave(object sender, EventArgs e) @@ -189,8 +140,7 @@ private void ComboBox_StringChanged(object sender, EventArgs e) private void ComboBox_SelectedIndexChanged(object sender, EventArgs e) { - if (OnSelectedIndexChanged != null) - OnSelectedIndexChanged.Invoke(sender, e); + OnSelectedIndexChanged?.Invoke(sender, e); _labelString.Text = _comboList.Text; } @@ -200,4 +150,4 @@ protected override void OnResize(EventArgs e) AdjustComboBoxDimensions(); } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientButton.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientButton.cs index 0464489..0198200 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientButton.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientButton.cs @@ -1,8 +1,10 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -40,25 +42,13 @@ public CrEaTiiOn_Ultimate_GradientButton() FlatAppearance.MouseOverBackColor = Color.FromArgb(25, 25, 25); FlatAppearance.MouseDownBackColor = Color.FromArgb(15, 15, 15); Resize += OnResize; + SetStyle(ControlStyles.ResizeRedraw, true); // Ensure control redraws when resized } private void OnResize(object sender, EventArgs e) { if (_borderRadius > Height) BorderRadius = Height; - - } - - private GraphicsPath GetFigurePath(RectangleF rect, float radius) - { - var path = new GraphicsPath(); - path.StartFigure(); - path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); - path.AddArc(rect.Width - radius, rect.Y, radius, radius, 270, 90); - path.AddArc(rect.Width - radius, rect.Height - radius, radius, radius, 0, 90); - path.AddArc(rect.X, rect.Height - radius, radius, radius, 90, 90); - path.CloseFigure(); - return path; } protected override void OnPaint(PaintEventArgs pevent) @@ -69,35 +59,31 @@ protected override void OnPaint(PaintEventArgs pevent) var rectSurface = new RectangleF(0, 0, Width, Height); var rectBorder = new RectangleF(1, 1, Width - 0.8f, Height - 1); - - if (BorderRadius > 2) + using (var pathSurface = GetFigurePath(rectSurface, BorderRadius)) + using (var pathBorder = GetFigurePath(rectBorder, BorderRadius - 1)) + using (var penSurface = new Pen(Parent.BackColor, 2)) + using (var penBorder = new Pen(new LinearGradientBrush(new PointF(0, Height / 2f), new PointF(Width, Height / 2f), _gradientColorPrimary, _gradientColorSecondary), BorderSize)) { - using (var pathSurface = GetFigurePath(rectSurface, BorderRadius)) - using (var pathBorder = GetFigurePath(rectBorder, BorderRadius - 1)) - using (var penSurface = new Pen(Parent.BackColor, 2)) - using (var penBorder = new Pen(new LinearGradientBrush(new PointF(0, Height / 2f), new PointF(Width, Height / 2f), _gradientColorPrimary, _gradientColorSecondary), BorderSize)) - { - penBorder.Alignment = PenAlignment.Inset; - Region = new Region(pathSurface); - pevent.Graphics.DrawPath(penSurface, pathSurface); - if (BorderSize >= 1) - pevent.Graphics.DrawPath(penBorder, pathBorder); - } - } - else - { - Region = new Region(rectSurface); + penBorder.Alignment = PenAlignment.Inset; + Region = new Region(pathSurface); + pevent.Graphics.DrawPath(penSurface, pathSurface); if (BorderSize >= 1) - { - using (var penBorder = new Pen(new LinearGradientBrush(new PointF(0, Height / 2f), new PointF(Width, Height / 2f), _gradientColorPrimary, _gradientColorSecondary), BorderSize)) - { - penBorder.Alignment = PenAlignment.Inset; - pevent.Graphics.DrawRectangle(penBorder, 0, 0, Width - 1, Height - 1); - } - } + pevent.Graphics.DrawPath(penBorder, pathBorder); } } + private GraphicsPath GetFigurePath(RectangleF rect, float radius) + { + var path = new GraphicsPath(); + path.StartFigure(); + path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); + path.AddArc(rect.Width - radius, rect.Y, radius, radius, 270, 90); + path.AddArc(rect.Width - radius, rect.Height - radius, radius, radius, 0, 90); + path.AddArc(rect.X, rect.Height - radius, radius, radius, 90, 90); + path.CloseFigure(); + return path; + } + protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); @@ -110,4 +96,4 @@ private void ParentOnBackColorChanged(object sender, EventArgs e) Invalidate(); } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientLabel.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientLabel.cs index 089141e..5384023 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientLabel.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientLabel.cs @@ -1,37 +1,54 @@ -using System.ComponentModel; +#region Imports +using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { public class CrEaTiiOn_Ultimate_GradientLabel : Label { - - private Color _FirstColor = Color.FromArgb(250, 36, 38); - private Color _SecondColor = Color.FromArgb(75, 75, 75); + private Color _firstColor = Color.FromArgb(250, 36, 38); + private Color _secondColor = Color.FromArgb(75, 75, 75); [Category("CrEaTiiOn")] - public string String { get { return Text; } set { Text = value; } } + public string CustomText { get { return Text; } set { Text = value; } } + [Category("CrEaTiiOn")] - public override Font Font { get => base.Font; set { base.Font = value; base.Font = value; } } + public override Font Font { get => base.Font; set { base.Font = value; } } [Category("CrEaTiiOn")] - public Color FirstColor { get => _FirstColor; set { _FirstColor = value; Invalidate(); } } + public Color FirstColor + { + get => _firstColor; + set { _firstColor = value; Invalidate(); } + } [Category("CrEaTiiOn")] - public Color SecondColor { get => _SecondColor; set { _SecondColor = value; Invalidate(); } } + public Color SecondColor + { + get => _secondColor; + set { _secondColor = value; Invalidate(); } + } public CrEaTiiOn_Ultimate_GradientLabel() { - + // Double buffer for smoother drawing + SetStyle(ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.DoubleBuffer, true); + UpdateStyles(); } protected override void OnPaint(PaintEventArgs e) { - LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 5), _FirstColor, _SecondColor, LinearGradientMode.Horizontal); - e.Graphics.DrawString(String, Font, brush, 0, 0); + base.OnPaint(e); + + // Create a linear gradient brush + using (LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 5), _firstColor, _secondColor, LinearGradientMode.Horizontal)) + { + // Draw string using gradient brush + e.Graphics.DrawString(CustomText, Font, brush, 0, 0); + } } - } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientNumericUpDown.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientNumericUpDown.cs index 47802e6..f10117a 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientNumericUpDown.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientNumericUpDown.cs @@ -1,9 +1,11 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -143,4 +145,4 @@ protected override void OnPaint(PaintEventArgs e) bitmap.Dispose(); } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientTextBox.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientTextBox.cs index 3c19a17..62d7d1d 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientTextBox.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientTextBox.cs @@ -1,8 +1,10 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -24,12 +26,10 @@ public partial class CrEaTiiOn_Ultimate_GradientTextBox : UserControl public CrEaTiiOn_Ultimate_GradientTextBox() { InitializeComponent(); - } public event EventHandler TextHasChanged; - [Category("CrEaTiiOn")] public Color GradientColorPrimary { get => _gradientColorPrimary; set { _gradientColorPrimary = value; Invalidate(); } } [Category("CrEaTiiOn")] @@ -43,7 +43,7 @@ public CrEaTiiOn_Ultimate_GradientTextBox() [Category("CrEaTiiOn")] public bool Multiline { get => textBox1.Multiline; set => textBox1.Multiline = value; } [Category("CrEaTiiOn")] - public string String { get { if (_isPlaceholder) return string.Empty; return textBox1.Text; } set { textBox1.Text = value; SetPlaceHolder(); } } + public string TextContent { get { if (_isPlaceholder) return string.Empty; return textBox1.Text; } set { textBox1.Text = value; SetPlaceholder(); } } [Category("CrEaTiiOn")] public override Color BackColor { get => base.BackColor; set { base.BackColor = value; textBox1.BackColor = value; } } [Category("CrEaTiiOn")] @@ -57,81 +57,27 @@ public CrEaTiiOn_Ultimate_GradientTextBox() [Category("CrEaTiiOn")] public Color PlaceholderColor { get => _placeholderColor; set { _placeholderColor = value; if (_isPlaceholder) textBox1.ForeColor = value; } } [Category("CrEaTiiOn")] - public string PlaceholderText { get => _placeholderText; set { _placeholderText = value; textBox1.Text = String.Empty; SetPlaceHolder(); } } + public string PlaceholderText { get => _placeholderText; set { _placeholderText = value; textBox1.Text = String.Empty; SetPlaceholder(); } } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); Graphics graphics = e.Graphics; - if (_borderRadius > 1) + using (GraphicsPath path = GetFigurePath(ClientRectangle, _borderRadius)) + using (Pen penBorder = new Pen(new LinearGradientBrush(new PointF(0, Height / 2f), new PointF(Width, Height / 2f), _gradientColorPrimary, _gradientColorSecondary), _borderSize)) { - var rectBorderSmooth = ClientRectangle; - var rectBorder = Rectangle.Inflate(rectBorderSmooth, -_borderSize, -_borderSize); - int smoothSize = _borderSize > 0 ? _borderSize : 1; - - using (GraphicsPath pathBorderSmooth = GetFigurePath(rectBorderSmooth, _borderRadius)) - using (GraphicsPath pathBorder = GetFigurePath(rectBorder, _borderRadius - _borderSize)) - using (Pen penBorderSmooth = new Pen(Parent.BackColor, smoothSize)) - using (Pen penBorder = new Pen(new LinearGradientBrush(new PointF(0, Height / 2f), new PointF(Width, Height / 2f), _gradientColorPrimary, _gradientColorSecondary), _borderSize)) - { - Region = new Region(pathBorderSmooth); - if (_borderSize > 15) SetTextBoxRoundedRegion(); - graphics.SmoothingMode = SmoothingMode.AntiAlias; - penBorder.Alignment = PenAlignment.Center; - - if (_isFocused) - penBorder.Color = _borderFocusColor; - - if (_underlinedStyle) - { - graphics.DrawPath(penBorderSmooth, pathBorderSmooth); - graphics.SmoothingMode = SmoothingMode.None; - graphics.DrawLine(penBorder, 0, Height - 1, Width, Height - 1); - } - else - { - graphics.DrawPath(penBorderSmooth, pathBorderSmooth); - graphics.DrawPath(penBorder, pathBorder); - } - } - } - else - { - using (Pen penBorder = new Pen(new LinearGradientBrush(new PointF(0, Height / 2f), new PointF(Width, Height / 2f), _gradientColorPrimary, _gradientColorSecondary), _borderSize)) - { - Region = new Region(ClientRectangle); - penBorder.Alignment = PenAlignment.Inset; - - if (_isFocused) - penBorder.Color = _borderFocusColor; - - if (_underlinedStyle) - graphics.DrawLine(penBorder, 0, Height - 1, Width, Height - 1); - else - graphics.DrawRectangle(penBorder, 0, 0, Width - 0.5f, Height - 0.5f); - } - } - } - - private void SetTextBoxRoundedRegion() - { - GraphicsPath pathText; + Region = new Region(path); + penBorder.Alignment = PenAlignment.Center; - pathText = GetFigurePath(textBox1.ClientRectangle, Multiline ? _borderRadius - _borderSize : _borderRadius * 2); - textBox1.Region = new Region(pathText); - } + if (_isFocused) + penBorder.Color = _borderFocusColor; - private GraphicsPath GetFigurePath(RectangleF rect, float radius) - { - var path = new GraphicsPath(); - path.StartFigure(); - path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); - path.AddArc(rect.Width - radius, rect.Y, radius, radius, 270, 90); - path.AddArc(rect.Width - radius, rect.Height - radius, radius, radius, 0, 90); - path.AddArc(rect.X, rect.Height - radius, radius, radius, 90, 90); - path.CloseFigure(); - return path; + if (_underlinedStyle) + graphics.DrawLine(penBorder, 0, Height - 1, Width, Height - 1); + else + graphics.DrawPath(penBorder, path); + } } protected override void OnResize(EventArgs e) @@ -159,7 +105,7 @@ private void UpdateControlHeight() } } - private void SetPlaceHolder() + private void SetPlaceholder() { if (string.IsNullOrWhiteSpace(textBox1.Text) && _placeholderText != String.Empty) { @@ -168,11 +114,10 @@ private void SetPlaceHolder() textBox1.ForeColor = _placeholderColor; if (_isPasswordChar) textBox1.UseSystemPasswordChar = false; - } } - private void RemovePlaceHolder() + private void RemovePlaceholder() { if (_isPlaceholder && _placeholderText != String.Empty) { @@ -181,7 +126,6 @@ private void RemovePlaceHolder() textBox1.ForeColor = ForeColor; if (_isPasswordChar) textBox1.UseSystemPasswordChar = true; - } } @@ -214,14 +158,26 @@ private void textBox1_Enter(object sender, EventArgs e) { _isFocused = true; Invalidate(); - RemovePlaceHolder(); + RemovePlaceholder(); } private void textBox1_Leave(object sender, EventArgs e) { _isFocused = false; Invalidate(); - SetPlaceHolder(); + SetPlaceholder(); + } + + private GraphicsPath GetFigurePath(RectangleF rect, float radius) + { + var path = new GraphicsPath(); + path.StartFigure(); + path.AddArc(rect.X, rect.Y, radius, radius, 180, 90); + path.AddArc(rect.Width - radius, rect.Y, radius, radius, 270, 90); + path.AddArc(rect.Width - radius, rect.Height - radius, radius, radius, 0, 90); + path.AddArc(rect.X, rect.Height - radius, radius, radius, 90, 90); + path.CloseFigure(); + return path; } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientToggleButton.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientToggleButton.cs index 27c9892..2a416dd 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientToggleButton.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GradientToggleButton.cs @@ -1,13 +1,15 @@ -using System.ComponentModel; +#region Imports +using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { public sealed class CrEaTiiOn_Ultimate_GradientToggleButton : CheckBox { - + // Fields for gradient colors and toggle properties private Color _gradientColorPrimary = Color.FromArgb(250, 36, 38); private Color _gradientColorSecondary = Color.Black; private Color _onToggleColor = Color.Black; @@ -15,6 +17,7 @@ public sealed class CrEaTiiOn_Ultimate_GradientToggleButton : CheckBox private Color _offToggleColor = Color.White; private bool _solidStyle = true; + // Properties for customization [Category("CrEaTiiOn")] public Color GradientColorPrimary { get => _gradientColorPrimary; set { _gradientColorPrimary = value; Invalidate(); } } [Category("CrEaTiiOn")] @@ -40,6 +43,7 @@ public CrEaTiiOn_Ultimate_GradientToggleButton() MinimumSize = new Size(45, 22); } + // Get the path for the toggle button figure private GraphicsPath GetFigurePath() { var arcSize = Height - 1; @@ -55,12 +59,14 @@ private GraphicsPath GetFigurePath() return path; } + // Custom painting logic protected override void OnPaint(PaintEventArgs pevent) { var toggleSize = Height - 5; pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias; pevent.Graphics.Clear(BackColor); + // Draw toggle button based on Checked state if (Checked) { if (_solidStyle) @@ -76,8 +82,9 @@ protected override void OnPaint(PaintEventArgs pevent) pevent.Graphics.FillPath(new SolidBrush(_offBackColor), GetFigurePath()); else pevent.Graphics.DrawPath(new Pen(_offBackColor), GetFigurePath()); + pevent.Graphics.FillEllipse(new SolidBrush(_offToggleColor), new Rectangle(2, 2, toggleSize, toggleSize)); } } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GroupBox.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GroupBox.cs index 1d0c4ca..7cf2540 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GroupBox.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_GroupBox.cs @@ -1,7 +1,9 @@ -using System.ComponentModel; +#region Imports +using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -45,21 +47,34 @@ private GraphicsPath GetFigurePath(RectangleF rect, float radius) protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - GroupBoxRenderer.DrawParentBackground(e.Graphics, ClientRectangle, this); - var rect = ClientRectangle; + + // Draw control background using (var path = GetFigurePath(ClientRectangle, Radius)) { e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; - rect = new Rectangle(0, 0, rect.Width, _titleFont.Height + Padding.Bottom + Padding.Top); - if (_backgroundColor != Color.Transparent) using (var brush = new SolidBrush(_backgroundColor)) e.Graphics.FillPath(brush, path); - var clip = e.Graphics.ClipBounds; - e.Graphics.SetClip(rect); - using (var brush = new SolidBrush(_titleBackColor)) e.Graphics.FillPath(brush, path); - //using (var pen = new Pen(_titleBackColor, 1)) e.Graphics.DrawPath(pen, path); - TextRenderer.DrawText(e.Graphics, Text, _titleFont, rect, _titleForeColor); - e.Graphics.SetClip(clip); - // using (var pen = new Pen(_titleBackColor, 1)) e.Graphics.DrawPath(pen, path); + + // Fill background + if (_backgroundColor != Color.Transparent) + { + using (var brush = new SolidBrush(_backgroundColor)) + { + e.Graphics.FillPath(brush, path); + } + } + + // Draw title background + var titleRect = new Rectangle(0, 0, ClientRectangle.Width, _titleFont.Height + Padding.Bottom + Padding.Top); + using (var titlePath = GetFigurePath(titleRect, Radius)) + { + using (var titleBrush = new SolidBrush(_titleBackColor)) + { + e.Graphics.FillPath(titleBrush, titlePath); + } + } + + // Draw title text + TextRenderer.DrawText(e.Graphics, Text, _titleFont, titleRect, _titleForeColor); } } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_NumericUpDown.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_NumericUpDown.cs index 547119e..714fd56 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_NumericUpDown.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_NumericUpDown.cs @@ -1,9 +1,11 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -140,4 +142,4 @@ protected override void OnPaint(PaintEventArgs e) bitmap.Dispose(); } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_PictureBox.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_PictureBox.cs index 0c24354..2022410 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_PictureBox.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_PictureBox.cs @@ -1,8 +1,10 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -19,21 +21,45 @@ public CrEaTiiOn_Ultimate_PictureBox() { Size = new Size(100, 100); SizeMode = PictureBoxSizeMode.StretchImage; - + SetStyle(ControlStyles.ResizeRedraw, true); // Enable redraw on resize } [Category("CrEaTiiOn")] - public int BorderSize { get => _borderSize; set { _borderSize = value; Invalidate(); } } + public int BorderSize + { + get => _borderSize; + set { _borderSize = value; Invalidate(); } + } [Category("CrEaTiiOn")] - public Color GradientColorPrimary { get => _gradientColorPrimary; set { _gradientColorPrimary = value; Invalidate(); } } + public Color GradientColorPrimary + { + get => _gradientColorPrimary; + set { _gradientColorPrimary = value; Invalidate(); } + } [Category("CrEaTiiOn")] - public Color GradientColorSecondary { get => _gradientColorSecondary; set { _gradientColorSecondary = value; Invalidate(); } } + public Color GradientColorSecondary + { + get => _gradientColorSecondary; + set { _gradientColorSecondary = value; Invalidate(); } + } [Category("CrEaTiiOn")] - public DashStyle BorderLineStyle { get => _borderLineStyle; set { _borderLineStyle = value; Invalidate(); } } + public DashStyle BorderLineStyle + { + get => _borderLineStyle; + set { _borderLineStyle = value; Invalidate(); } + } [Category("CrEaTiiOn")] - public DashCap BorderCapStyle { get => _borderCapStyle; set { _borderCapStyle = value; Invalidate(); } } + public DashCap BorderCapStyle + { + get => _borderCapStyle; + set { _borderCapStyle = value; Invalidate(); } + } [Category("CrEaTiiOn")] - public float GradientAngle { get => _gradientAngle; set { _gradientAngle = value; Invalidate(); } } + public float GradientAngle + { + get => _gradientAngle; + set { _gradientAngle = value; Invalidate(); } + } protected override void OnResize(EventArgs e) { @@ -44,7 +70,11 @@ protected override void OnResize(EventArgs e) protected override void OnPaint(PaintEventArgs pe) { base.OnPaint(pe); - var graphics = pe.Graphics; + DrawPictureBox(pe.Graphics); + } + + private void DrawPictureBox(Graphics graphics) + { var rectContourSmooth = Rectangle.Inflate(ClientRectangle, -1, -1); var rectBorder = Rectangle.Inflate(ClientRectangle, -_borderSize, -_borderSize); var smoothSize = _borderSize > 0 ? _borderSize * 3 : 1; @@ -66,4 +96,4 @@ protected override void OnPaint(PaintEventArgs pe) } } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_RadioButton.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_RadioButton.cs index 1a4946c..a95067c 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_RadioButton.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_RadioButton.cs @@ -1,8 +1,10 @@ -using System; +#region Imports +using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -26,8 +28,11 @@ public CrEaTiiOn_Ultimate_RadioButton() protected override void OnPaint(PaintEventArgs pevent) { + base.OnPaint(pevent); + var graphics = pevent.Graphics; graphics.SmoothingMode = SmoothingMode.AntiAlias; + var rbBorderSize = 18f; var rbCheckSize = 12f; var rectRbBorder = new RectangleF() @@ -45,22 +50,21 @@ protected override void OnPaint(PaintEventArgs pevent) Height = rbCheckSize }; - using (var penBorder = new Pen(_checkedColor, 1.6f)) + using (var penBorder = new Pen(Checked ? _checkedColor : _unCheckedColor, 1.6f)) using (var brushRbCheck = new SolidBrush(_checkedColor)) using (var brushBgCheck = new SolidBrush(_backgroundColor)) using (var brushText = new SolidBrush(ForeColor)) { graphics.Clear(_backgroundColor); + + // Draw RadioButton border + graphics.DrawEllipse(penBorder, rectRbBorder); + + // Draw RadioButton check if checked if (Checked) - { - graphics.DrawEllipse(penBorder, rectRbBorder); graphics.FillEllipse(brushRbCheck, rectRbCheck); - } - else - { - penBorder.Color = _unCheckedColor; - graphics.DrawEllipse(penBorder, rectRbBorder); - } + + // Draw RadioButton text graphics.DrawString(Text, Font, brushText, rbBorderSize + 8, (Height - TextRenderer.MeasureText(Text, Font).Height) / 2f); } } @@ -68,7 +72,8 @@ protected override void OnPaint(PaintEventArgs pevent) protected override void OnResize(EventArgs e) { base.OnResize(e); + // Dynamically adjust width based on text size Width = TextRenderer.MeasureText(Text, Font).Width + 30; } } -} +} \ No newline at end of file diff --git a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_ToggleButton.cs b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_ToggleButton.cs index 8905d76..28d317f 100644 --- a/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_ToggleButton.cs +++ b/CBH-WinForm-Theme-NET/Theme/ThemeBase/Ultimate Controls/CrEaTiiOn_Ultimate_ToggleButton.cs @@ -1,7 +1,9 @@ -using System.ComponentModel; +#region Imports +using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Windows.Forms; +#endregion namespace CBH.Ultimate.Controls { @@ -34,6 +36,7 @@ public override string Text public CrEaTiiOn_Ultimate_ToggleButton() { MinimumSize = new Size(45, 22); + SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw, true); } private GraphicsPath GetFigurePath() @@ -55,7 +58,6 @@ protected override void OnPaint(PaintEventArgs pevent) { var toggleSize = Height - 5; pevent.Graphics.SmoothingMode = SmoothingMode.AntiAlias; - pevent.Graphics.Clear(BackColor); if (Checked) { @@ -76,4 +78,4 @@ protected override void OnPaint(PaintEventArgs pevent) } } } -} +} \ No newline at end of file