random-file-runner/RyzStudio/Windows/ThemedForms/TNumericBox.cs

99 lines
3.3 KiB
C#
Raw Permalink Normal View History

2021-10-24 15:49:48 +00:00
using RyzStudio.Drawing;
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
namespace RyzStudio.Windows.ThemedForms
{
public partial class TNumericBox : RyzStudio.Windows.ThemedForms.TUserControl
{
protected readonly Padding textboxPadding = new Padding(4, 4, 4, 4);
public TNumericBox() : base()
{
InitializeComponent();
this.Margin = new Padding(10, 6, 10, 6);
this.Font = new Font(this.Font, FontStyle.Regular);
numericUpDown1.Font = this.Font;
numericUpDown1.PreviewKeyDown += textBox_PreviewKeyDown;
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
int b = (styleActive.BorderWidth + 1) + styleActive.BorderPadding;
this.Height = numericUpDown1.Height + (b + textboxPadding.Top) + ((b - 1) + textboxPadding.Bottom);
this.Invalidate();
}
protected override void OnGotFocus(EventArgs e)
{
base.OnGotFocus(e);
numericUpDown1.Focus();
}
protected void textBox_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
switch (e.KeyCode)
{
case Keys.Enter:
if (this.SubmitButton != null)
{
this.SubmitButton.PerformClick();
}
break;
case Keys.Escape:
close();
break;
default: break;
}
}
[Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)]
[Category("Appearance")]
public System.Windows.Forms.NumericUpDown InnerControl { get => numericUpDown1; set => numericUpDown1 = value; }
[Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)]
[Category("Appearance")]
public int Value
{
get => (int)numericUpDown1.Value;
set
{
numericUpDown1.Value = value;
}
}
//[Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)]
//[Category("Appearance")]
//public bool UseSystemPasswordChar { get => textBox1.UseSystemPasswordChar; set => textBox1.UseSystemPasswordChar = value; }
[Browsable(true), EditorBrowsable(EditorBrowsableState.Advanced)]
[Category("Appearance")]
public TButton SubmitButton { get; set; } = null;
[Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
public new Padding Margin { get { return base.Margin; } set { base.Margin = value; } }
protected override void updateBackground(Graphics g, ThemeStyle style)
{
int b = (styleActive.BorderWidth + 1) + styleActive.BorderPadding;
this.Padding = new Padding((b + textboxPadding.Left), (b + textboxPadding.Top), ((b - 1) + textboxPadding.Right), ((b - 1) + textboxPadding.Bottom));
Rectangoid area = new Rectangoid(this.ClientRectangle, style.BorderRadius, style.BorderWidth);
g.FillPath(new SolidBrush(style.BackColour), area.ToGraphicsPath());
g.DrawPath(new Pen(new SolidBrush(style.BorderColour), style.BorderWidth), area.ToGraphicsPath());
}
}
}