From f56644098d2e69086dcafea547b2c75542e90d7c Mon Sep 17 00:00:00 2001 From: denis apostolidi Date: Fri, 4 Aug 2017 11:33:46 +0300 Subject: [PATCH] - added DefaultSize property; - implemented ProgressBar control; - changed default shadow and header color for forms, added innerBorderPen; - more public to internal changes (uwf...),; - styling. --- System/Drawing/Font.cs | 3 +- System/Windows/Forms/ButtonBase.cs | 6 +- System/Windows/Forms/CheckBox.cs | 6 +- System/Windows/Forms/ComboBox.cs | 9 +- System/Windows/Forms/Control.cs | 12 +- System/Windows/Forms/Form.cs | 55 ++- System/Windows/Forms/GroupBox.cs | 34 +- System/Windows/Forms/HScrollBar.cs | 26 +- System/Windows/Forms/Label.cs | 5 + System/Windows/Forms/ListBox.cs | 6 +- System/Windows/Forms/MenuStrip.cs | 8 +- System/Windows/Forms/MessageBox.cs | 2 +- System/Windows/Forms/MonthCalendar.cs | 193 +++++----- System/Windows/Forms/NumericUpDown.cs | 190 +++++----- System/Windows/Forms/Panel.cs | 7 +- System/Windows/Forms/PictureBox.cs | 6 +- System/Windows/Forms/ProgressBar.cs | 197 +++++++++- System/Windows/Forms/ProgressBarStyle.cs | 9 + System/Windows/Forms/RadioButton.cs | 16 +- System/Windows/Forms/RepeatButton.cs | 80 ++-- System/Windows/Forms/ResizeButton.cs | 26 +- System/Windows/Forms/ScrollBar.cs | 34 +- System/Windows/Forms/TabControl.cs | 454 +++++++++++------------ System/Windows/Forms/TabPage.cs | 16 +- System/Windows/Forms/TextBox.cs | 6 +- System/Windows/Forms/ToolStrip.cs | 185 ++++----- System/Windows/Forms/TreeView.cs | 6 +- System/Windows/Forms/VScrollBar.cs | 6 +- 28 files changed, 924 insertions(+), 679 deletions(-) create mode 100644 System/Windows/Forms/ProgressBarStyle.cs diff --git a/System/Drawing/Font.cs b/System/Drawing/Font.cs index 9435f3e..d1443b6 100644 --- a/System/Drawing/Font.cs +++ b/System/Drawing/Font.cs @@ -9,8 +9,7 @@ public enum FontStyle Underline = 4, Strikeout = 8, } - - [Serializable] + public sealed class Font { internal UnityEngine.Font UFont; diff --git a/System/Windows/Forms/ButtonBase.cs b/System/Windows/Forms/ButtonBase.cs index 3c40f5a..702fe7c 100644 --- a/System/Windows/Forms/ButtonBase.cs +++ b/System/Windows/Forms/ButtonBase.cs @@ -30,7 +30,6 @@ public ButtonBase() BackColor = Color.FromArgb(234, 234, 234); BackgroundImageLayout = ImageLayout.Center; ForeColor = Color.FromArgb(64, 64, 64); - Size = new Size(75, 23); } public FlatStyle FlatStyle @@ -70,6 +69,11 @@ public virtual ContentAlignment TextAlign set { textAlign = value; } } + protected override Size DefaultSize + { + get { return new Size(75, 23); } + } + protected override void OnKeyUp(KeyEventArgs e) { if (e.KeyCode == Keys.Space || e.KeyCode == Keys.Return) diff --git a/System/Windows/Forms/CheckBox.cs b/System/Windows/Forms/CheckBox.cs index 0c1e71a..ca47af0 100644 --- a/System/Windows/Forms/CheckBox.cs +++ b/System/Windows/Forms/CheckBox.cs @@ -11,7 +11,6 @@ public CheckBox() { BackColor = Color.White; ForeColor = Color.Black; - Size = new Drawing.Size(128, 17); TextAlign = ContentAlignment.MiddleLeft; uwfBorderColor = Color.FromArgb(112, 112, 112); @@ -46,6 +45,11 @@ public CheckState CheckState } } + protected override Size DefaultSize + { + get { return new Size(104, 24); } + } + protected virtual void OnCheckedChanged(EventArgs e) { CheckedChanged(this, e); diff --git a/System/Windows/Forms/ComboBox.cs b/System/Windows/Forms/ComboBox.cs index 81b766c..8970a1a 100644 --- a/System/Windows/Forms/ComboBox.cs +++ b/System/Windows/Forms/ComboBox.cs @@ -36,7 +36,6 @@ public ComboBox() HoverColor = Color.White; HoverColorDropDownList = Color.FromArgb(227, 240, 252); Padding = new Padding(4, 0, 4, 0); - Size = new Size(121, 21); } public event EventHandler SelectedIndexChanged = delegate { }; @@ -101,6 +100,14 @@ public object SelectedItem } public bool WrapText { get; set; } + protected override Size DefaultSize + { + get + { + return new Size(121, 21); + } + } + internal override bool FocusInternal() { var res = base.FocusInternal(); diff --git a/System/Windows/Forms/Control.cs b/System/Windows/Forms/Control.cs index 61c7414..e0417dd 100644 --- a/System/Windows/Forms/Control.cs +++ b/System/Windows/Forms/Control.cs @@ -23,7 +23,6 @@ public class Control : Component internal DrawHandler uwfShadowHandler; internal IControlDesigner uwfDesigner; internal Point uwfOffset; - internal string uwfSource; protected static Color defaultShadowColor = Color.FromArgb(12, 0, 0, 0); @@ -60,6 +59,10 @@ public Control() ControlStyles.StandardClick | ControlStyles.Selectable | ControlStyles.StandardDoubleClick | ControlStyles.AllPaintingInWmPaint | ControlStyles.UseTextForAccessibility, true); + + var defaultSize = DefaultSize; + width = defaultSize.Width; + height = defaultSize.Height; } public delegate void DrawHandler(PaintEventArgs e); @@ -209,7 +212,12 @@ internal virtual bool uwfContext // Close on click control. } } } - internal bool uwfHovered { get { return hovered; } } + internal bool uwfHovered { get { return hovered; } } + + protected virtual Size DefaultSize + { + get { return Size.Empty; } + } public void BringToFront() { diff --git a/System/Windows/Forms/Form.cs b/System/Windows/Forms/Form.cs index b346eb7..3132823 100644 --- a/System/Windows/Forms/Form.cs +++ b/System/Windows/Forms/Form.cs @@ -6,14 +6,23 @@ [Serializable] public class Form : ContainerControl, IResizableControl { + internal readonly Pen borderPen = new Pen(Color.White); + internal readonly Pen innerBorderPen = new Pen(Color.FromArgb(214, 214, 214)); internal bool dialog; + internal Color uwfHeaderColor = Color.FromArgb(251, 251, 251); + internal Font uwfHeaderFont; + internal int uwfHeaderHeight = 24; + internal Padding uwfHeaderPadding = new Padding(32, 0, 32, 0); + internal ContentAlignment uwfHeaderTextAlign; + internal Color uwfHeaderTextColor = Color.FromArgb(64, 64, 64); + internal bool uwfMovable = true; - protected Button uwfSizeGripRenderer; + protected internal Button uwfSizeGripRenderer; private const int RESIZE_OFFSET = 8; private static Point nextLocation = new Point(128, 64); - private readonly Pen borderPen; + private Color backColor = SystemColors.Control; private Button closeButton; private Action dialogCallback; private MenuStrip mainMenuStrip; @@ -28,26 +37,18 @@ public class Form : ContainerControl, IResizableControl public Form() { - borderPen = new Pen(Color.White); - - BackColor = Color.FromArgb(238, 238, 242); ControlBox = true; Font = SystemFonts.uwfArial_14; FormBorderStyle = FormBorderStyle.Sizable; Location = nextLocation; MinimumSize = new Size(128, 48); - Size = new Size(334, 260); Visible = false; - uwfBorderColor = Color.FromArgb(204, 206, 219); - uwfHeaderColor = Color.FromArgb(238, 238, 242); + uwfBorderColor = Color.FromArgb(192, 192, 192); uwfHeaderFont = Font; - uwfHeaderHeight = 24; - uwfHeaderPadding = new Padding(32, 0, 32, 0); - uwfHeaderTextColor = Color.FromArgb(64, 64, 64); uwfHeaderTextAlign = ContentAlignment.MiddleLeft; - uwfMovable = true; uwfShadowBox = true; + uwfShadowHandler = DrawShadow; uwfAppOwner.UpClick += _Application_UpClick; uwfAppOwner.UpdateEvent += Owner_UpdateEvent; @@ -63,6 +64,11 @@ public Form() public event EventHandler Shown = delegate { }; public IButtonControl AcceptButton { get; set; } + public override Color BackColor + { + get { return backColor; } + set { backColor = value; } + } public Button CloseButton { get { return closeButton; } } public bool ControlBox { @@ -125,18 +131,16 @@ public bool TopMost } } - public Color uwfBorderColor + internal Color uwfBorderColor { get { return borderPen.Color; } set { borderPen.Color = value; } } - public Color uwfHeaderColor { get; set; } - public Font uwfHeaderFont { get; set; } - public int uwfHeaderHeight { get; set; } - public Padding uwfHeaderPadding { get; set; } - public ContentAlignment uwfHeaderTextAlign { get; set; } - public Color uwfHeaderTextColor { get; set; } - public bool uwfMovable { get; set; } + + protected override Size DefaultSize + { + get { return new Size(300, 300); } + } public void Close() { @@ -308,6 +312,7 @@ protected override void uwfOnLatePaint(PaintEventArgs e) { base.uwfOnLatePaint(e); + e.Graphics.DrawLine(innerBorderPen, 0, uwfHeaderHeight - 1, Width, uwfHeaderHeight - 1); e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height); } protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) @@ -322,6 +327,16 @@ private void _Application_UpClick(object sender, MouseEventArgs e) if (Application.activeResizeControl == this) Application.activeResizeControl = null; } + private void DrawShadow(PaintEventArgs e) + { + var loc = PointToScreen(Point.Empty); + var shadowAlpha = 12; + var shadowColor = Color.FromArgb(shadowAlpha, 64, 64, 64); + + e.Graphics.uwfFillRectangle(shadowColor, loc.X - 3, loc.Y, Width + 6, Height + 3); + e.Graphics.uwfFillRectangle(shadowColor, loc.X - 2, loc.Y, Width + 4, Height + 2); + e.Graphics.uwfFillRectangle(shadowColor, loc.X - 1, loc.Y - 1, Width + 2, Height + 2); + } private void _MakeButtonClose() { closeButton = new formSystemButton(); diff --git a/System/Windows/Forms/GroupBox.cs b/System/Windows/Forms/GroupBox.cs index 7abf5fa..253c9f1 100644 --- a/System/Windows/Forms/GroupBox.cs +++ b/System/Windows/Forms/GroupBox.cs @@ -1,31 +1,31 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Drawing; + public class GroupBox : Control { - private Pen borderPen = new Pen(Color.Transparent); - - public Color BorderColor - { - get { return borderPen.Color; } - set { borderPen.Color = value; } - } + private readonly Pen borderPen = new Pen(Color.LightGray); public GroupBox() { BackColor = Color.FromArgb(240, 240, 240); - BorderColor = Color.LightGray; ForeColor = Color.Gray; - Size = new Size(168, 286); TabIndex = -1; SetStyle(ControlStyles.Selectable, false); } + + internal Color uwfBorderColor + { + get { return borderPen.Color; } + set { borderPen.Color = value; } + } + + protected override Size DefaultSize + { + get { return new Size(200, 100); } + } + protected override void uwfOnLatePaint(PaintEventArgs e) { base.uwfOnLatePaint(e); @@ -35,7 +35,7 @@ protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); - Graphics g = e.Graphics; + var g = e.Graphics; g.uwfFillRectangle(BackColor, 0, 0, Width, Height); g.uwfDrawString(Text, Font, ForeColor, 8, 0, Width - 16, Height - 0); diff --git a/System/Windows/Forms/HScrollBar.cs b/System/Windows/Forms/HScrollBar.cs index 39a6f6b..9c68997 100644 --- a/System/Windows/Forms/HScrollBar.cs +++ b/System/Windows/Forms/HScrollBar.cs @@ -1,31 +1,31 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Drawing; + public class HScrollBar : ScrollBar { - private readonly Size ButtonSize = new Size(17, 15); + private readonly Size buttonSize = new Size(17, 15); public HScrollBar() { scrollOrientation = ScrollOrientation.HorizontalScroll; - Size = new Size(80, 15); subtractButton.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; subtractButton.Image = uwfAppOwner.Resources.CurvedArrowLeft; subtractButton.Location = new Point(0, 0); - subtractButton.Size = ButtonSize; + subtractButton.Size = buttonSize; addButton.Anchor = AnchorStyles.Right | AnchorStyles.Top | AnchorStyles.Bottom; addButton.Image = uwfAppOwner.Resources.CurvedArrowRight; - addButton.Location = new Point(Width - ButtonSize.Width, 0); - addButton.Size = ButtonSize; + addButton.Location = new Point(Width - buttonSize.Width, 0); + addButton.Size = buttonSize; - Refresh(); + UpdateScrollRect(); + } + + protected override Size DefaultSize + { + get { return new Size(80, 15); } } } } diff --git a/System/Windows/Forms/Label.cs b/System/Windows/Forms/Label.cs index 3ef1238..f42b38f 100644 --- a/System/Windows/Forms/Label.cs +++ b/System/Windows/Forms/Label.cs @@ -19,6 +19,11 @@ public Label() public ContentAlignment TextAlign { get; set; } + protected override Size DefaultSize + { + get { return new Size(100, 23); } // Autosize ? Preferred height. + } + protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); diff --git a/System/Windows/Forms/ListBox.cs b/System/Windows/Forms/ListBox.cs index facf008..c8fa780 100644 --- a/System/Windows/Forms/ListBox.cs +++ b/System/Windows/Forms/ListBox.cs @@ -42,7 +42,6 @@ public ListBox() SelectionBackColor = SystemColors.Highlight; SelectionDisabledColor = Color.FromArgb(101, 203, 255); SelectionForeColor = SystemColors.HighlightText; - Size = new Size(120, 95); WrapText = true; vScroll = new VScrollBar(); @@ -173,6 +172,11 @@ internal int ScrollIndex set { vScroll.Value = value * ItemHeight; } } + protected override Size DefaultSize + { + get { return new Size(120, 96); } + } + public void AdjustHeight() { integralHeightAdjust = false; diff --git a/System/Windows/Forms/MenuStrip.cs b/System/Windows/Forms/MenuStrip.cs index 12cc4e9..209c6c3 100644 --- a/System/Windows/Forms/MenuStrip.cs +++ b/System/Windows/Forms/MenuStrip.cs @@ -1,5 +1,7 @@ namespace System.Windows.Forms { + using System.Drawing; + [Serializable] public class MenuStrip : ToolStrip { @@ -8,7 +10,11 @@ public MenuStrip() BorderColor = Drawing.Color.Transparent; Orientation = Orientation.Horizontal; Padding = new Padding(2); - Size = new Drawing.Size(600, 24); + } + + protected override Size DefaultSize + { + get { return new Size(200, 24); } } } } diff --git a/System/Windows/Forms/MessageBox.cs b/System/Windows/Forms/MessageBox.cs index 26da177..9ffc656 100644 --- a/System/Windows/Forms/MessageBox.cs +++ b/System/Windows/Forms/MessageBox.cs @@ -38,7 +38,7 @@ public static DialogResult Show(string text, string caption, Font textFont) GroupBox formGroup = new GroupBox(); formGroup.Anchor = AnchorStyles.Left | AnchorStyles.Bottom | AnchorStyles.Right | AnchorStyles.Top; formGroup.BackColor = Color.White; - formGroup.BorderColor = form.uwfBorderColor; + formGroup.uwfBorderColor = form.uwfBorderColor; formGroup.Size = new Size(form.Width - 16, form.Height - (int)form.uwfHeaderHeight - 8 - 28); formGroup.Location = new Point(8, (int)form.uwfHeaderHeight); diff --git a/System/Windows/Forms/MonthCalendar.cs b/System/Windows/Forms/MonthCalendar.cs index 896648d..892b9c6 100644 --- a/System/Windows/Forms/MonthCalendar.cs +++ b/System/Windows/Forms/MonthCalendar.cs @@ -1,24 +1,62 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Collections.Generic; + using System.Drawing; + public class MonthCalendar : Control { private readonly Pen borderPen = new Pen(Color.Black); - private readonly List _daysControls = new List(); - private string[] _daysShort; - private DayOfWeek _firstDayOfWeek; - private string[] _months; - private DateTime _selectedDate; - private bool _showToday; - private DateTime _todayDate; - private DateTime _value; - + private readonly List daysControls = new List(); + private string[] daysShort; + private DayOfWeek firstDayOfWeek; + private string[] months; + private DateTime selectedDate; + private bool showToday; private Button todayButton; + private DateTime todayDate; + private DateTime value; + + public MonthCalendar() + { + firstDayOfWeek = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; + + BackColor = Color.White; + CellWidth = 31; + DaysShort = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames; + Size = new Size(CellWidth * 7 + 6, 158); + ShowToday = true; + TitleBackColor = Color.Transparent; + TitleForeColor = Color.FromArgb(42, 42, 42); + TodayDate = DateTime.Now; + Value = DateTime.Now; + + Button prevMonthButton = new Button(); + prevMonthButton.Image = uwfAppOwner.Resources.ArrowLeft; + prevMonthButton.uwfImageColor = Color.FromArgb(48, 48, 48); + prevMonthButton.Size = new Size(16, 16); + prevMonthButton.Location = new Point(4, 8); + prevMonthButton.uwfBorderColor = Color.Transparent; + prevMonthButton.uwfBorderHoverColor = Color.Transparent; + prevMonthButton.BackColor = Color.Transparent; + prevMonthButton.Click += (s, a) => { SetDate(selectedDate.AddMonths(-1)); }; + Controls.Add(prevMonthButton); + + Button nextMonthButton = new Button(); + nextMonthButton.Anchor = AnchorStyles.Right; + nextMonthButton.Image = uwfAppOwner.Resources.ArrowRight; + nextMonthButton.uwfImageColor = Color.FromArgb(48, 48, 48); + nextMonthButton.Size = new Size(16, 16); + nextMonthButton.Location = new Point(Width - nextMonthButton.Width - 4, 8); + nextMonthButton.uwfBorderColor = Color.Transparent; + nextMonthButton.uwfBorderHoverColor = Color.Transparent; + nextMonthButton.BackColor = Color.Transparent; + nextMonthButton.Click += (s, a) => { SetDate(selectedDate.AddMonths(1)); }; + Controls.Add(nextMonthButton); + + months = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames; + } + + public event DateRangeEventHandler DateChanged = delegate { }; public Color BorderColor { @@ -28,45 +66,45 @@ public Color BorderColor public int CellWidth { get; set; } public string[] DaysShort { - get { return _daysShort; } + get { return daysShort; } set { if (value == null) throw new NullReferenceException("value is null"); if (value.Length != 7) throw new ArgumentException("value length is not equal 7"); - _daysShort = value; + daysShort = value; } } public DayOfWeek FirstDayOfWeek { - get { return _firstDayOfWeek; } + get { return firstDayOfWeek; } set { - if (_firstDayOfWeek != value) + if (firstDayOfWeek != value) { - _firstDayOfWeek = value; - SetDate(_selectedDate); + firstDayOfWeek = value; + SetDate(selectedDate); } } } public string[] Months { - get { return _months; } + get { return months; } set { if (value == null) throw new NullReferenceException("value is null"); if (value.Length != 12) throw new ArgumentException("value length is not equal 12"); - _months = value; + months = value; } } public bool ShowToday { - get { return _showToday; } + get { return showToday; } set { - if (_showToday != value) + if (showToday != value) { - _showToday = value; - if (_showToday) + showToday = value; + if (showToday) { todayButton = new Button(); todayButton.Location = new Point(3 + 2 * CellWidth, 33 + 7 * 15); @@ -96,85 +134,44 @@ public bool ShowToday public Color TitleForeColor { get; set; } public DateTime TodayDate { - get { return _todayDate; } + get { return todayDate; } set { - _todayDate = value; + todayDate = value; if (todayButton != null) todayButton.Text = "Today: " + value.ToShortDateString(); } } public DateTime Value { - get { return _value; } + get { return value; } set { - _value = value; - SetDate(_value); - DateChanged(this, new DateRangeEventArgs(_value, _value)); + this.value = value; + SetDate(this.value); + DateChanged(this, new DateRangeEventArgs(this.value, this.value)); } } - public MonthCalendar() - { - _firstDayOfWeek = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.FirstDayOfWeek; - - BackColor = Color.White; - CellWidth = 31; - DaysShort = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AbbreviatedDayNames; - Size = new Size(CellWidth * 7 + 6, 158); - ShowToday = true; - TitleBackColor = Color.Transparent; - TitleForeColor = Color.FromArgb(42, 42, 42); - TodayDate = DateTime.Now; - Value = DateTime.Now; - - Button prevMonthButton = new Button(); - prevMonthButton.Image = uwfAppOwner.Resources.ArrowLeft; - prevMonthButton.uwfImageColor = Color.FromArgb(48, 48, 48); - prevMonthButton.Size = new Size(16, 16); - prevMonthButton.Location = new Point(4, 8); - prevMonthButton.uwfBorderColor = Color.Transparent; - prevMonthButton.uwfBorderHoverColor = Color.Transparent; - prevMonthButton.BackColor = Color.Transparent; - prevMonthButton.Click += (s, a) => { SetDate(_selectedDate.AddMonths(-1)); }; - Controls.Add(prevMonthButton); - - Button nextMonthButton = new Button(); - nextMonthButton.Anchor = AnchorStyles.Right; - nextMonthButton.Image = uwfAppOwner.Resources.ArrowRight; - nextMonthButton.uwfImageColor = Color.FromArgb(48, 48, 48); - nextMonthButton.Size = new Size(16, 16); - nextMonthButton.Location = new Point(Width - nextMonthButton.Width - 4, 8); - nextMonthButton.uwfBorderColor = Color.Transparent; - nextMonthButton.uwfBorderHoverColor = Color.Transparent; - nextMonthButton.BackColor = Color.Transparent; - nextMonthButton.Click += (s, a) => { SetDate(_selectedDate.AddMonths(1)); }; - Controls.Add(nextMonthButton); - - _months = System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.MonthNames; - } - public void SetDate(DateTime date) { - _selectedDate = date; + selectedDate = date; // TODO: update only if month & year are changed. - for (int i = 0; i < _daysControls.Count; i++) - _daysControls[i].Dispose(); - _daysControls.Clear(); - - var daysShort = DaysShort; - List daysShortList = new List(); - for (int i = (int)(_firstDayOfWeek); i < 7; i++) + for (int i = 0; i < daysControls.Count; i++) + daysControls[i].Dispose(); + daysControls.Clear(); + + var daysShortList = new List(); + for (int i = (int)firstDayOfWeek; i < 7; i++) daysShortList.Add(daysShort[i]); - for (int i = 0; i < (int)_firstDayOfWeek; i++) + for (int i = 0; i < (int)firstDayOfWeek; i++) daysShortList.Add(daysShort[i]); daysShort = daysShortList.ToArray(); var monthStartDayOfWeek = new DateTime(date.Year, date.Month, 1).DayOfWeek; - DateTime startDate = new DateTime(date.Year, date.Month, 1).AddDays(-(int)monthStartDayOfWeek + (int)_firstDayOfWeek); + DateTime startDate = new DateTime(date.Year, date.Month, 1).AddDays(-(int)monthStartDayOfWeek + (int)firstDayOfWeek); for (int row = 0; row < 7; row++) { @@ -191,7 +188,7 @@ public void SetDate(DateTime date) labelDayOfWeek.Padding = new Padding(); Controls.Add(labelDayOfWeek); - _daysControls.Add(labelDayOfWeek); + daysControls.Add(labelDayOfWeek); } else { @@ -230,11 +227,21 @@ public void SetDate(DateTime date) } startDate = startDate.AddDays(1); - _daysControls.Add(dayButton); + daysControls.Add(dayButton); } } } } + public override void Refresh() + { + base.Refresh(); + SetDate(selectedDate); + + if (todayButton != null) + { + todayButton.Location = new Point(3 + 2 * CellWidth, 33 + 7 * 15); + } + } protected override void OnPaint(PaintEventArgs e) { @@ -242,24 +249,12 @@ protected override void OnPaint(PaintEventArgs e) // Header. e.Graphics.uwfFillRectangle(TitleBackColor, 0, 0, Width, 32); - e.Graphics.uwfDrawString(_months[_selectedDate.Month - 1] + " " + _selectedDate.Year.ToString(), Font, TitleForeColor, 0, 0, Width, 32, ContentAlignment.MiddleCenter); + e.Graphics.uwfDrawString(months[selectedDate.Month - 1] + " " + selectedDate.Year.ToString(), Font, TitleForeColor, 0, 0, Width, 32, ContentAlignment.MiddleCenter); if (ShowToday) e.Graphics.DrawRectangle(new Pen(Color.FromArgb(0, 102, 204)), CellWidth * 1, 141, CellWidth - 2, 13); e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height); } - public override void Refresh() - { - base.Refresh(); - SetDate(_selectedDate); - - if (todayButton != null) - { - todayButton.Location = new Point(3 + 2 * CellWidth, 33 + 7 * 15); - } - } - - public event DateRangeEventHandler DateChanged = delegate { }; } } diff --git a/System/Windows/Forms/NumericUpDown.cs b/System/Windows/Forms/NumericUpDown.cs index 9b7c8eb..a79731b 100644 --- a/System/Windows/Forms/NumericUpDown.cs +++ b/System/Windows/Forms/NumericUpDown.cs @@ -1,51 +1,89 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Drawing; + public class NumericUpDown : Control { - private decimal _minimum; - private decimal _maximum; + internal Pen borderPen = new Pen(Color.Transparent); - protected Pen borderPen = new Pen(Color.Transparent); protected decimal value; protected string valueText = "0"; - public Button ButtonIncrease { get; private set; } - public Button ButtonDecrease { get; private set; } + private decimal minimum; + private decimal maximum; - public Color BorderColor + public NumericUpDown() : this(true) { - get { return borderPen.Color; } - set { borderPen.Color = value; } + + } + internal NumericUpDown(bool initButtons) + { + BackColor = Color.FromArgb(250, 250, 250); + uwfBorderColor = Color.FromArgb(175, 175, 175); + uwfDisabledColor = Color.FromArgb(240, 240, 240); + Increment = 1; + Maximum = 100; + Minimum = 0; + Padding = new Padding(4, 0, 4, 0); + TextAlign = HorizontalAlignment.Left; + + if (initButtons) + { + uwfButtonIncrease = new RepeatButton(); + uwfButtonIncrease.Anchor = AnchorStyles.Right | AnchorStyles.Top; + uwfButtonIncrease.Location = new Point(Width - 16, Height / 2 - 8); + uwfButtonIncrease.Size = new Size(14, 8); + uwfButtonIncrease.Name = "_numericButtonIncrease"; + uwfButtonIncrease.BackColor = Color.FromArgb(236, 236, 236); + uwfButtonIncrease.uwfBorderColor = Color.FromArgb(172, 172, 172); + uwfButtonIncrease.uwfHoverColor = Color.FromArgb(228, 241, 252); + uwfButtonIncrease.uwfBorderHoverColor = Color.FromArgb(126, 180, 234); + uwfButtonIncrease.Image = uwfAppOwner.Resources.NumericUp; + uwfButtonIncrease.Click += delegate { if (Enabled) Value += Increment; }; + + ButtonDecrease = new RepeatButton(); + ButtonDecrease.Anchor = AnchorStyles.Right | AnchorStyles.Top; + ButtonDecrease.Location = new Point(Width - 16, Height / 2); + ButtonDecrease.Size = new Drawing.Size(14, 8); + ButtonDecrease.Name = "_numericButtonDecrease"; + ButtonDecrease.BackColor = Color.FromArgb(236, 236, 236); + ButtonDecrease.uwfBorderColor = Color.FromArgb(172, 172, 172); + ButtonDecrease.uwfHoverColor = Color.FromArgb(228, 241, 252); + ButtonDecrease.uwfBorderHoverColor = Color.FromArgb(126, 180, 234); + ButtonDecrease.Image = uwfAppOwner.Resources.NumericDown; + ButtonDecrease.Click += delegate { if (Enabled) Value -= Increment; }; + + Controls.Add(uwfButtonIncrease); + Controls.Add(ButtonDecrease); + } + + Resize += UpdateButtonsLocation; + LostFocus += (s, a) => { ConfirmValue(); }; } - public Color DisabledColor { get; set; } + + public event EventHandler ValueChanged = delegate { }; + public decimal Increment { get; set; } public decimal Maximum { - get { return _maximum; } + get { return maximum; } set { - if (value < _minimum) _minimum = value; - _maximum = value; - if (this.value < _minimum) this.value = _minimum; - if (this.value > _maximum) this.value = _maximum; + if (value < minimum) minimum = value; + maximum = value; + if (this.value < minimum) this.value = minimum; + if (this.value > maximum) this.value = maximum; } } public decimal Minimum { - get { return _minimum; } + get { return minimum; } set { - if (value > _maximum) _maximum = value; - _minimum = value; - if (this.value < _minimum) this.value = _minimum; - if (this.value > _maximum) this.value = _maximum; + if (value > maximum) maximum = value; + minimum = value; + if (this.value < minimum) this.value = minimum; + if (this.value > maximum) this.value = maximum; } } public HorizontalAlignment TextAlign { get; set; } @@ -64,57 +102,30 @@ public decimal Value } } - public NumericUpDown() : this(true) + internal Color uwfBorderColor { - + get { return borderPen.Color; } + set { borderPen.Color = value; } } - public NumericUpDown(bool initButtons) - { - BackColor = Color.FromArgb(250, 250, 250); - BorderColor = Color.FromArgb(175, 175, 175); - DisabledColor = Color.FromArgb(240, 240, 240); - Increment = 1; - Maximum = 100; - Minimum = 0; - Padding = new Padding(4, 0, 4, 0); - Size = new Drawing.Size(120, 20); - TextAlign = HorizontalAlignment.Left; + internal Button ButtonDecrease { get; private set; } + internal Button uwfButtonIncrease { get; private set; } + internal Color uwfDisabledColor { get; set; } - if (initButtons) - { - ButtonIncrease = new RepeatButton(); - ButtonIncrease.Anchor = AnchorStyles.Right | AnchorStyles.Top; - ButtonIncrease.Location = new Point(Width - 16, Height / 2 - 8); - ButtonIncrease.Size = new Size(14, 8); - ButtonIncrease.Name = "_numericButtonIncrease"; - ButtonIncrease.BackColor = Color.FromArgb(236, 236, 236); - ButtonIncrease.uwfBorderColor = Color.FromArgb(172, 172, 172); - ButtonIncrease.uwfHoverColor = Color.FromArgb(228, 241, 252); - ButtonIncrease.uwfBorderHoverColor = Color.FromArgb(126, 180, 234); - ButtonIncrease.Image = uwfAppOwner.Resources.NumericUp; - ButtonIncrease.Click += delegate { if (Enabled) Value += Increment; }; - - ButtonDecrease = new RepeatButton(); - ButtonDecrease.Anchor = AnchorStyles.Right | AnchorStyles.Top; - ButtonDecrease.Location = new Point(Width - 16, Height / 2); - ButtonDecrease.Size = new Drawing.Size(14, 8); - ButtonDecrease.Name = "_numericButtonDecrease"; - ButtonDecrease.BackColor = Color.FromArgb(236, 236, 236); - ButtonDecrease.uwfBorderColor = Color.FromArgb(172, 172, 172); - ButtonDecrease.uwfHoverColor = Color.FromArgb(228, 241, 252); - ButtonDecrease.uwfBorderHoverColor = Color.FromArgb(126, 180, 234); - ButtonDecrease.Image = uwfAppOwner.Resources.NumericDown; - ButtonDecrease.Click += delegate { if (Enabled) Value -= Increment; }; - - Controls.Add(ButtonIncrease); - Controls.Add(ButtonDecrease); - } - - Resize += UpdateButtonsLocation; - LostFocus += (s, a) => { ConfirmValue(); }; + protected override Size DefaultSize + { + get { return new Size(120, 20); } } - public event EventHandler ValueChanged = delegate { }; + public void ShowButtons() + { + uwfButtonIncrease.Visible = true; + ButtonDecrease.Visible = true; + } + public void HideButtons() + { + uwfButtonIncrease.Visible = false; + ButtonDecrease.Visible = false; + } protected void ConfirmValue() { @@ -123,12 +134,6 @@ protected void ConfirmValue() if (Value != value) Value = value; } - protected override void uwfOnLatePaint(PaintEventArgs e) - { - base.uwfOnLatePaint(e); - - e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height); - } protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); @@ -152,10 +157,10 @@ protected override void OnPaint(PaintEventArgs e) var g = e.Graphics; int textPaddingRight = 0; - if (ButtonIncrease != null && ButtonIncrease.Visible) + if (uwfButtonIncrease != null && uwfButtonIncrease.Visible) textPaddingRight = -16; - var backColor = Enabled ? BackColor : DisabledColor; + var backColor = Enabled ? BackColor : uwfDisabledColor; var foreColor = Enabled ? ForeColor : Color.Black; g.uwfFillRectangle(backColor, 0, 0, Width, Height); @@ -165,23 +170,20 @@ protected override void OnPaint(PaintEventArgs e) else g.uwfDrawString(valueText, Font, foreColor, Padding.Left, 0, Width + textPaddingRight, Height, TextAlign); } - protected void UpdateButtonsLocation(object sender, EventArgs e) - { - if (ButtonIncrease != null) - ButtonIncrease.Location = new Point(Width - 16, Height / 2 - 8); - if (ButtonDecrease != null) - ButtonDecrease.Location = new Point(Width - 16, Height / 2); - } - public void ShowButtons() + protected override void uwfOnLatePaint(PaintEventArgs e) { - ButtonIncrease.Visible = true; - ButtonDecrease.Visible = true; + base.uwfOnLatePaint(e); + + e.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height); } - public void HideButtons() + + private void UpdateButtonsLocation(object sender, EventArgs e) { - ButtonIncrease.Visible = false; - ButtonDecrease.Visible = false; + if (uwfButtonIncrease != null) + uwfButtonIncrease.Location = new Point(Width - 16, Height / 2 - 8); + if (ButtonDecrease != null) + ButtonDecrease.Location = new Point(Width - 16, Height / 2); } } } diff --git a/System/Windows/Forms/Panel.cs b/System/Windows/Forms/Panel.cs index 0605d79..bc69cd3 100644 --- a/System/Windows/Forms/Panel.cs +++ b/System/Windows/Forms/Panel.cs @@ -11,12 +11,17 @@ public Panel() SetStyle(ControlStyles.Selectable | ControlStyles.AllPaintingInWmPaint, false); } - public Color uwfBorderColor + internal Color uwfBorderColor { get { return borderPen.Color; } set { borderPen.Color = value; } } + protected override Size DefaultSize + { + get { return new Size(200, 100); } + } + protected override void OnPaint(PaintEventArgs e) { e.Graphics.uwfFillRectangle(BackColor, 0, 0, Width, Height); diff --git a/System/Windows/Forms/PictureBox.cs b/System/Windows/Forms/PictureBox.cs index 88e31cc..5fa4e48 100644 --- a/System/Windows/Forms/PictureBox.cs +++ b/System/Windows/Forms/PictureBox.cs @@ -13,7 +13,6 @@ public class PictureBox : Control, ISupportInitialize public PictureBox() { backgroundImageLayout = ImageLayout.Center; - Size = new Size(100, 50); UpdateRect(this, EventArgs.Empty); Resize += UpdateRect; @@ -38,6 +37,11 @@ public Bitmap Image } } + protected override Size DefaultSize + { + get { return new Size(100, 50); } + } + public void BeginInit() { } diff --git a/System/Windows/Forms/ProgressBar.cs b/System/Windows/Forms/ProgressBar.cs index ea02659..0ef91be 100644 --- a/System/Windows/Forms/ProgressBar.cs +++ b/System/Windows/Forms/ProgressBar.cs @@ -1,12 +1,195 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace System.Windows.Forms +namespace System.Windows.Forms { - [Obsolete] + using System.Drawing; + using System.Globalization; + public class ProgressBar : Control { + private readonly SolidBrush backBrush = new SolidBrush(SystemColors.ControlLight); + private readonly SolidBrush barBrush = new SolidBrush(Color.FromArgb(6, 176, 37)); + private readonly Pen borderPen = new Pen(SystemColors.ActiveBorder); + private readonly Color defaultForeColor = SystemColors.Highlight; + + private float barX; + private float barWidth; + private int marqueeSpeed = 100; + private int marqueeWidth = 127; + private int maximum = 100; + private int minimum; + private bool rightToLeftLayout; + private int step = 10; + private bool updatePos; + private int value; + + public ProgressBar() + { + ForeColor = this.defaultForeColor; + SetStyle(ControlStyles.UserPaint | ControlStyles.Selectable | ControlStyles.UseTextForAccessibility, false); + + uwfAppOwner.UpdateEvent += AppOwnerOnUpdateEvent; + } + public event EventHandler RightToLeftLayoutChanged = delegate { }; + + public int MarqueeAnimationSpeed + { + get { return marqueeSpeed; } + set + { + if (value < 0) + throw new ArgumentOutOfRangeException("marqueeSpeed"); + + marqueeSpeed = value; + } + } + public int Maximum + { + get { return maximum; } + set + { + if (maximum == value) + return; + + if (value < 0) + throw new ArgumentOutOfRangeException("maximum"); + + if (minimum > value) + minimum = value; + + maximum = value; + + if (this.value > maximum) + this.value = maximum; + + UpdatePos(); + } + } + public int Minimum + { + get { return minimum; } + set + { + if (minimum == value) + return; + + if (value < 0) + throw new ArgumentOutOfRangeException("minimum"); + + if (maximum < value) + maximum = value; + + minimum = value; + if (this.value < minimum) + this.value = minimum; + + UpdatePos(); + } + } + public virtual bool RightToLeftLayout + { + get { return rightToLeftLayout; } + set + { + if (rightToLeftLayout == value) + return; + + rightToLeftLayout = value; + OnRightToLeftLayoutChanged(EventArgs.Empty); + } + } + public int Step + { + get { return step; } + set { step = value; } + } + public ProgressBarStyle Style { get; set; } + public int Value + { + get { return this.value; } + set + { + if (this.value == value) + return; + + if (value < minimum || value > maximum) + throw new ArgumentOutOfRangeException("value"); + + this.value = value; + UpdatePos(); + } + } + + protected override Size DefaultSize + { + get { return new Size(100, 23); } + } + + public void Increment(int value) + { + if (Style == ProgressBarStyle.Marquee) + throw new InvalidOperationException("ProgressBarIncrementMarqueeException"); + + this.value += value; + if (this.value < minimum) + this.value = minimum; + if (this.value > maximum) + this.value = maximum; + UpdatePos(); + } + public void PerformStep() + { + Increment(step); + } + public override string ToString() + { + return base.ToString() + + ", Minimum: " + minimum.ToString(CultureInfo.CurrentCulture) + + ", Maximum: " + maximum.ToString(CultureInfo.CurrentCulture) + + ", Value: " + value.ToString(CultureInfo.CurrentCulture); + } + + protected override void OnPaint(PaintEventArgs e) + { + var g = e.Graphics; + + g.FillRectangle(backBrush, 0, 0, Width, Height); + g.DrawRectangle(borderPen, 0, 0, Width, Height); + g.FillRectangle(barBrush, barX, 1, barWidth, Height - 2); + } + protected override void OnResize(EventArgs e) + { + base.OnResize(e); + + UpdatePos(); + } + protected virtual void OnRightToLeftLayoutChanged(EventArgs e) + { + if (RightToLeftLayoutChanged == null) + return; + + RightToLeftLayoutChanged(this, e); + } + + private void AppOwnerOnUpdateEvent() + { + if (updatePos == false && Style != ProgressBarStyle.Marquee) + return; + + if (Style == ProgressBarStyle.Marquee) + { + barWidth = marqueeWidth; + if (barX < Width) + barX = MathHelper.Step(barX, Width, marqueeSpeed / 2f); + else + barX = -marqueeWidth; + return; + } + + barX = 0; + barWidth = MathHelper.Step(barWidth, (value / maximum) * Width, 200); + } + private void UpdatePos() + { + updatePos = true; + } } } diff --git a/System/Windows/Forms/ProgressBarStyle.cs b/System/Windows/Forms/ProgressBarStyle.cs new file mode 100644 index 0000000..ca569b9 --- /dev/null +++ b/System/Windows/Forms/ProgressBarStyle.cs @@ -0,0 +1,9 @@ +namespace System.Windows.Forms +{ + public enum ProgressBarStyle + { + Blocks, + Continuous, + Marquee, + } +} diff --git a/System/Windows/Forms/RadioButton.cs b/System/Windows/Forms/RadioButton.cs index 0b18d80..14456f2 100644 --- a/System/Windows/Forms/RadioButton.cs +++ b/System/Windows/Forms/RadioButton.cs @@ -1,13 +1,15 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Drawing; + [Obsolete] - public class RadioButton : Button + public class RadioButton : ButtonBase { public bool Checked { get; set; } + + protected override Size DefaultSize + { + get { return new Size(104, 24); } + } } } diff --git a/System/Windows/Forms/RepeatButton.cs b/System/Windows/Forms/RepeatButton.cs index cd1b31e..8b657ad 100644 --- a/System/Windows/Forms/RepeatButton.cs +++ b/System/Windows/Forms/RepeatButton.cs @@ -1,12 +1,6 @@ -using System; -using System.Collections.Generic; -using System.ComponentModel; -using System.Linq; -using System.Text; - -namespace System.Windows.Forms +namespace System.Windows.Forms { - public class RepeatButton : Button + internal class RepeatButton : Button { private bool mdown = false; private bool repeatClick = false; @@ -14,7 +8,13 @@ public class RepeatButton : Button private float repeatCooldownCurrent = 0; private float repeatCooldownMin = .1f; private float repeatStartCooldown = .4f; - + + public RepeatButton() + { + uwfAppOwner.UpClick += Owner_UpClick; + uwfAppOwner.UpdateEvent += Owner_UpdateEvent; + } + public float CooldownBetweenClicks { get { return repeatCooldownMin; } @@ -29,40 +29,6 @@ public float WaitCooldown set { repeatStartCooldown = value; } } - public RepeatButton() - { - uwfAppOwner.UpClick += Owner_UpClick; - uwfAppOwner.UpdateEvent += Owner_UpdateEvent; - } - - private void Owner_UpClick(object sender, MouseEventArgs e) - { - mdown = false; - repeatClick = false; - } - private void Owner_UpdateEvent() - { - if (repeatClick) - { - if (repeatCooldownCurrent <= 0) - { - PerformClick(); - - repeatCooldown = repeatCooldownMin; - repeatCooldownCurrent = repeatCooldown; - } - else - repeatCooldownCurrent -= swfHelper.GetDeltaTime(); - } - } - private void StartRepeat() - { - mdown = true; - repeatClick = true; - repeatCooldown = repeatStartCooldown; - repeatCooldownCurrent = repeatCooldown; - } - protected override void Dispose(bool release_all) { uwfAppOwner.UpClick -= Owner_UpClick; @@ -100,5 +66,33 @@ protected override void OnMouseLeave(EventArgs e) repeatClick = false; } + + private void Owner_UpClick(object sender, MouseEventArgs e) + { + mdown = false; + repeatClick = false; + } + private void Owner_UpdateEvent() + { + if (repeatClick) + { + if (repeatCooldownCurrent <= 0) + { + PerformClick(); + + repeatCooldown = repeatCooldownMin; + repeatCooldownCurrent = repeatCooldown; + } + else + repeatCooldownCurrent -= swfHelper.GetDeltaTime(); + } + } + private void StartRepeat() + { + mdown = true; + repeatClick = true; + repeatCooldown = repeatStartCooldown; + repeatCooldownCurrent = repeatCooldown; + } } } diff --git a/System/Windows/Forms/ResizeButton.cs b/System/Windows/Forms/ResizeButton.cs index 47c24ed..fe05dc9 100644 --- a/System/Windows/Forms/ResizeButton.cs +++ b/System/Windows/Forms/ResizeButton.cs @@ -1,15 +1,11 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Drawing; + internal sealed class ResizeButton : Button, IResizableControl { - private bool pressed; private readonly Form owner; + private bool pressed; public ResizeButton(Form form, Bitmap img) { @@ -34,13 +30,6 @@ public ResizeButton(Form form, Bitmap img) uwfAppOwner.UpClick += Owner_UpClick; } - private void Owner_UpClick(object sender, MouseEventArgs e) - { - if (pressed) - Cursor.CurrentSystem = Cursors.Default; - pressed = false; - } - public ControlResizeTypes GetResizeAt(Point mclient) { return ControlResizeTypes.RightDown; @@ -73,5 +62,12 @@ protected override void OnMouseLeave(EventArgs e) if (pressed == false) Cursor.CurrentSystem = Cursors.Default; } + + private void Owner_UpClick(object sender, MouseEventArgs e) + { + if (pressed) + Cursor.CurrentSystem = Cursors.Default; + pressed = false; + } } } diff --git a/System/Windows/Forms/ScrollBar.cs b/System/Windows/Forms/ScrollBar.cs index 10c0de9..6aac43a 100644 --- a/System/Windows/Forms/ScrollBar.cs +++ b/System/Windows/Forms/ScrollBar.cs @@ -171,7 +171,7 @@ internal void DoScroll(ScrollEventType type) UpdateScrollRect(); - ScrollEventArgs se = new ScrollEventArgs(type, oldValue, newValue, scrollOrientation); + var se = new ScrollEventArgs(type, oldValue, newValue, scrollOrientation); OnScroll(se); Value = se.NewValue; } @@ -292,25 +292,23 @@ protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); - if (scrollDraging == false) + if (scrollDraging) return; + + var sEvent = ScrollEventType.LargeIncrement; + if (scrollRect.Contains(e.Location)) return; + + if (scrollOrientation == ScrollOrientation.HorizontalScroll) { - var sEvent = ScrollEventType.LargeIncrement; - if (scrollRect.Contains(e.Location) == false) - { - if (scrollOrientation == ScrollOrientation.HorizontalScroll) - { - if (scrollRect.X + scrollRect.Width / 2 > e.Location.X) - sEvent = ScrollEventType.LargeDecrement; - } - else - { - if (scrollRect.Y + scrollRect.Height / 2 > e.Location.Y) - sEvent = ScrollEventType.LargeDecrement; - } - - DoScroll(sEvent); - } + if (scrollRect.X + scrollRect.Width / 2 > e.Location.X) + sEvent = ScrollEventType.LargeDecrement; } + else + { + if (scrollRect.Y + scrollRect.Height / 2 > e.Location.Y) + sEvent = ScrollEventType.LargeDecrement; + } + + DoScroll(sEvent); } protected override void OnMouseWheel(MouseEventArgs e) { diff --git a/System/Windows/Forms/TabControl.cs b/System/Windows/Forms/TabControl.cs index 6abe4a3..faba2f0 100644 --- a/System/Windows/Forms/TabControl.cs +++ b/System/Windows/Forms/TabControl.cs @@ -1,35 +1,41 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Collections; + using System.Collections.Generic; + using System.Drawing; + using System.Linq; + public class TabControl : Control { - private Size itemSize = new Size(); + internal List pagesButtons = new List(); + internal int tabPageCount; + internal int tabViewIndex; + + private readonly Control pagesButtonsPanel; + private Size itemSize; private Button navigationButtonLeft; private Button navigationButtonRight; private Padding padding; - internal List pagesButtons = new List(); - private Control pagesButtonsPanel; private int selectedIndex = -1; - internal int tabPageCount = 0; - internal int tabViewIndex = 0; - - private bool AllButtonsRendered + public TabControl() { - get - { - if (pagesButtons.Count == 0) return true; - var lastButton = pagesButtons.Last(); + Controls = new ControlCollection(this); + TabPages = new TabPageCollection(this); - return lastButton.Location.X + lastButton.Width < pagesButtonsPanel.Width; - } + BorderColor = Color.FromArgb(172, 172, 172); + ItemSize = new Size(42, 30); + Padding = new Padding(3); + + pagesButtonsPanel = new Control(); + pagesButtonsPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + pagesButtonsPanel.BackColor = Color.Transparent; + pagesButtonsPanel.Name = "buttonsPanel"; + pagesButtonsPanel.Size = new Size(Width, ItemSize.Height); + + Controls.AddInternal(pagesButtonsPanel); } + public Color BorderColor { get; set; } public new ControlCollection Controls { get; private set; } public new Rectangle DisplayRectangle @@ -43,18 +49,6 @@ private bool AllButtonsRendered Height - ItemSize.Height - Padding.Vertical); } } - private int HeaderWidth - { - get - { - int w = 0; - - for (int i = 0; i < pagesButtons.Count; i++) - w += pagesButtons[i].Width; - - return w; - } - } public Size ItemSize { get { return itemSize; } @@ -64,22 +58,6 @@ public Size ItemSize UpdateSizes(); } } - private int MaxVisibleTabIndex - { - get - { - if (navigationButtonLeft == null) - return tabPageCount; - - for (int i = tabViewIndex, vItems = 0; i < pagesButtons.Count; i++, vItems++) - { - bool isVisible = pagesButtons[i].Location.X < navigationButtonLeft.Location.X; - if (isVisible == false) - return vItems; - } - return tabPageCount; - } - } public new Padding Padding { get { return padding; } @@ -108,25 +86,50 @@ public TabPage SelectedTab } } public int TabCount { get { return tabPageCount; } } - public TabControl.TabPageCollection TabPages { get; private set; } + public TabPageCollection TabPages { get; private set; } - public TabControl() + protected override Size DefaultSize { - Controls = new ControlCollection(this); - TabPages = new TabPageCollection(this); + get { return new Size(200, 100); } + } - BorderColor = Color.FromArgb(172, 172, 172); - ItemSize = new Size(42, 30); - Padding = new Padding(3); - Size = new Size(200, 100); + private bool AllButtonsRendered + { + get + { + if (pagesButtons.Count == 0) return true; + var lastButton = pagesButtons.Last(); - pagesButtonsPanel = new Control(); - pagesButtonsPanel.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; - pagesButtonsPanel.BackColor = Color.Transparent; - pagesButtonsPanel.Name = "buttonsPanel"; - pagesButtonsPanel.Size = new Size(Width, ItemSize.Height); + return lastButton.Location.X + lastButton.Width < pagesButtonsPanel.Width; + } + } + private int HeaderWidth + { + get + { + int w = 0; - (Controls as ControlCollection).AddInternal(pagesButtonsPanel); + for (int i = 0; i < pagesButtons.Count; i++) + w += pagesButtons[i].Width; + + return w; + } + } + private int MaxVisibleTabIndex + { + get + { + if (navigationButtonLeft == null) + return tabPageCount; + + for (int i = tabViewIndex, vItems = 0; i < pagesButtons.Count; i++, vItems++) + { + bool isVisible = pagesButtons[i].Location.X < navigationButtonLeft.Location.X; + if (isVisible == false) + return vItems; + } + return tabPageCount; + } } public void SelectTab(int index) @@ -136,7 +139,7 @@ public void SelectTab(int index) selectedIndex = index; if (selectedIndex == -1) return; - if (selectedIndex >= TabPages.Count) throw new ArgumentOutOfRangeException("tabControl.selectedIndex"); + if (selectedIndex >= TabPages.Count) throw new ArgumentOutOfRangeException("index"); pagesButtons[selectedIndex].Show(); TabPages[index].Visible = true; @@ -161,6 +164,96 @@ public void SetPageButtonWidth(int index, int width) UpdateButtons(); } + internal int AddTabPage(TabPage tabPage) + { + TabPageButton pageButton = new TabPageButton(this, tabPageCount); + pageButton.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; + pageButton.uwfBorderHoverColor = Color.Transparent; + pageButton.uwfBorderColor = Color.Transparent; + pageButton.Location = new Point(tabPageCount * pageButton.Width - tabPageCount, 0); + pageButton.Height = ItemSize.Height; + pageButton.Text = tabPage.Text; + pageButton.Hide(); + + pagesButtonsPanel.Controls.Add(pageButton); + pagesButtons.Add(pageButton); + + tabPageCount++; + + if (TabPages.Count > 0 && SelectedIndex == -1) + SelectTab(0); + + return tabPageCount; + } + internal int FindTabPage(TabPage tabPage) + { + if (TabPages != null) + for (int i = 0; i < tabPageCount; i++) + if (TabPages[i].Equals(tabPage)) + return i; + + return -1; + } + internal void HideSelectedPage() + { + if (selectedIndex == -1) return; + if (selectedIndex >= TabPages.Count) return; + + pagesButtons[selectedIndex].Hide(); + TabPages[selectedIndex].Visible = false; + } + internal void RemoveTabPage(int index) + { + if (index < 0 || index >= tabPageCount) + throw new ArgumentException("tabControl.RemoveTabPage(index)"); + + tabPageCount--; + + TabPages.RemoveAt(index); + Controls.Remove(pagesButtons[index]); + pagesButtons.RemoveAt(index); + + if (selectedIndex == tabPageCount) + SelectedIndex = tabPageCount - 1; + + SelectTab(SelectedIndex); + UpdateButtons(); + } + internal void UpdateButtons() + { + if (navigationButtonLeft == null || navigationButtonRight == null) + { + for (int i = 0; i < pagesButtons.Count; i++) + pagesButtons[i].Visible = true; + } + else + { + for (int i = 0; i < tabViewIndex; i++) + pagesButtons[i].Visible = false; + for (int i = tabViewIndex, locX = 0; i < pagesButtons.Count; i++) + { + pagesButtons[i].Location = new Point(locX, pagesButtons[i].Location.Y); + if (pagesButtons[i].Location.X < pagesButtonsPanel.Width) + pagesButtons[i].Visible = true; + else + pagesButtons[i].Visible = false; + + locX += pagesButtons[i].Width - 1; + } + } + } + internal void UpdateSizes() + { + for (int i = 0; i < TabPages.Count; i++) + { + var page = TabPages[i]; + page.Location = DisplayRectangle.Location; + page.Size = new Size(DisplayRectangle.Width, DisplayRectangle.Height); + } + if (pagesButtonsPanel != null) + pagesButtonsPanel.Height = ItemSize.Height; + } + protected override void OnPaint(PaintEventArgs e) { e.Graphics.uwfFillRectangle(BackColor, 0, 0, Width, Height); @@ -195,28 +288,28 @@ protected override void OnResize(EventArgs e) base.OnResize(e); CheckNavButtons(); } - - internal int AddTabPage(TabPage tabPage) + protected void RemoveAll() { - TabPageButton pageButton = new TabPageButton(this, tabPageCount); - pageButton.Anchor = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Bottom; - pageButton.uwfBorderHoverColor = Color.Transparent; - pageButton.uwfBorderColor = Color.Transparent; - pageButton.Location = new Point(tabPageCount * pageButton.Width - tabPageCount, 0); - pageButton.Height = ItemSize.Height; - pageButton.Text = tabPage.Text; - pageButton.Hide(); - - pagesButtonsPanel.Controls.Add(pageButton); - pagesButtons.Add(pageButton); + tabPageCount = 0; + selectedIndex = -1; - tabPageCount++; + for (int i = 0; i < pagesButtons.Count; i++) + pagesButtons[i].Dispose(); + pagesButtons.Clear(); - if (TabPages.Count > 0 && SelectedIndex == -1) - SelectTab(0); + for (int i = 0; i < Controls.Count; i++) + if (Controls[i] is TabPage) + { + Controls[i].Dispose(); + i--; + } - return tabPageCount; + navigationButtonLeft.Dispose(); + navigationButtonRight.Dispose(); + navigationButtonLeft = null; + navigationButtonRight = null; } + private void CheckNavButtons() { if (HeaderWidth > Width) @@ -254,8 +347,8 @@ private void CheckNavButtons() UpdateButtons(); }; - (Controls as ControlCollection).AddInternal(navigationButtonLeft); - (Controls as ControlCollection).AddInternal(navigationButtonRight); + Controls.AddInternal(navigationButtonLeft); + Controls.AddInternal(navigationButtonRight); pagesButtonsPanel.Width = navigationButtonLeft.Location.X - 2; } @@ -276,99 +369,10 @@ private void CheckNavButtons() UpdateButtons(); } - internal int FindTabPage(TabPage tabPage) - { - if (TabPages != null) - for (int i = 0; i < tabPageCount; i++) - if (TabPages[i].Equals(tabPage)) - return i; - - return -1; - } - internal void HideSelectedPage() - { - if (selectedIndex == -1) return; - if (selectedIndex >= TabPages.Count) return; - - pagesButtons[selectedIndex].Hide(); - TabPages[selectedIndex].Visible = false; - } - internal void RemoveTabPage(int index) - { - if (index < 0 || index >= tabPageCount) - throw new ArgumentException("tabControl.RemoveTabPage(index)"); - - tabPageCount--; - - TabPages.RemoveAt(index); - Controls.Remove(pagesButtons[index]); - pagesButtons.RemoveAt(index); - - if (selectedIndex == tabPageCount) - SelectedIndex = tabPageCount - 1; - - SelectTab(SelectedIndex); - UpdateButtons(); - } - protected void RemoveAll() - { - tabPageCount = 0; - selectedIndex = -1; - - for (int i = 0; i < pagesButtons.Count; i++) - pagesButtons[i].Dispose(); - pagesButtons.Clear(); - - for (int i = 0; i < Controls.Count; i++) - if (Controls[i] is TabPage) - { - Controls[i].Dispose(); - i--; - } - - navigationButtonLeft.Dispose(); - navigationButtonRight.Dispose(); - navigationButtonLeft = null; - navigationButtonRight = null; - } - internal void UpdateButtons() - { - if (navigationButtonLeft == null || navigationButtonRight == null) - { - for (int i = 0; i < pagesButtons.Count; i++) - pagesButtons[i].Visible = true; - } - else - { - for (int i = 0; i < tabViewIndex; i++) - pagesButtons[i].Visible = false; - for (int i = tabViewIndex, locX = 0; i < pagesButtons.Count; i++) - { - pagesButtons[i].Location = new Point(locX, pagesButtons[i].Location.Y); - if (pagesButtons[i].Location.X < pagesButtonsPanel.Width) - pagesButtons[i].Visible = true; - else - pagesButtons[i].Visible = false; - - locX += pagesButtons[i].Width - 1; - } - } - } - internal void UpdateSizes() - { - for (int i = 0; i < TabPages.Count; i++) - { - var page = TabPages[i]; - page.Location = DisplayRectangle.Location; - page.Size = new Size(DisplayRectangle.Width, DisplayRectangle.Height); - } - if (pagesButtonsPanel != null) - pagesButtonsPanel.Height = ItemSize.Height; - } public new class ControlCollection : Control.ControlCollection { - private TabControl owner; + private readonly TabControl owner; public ControlCollection(TabControl owner) : base(owner) { @@ -410,9 +414,9 @@ internal void AddInternal(Control value) base.Add(value); } } - public class TabPageCollection : IList, ICollection, IEnumerable + public class TabPageCollection : IList { - private TabControl owner; + private readonly TabControl owner; public TabPageCollection(TabControl owner) { @@ -422,6 +426,40 @@ public TabPageCollection(TabControl owner) public int Count { get { return owner.tabPageCount; } } public bool IsReadOnly { get { return false; } } + bool IList.IsFixedSize + { + get + { + throw new NotImplementedException(); + } + } + bool ICollection.IsSynchronized + { + get + { + throw new NotImplementedException(); + } + } + object ICollection.SyncRoot + { + get + { + throw new NotImplementedException(); + } + } + object IList.this[int index] + { + get + { + throw new NotImplementedException(); + } + + set + { + throw new NotImplementedException(); + } + } + public virtual TabPage this[int index] { get @@ -574,40 +612,6 @@ public virtual void RemoveByKey(string key) RemoveAt(index); } - bool IList.IsFixedSize - { - get - { - throw new NotImplementedException(); - } - } - bool ICollection.IsSynchronized - { - get - { - throw new NotImplementedException(); - } - } - object ICollection.SyncRoot - { - get - { - throw new NotImplementedException(); - } - } - object IList.this[int index] - { - get - { - throw new NotImplementedException(); - } - - set - { - throw new NotImplementedException(); - } - } - int IList.Add(object value) { if (value is TabPage == false) throw new ArgumentException("tabPageCollection.Add(value is not TabPage)"); @@ -649,14 +653,9 @@ void ICollection.CopyTo(Array array, int index) internal class TabPageButton : Button { - private TabControl owner; - private int index; - private bool hidden = false; - - public Color EnabledBackColor { get; set; } - public Color EnabledBackHoverColor { get; set; } - public Color DisabledBackColor { get; set; } - public Color DisabledBackHoverColor { get; set; } + private readonly TabControl owner; + private readonly int index; + private bool hidden; public TabPageButton(TabControl owner, int index) { @@ -672,6 +671,11 @@ public TabPageButton(TabControl owner, int index) Click += TabPageButton_Click; } + public Color EnabledBackColor { get; set; } + public Color EnabledBackHoverColor { get; set; } + public Color DisabledBackColor { get; set; } + public Color DisabledBackHoverColor { get; set; } + public void Hide() { hidden = true; @@ -700,11 +704,6 @@ public void Update() } } - private void TabPageButton_Click(object sender, EventArgs e) - { - owner.SelectTab(index); - } - protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); @@ -714,14 +713,11 @@ protected override void OnPaint(PaintEventArgs e) e.Graphics.DrawLine(borderPen, 0, 0, Width, 0); // Top. e.Graphics.DrawLine(borderPen, 0, 0, 0, Height - 1); // Left. e.Graphics.DrawLine(borderPen, Width - 1, 0, Width - 1, Height - 1); // Right. - if (hidden == false) - { - - } - else - { + } - } + private void TabPageButton_Click(object sender, EventArgs e) + { + owner.SelectTab(index); } } } diff --git a/System/Windows/Forms/TabPage.cs b/System/Windows/Forms/TabPage.cs index 6a2855e..48a65e6 100644 --- a/System/Windows/Forms/TabPage.cs +++ b/System/Windows/Forms/TabPage.cs @@ -1,16 +1,9 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { + using System.Drawing; + public class TabPage : Panel { - public int ImageIndex { get; set; } - public string ImageKey { get; set; } - public TabPage() { BackColor = Color.White; @@ -19,5 +12,8 @@ public TabPage(string text) { Text = text; } + + public int ImageIndex { get; set; } + public string ImageKey { get; set; } } } diff --git a/System/Windows/Forms/TextBox.cs b/System/Windows/Forms/TextBox.cs index 7c5d5f2..09b3925 100644 --- a/System/Windows/Forms/TextBox.cs +++ b/System/Windows/Forms/TextBox.cs @@ -17,7 +17,6 @@ public TextBox() BorderHoverColor = Color.FromArgb(126, 180, 234); ForeColor = Color.Black; Padding = new Padding(2, 0, 2, 0); - Size = new Size(128, 24); TextAlign = HorizontalAlignment.Left; } @@ -41,6 +40,11 @@ public override string Text } public HorizontalAlignment TextAlign { get; set; } + protected override Size DefaultSize + { + get { return new Size(100, 24); } + } + protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); diff --git a/System/Windows/Forms/ToolStrip.cs b/System/Windows/Forms/ToolStrip.cs index a589810..4d723f0 100644 --- a/System/Windows/Forms/ToolStrip.cs +++ b/System/Windows/Forms/ToolStrip.cs @@ -1,43 +1,40 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Drawing; - -namespace System.Windows.Forms +namespace System.Windows.Forms { - [Serializable] + using System.Drawing; + public class ToolStrip : ScrollableControl { private readonly SolidBrush brushBack = new SolidBrush(Color.Transparent); private readonly Pen borderPen = new Pen(Color.Transparent); - private readonly ToolStripItemCollection _items; + private readonly ToolStripItemCollection items; private readonly PaintEventArgs p_args; private readonly Pen verticalLinePen = new Pen(Color.FromArgb(215, 215, 215)); public ToolStrip() { - _items = new ToolStripItemCollection(this, null); + items = new ToolStripItemCollection(this, null); p_args = new PaintEventArgs(); BackColor = Color.FromArgb(246, 246, 246); BorderColor = Color.FromArgb(204, 206, 219); - Orientation = Forms.Orientation.Vertical; + Orientation = Orientation.Vertical; uwfAppOwner.UpClick += Application_UpClick; } public ToolStrip(ToolStripItem[] items) { - _items = new ToolStripItemCollection(this, items); - _items.AddRange(items); + this.items = new ToolStripItemCollection(this, items); + this.items.AddRange(items); BackColor = Color.FromArgb(246, 246, 246); BorderColor = Color.FromArgb(204, 206, 219); - Orientation = Forms.Orientation.Vertical; + Orientation = Orientation.Vertical; uwfAppOwner.UpClick += Application_UpClick; } + public event ToolStripItemClickedEventHandler ItemClicked = delegate { }; + public override Color BackColor { get { return brushBack.Color; } @@ -48,39 +45,35 @@ public Color BorderColor get { return borderPen.Color; } set { borderPen.Color = value; } } - public virtual ToolStripItemCollection Items { get { return _items; } } + public virtual ToolStripItemCollection Items { get { return items; } } public Orientation Orientation { get; set; } + internal ToolStripItem OwnerItem { get; set; } - void Application_UpClick(object sender, EventArgs e) + protected override Size DefaultSize { - bool reset = true; - var toolStrip = sender as ToolStrip; - if (toolStrip != null) - { - if (toolStrip.OwnerItem != null) - { - var parent = toolStrip.OwnerItem.Parent; - while (true) - { - if (parent == null) break; - if (parent == this) - { - reset = false; - break; - } - - if (parent.OwnerItem == null) break; + get { return new Size(100, 25); } + } - parent = parent.OwnerItem.Parent; - } - } - } + public void ResetSelected() + { + for (int i = 0; i < items.Count; i++) + items[i].Selected = false; + } - var mc_pos = PointToClient(MousePosition); - if (!ClientRectangle.Contains(mc_pos) && reset) - for (int i = 0; i < _items.Count; i++) - _items[i].Selected = false; + /// + /// For menu strips. + /// + internal void MakeShadow() + { + uwfShadowHandler = (g) => + { + var loc = PointToScreen(Point.Empty); + var color = Color.FromArgb(12, 64, 64, 64); + g.Graphics.uwfFillRectangle(color, loc.X - 3, loc.Y, Width + 6, Height + 3); + g.Graphics.uwfFillRectangle(color, loc.X - 2, loc.Y, Width + 4, Height + 2); + g.Graphics.uwfFillRectangle(color, loc.X - 1, loc.Y, Width + 2, Height + 1); + }; } protected override void Dispose(bool release_all) @@ -93,27 +86,27 @@ protected override void OnMouseHover(EventArgs e) base.OnMouseHover(e); var mc_pos = ((MouseEventArgs)e).Location; - for (int i = 0, x = Padding.Left, y = Padding.Top; i < _items.Count; i++) + for (int i = 0, x = Padding.Left, y = Padding.Top; i < items.Count; i++) { - if (_items[i].JustVisual) continue; + if (items[i].JustVisual) continue; - _items[i].RaiseOnMouseLeave(e); - if (mc_pos.X > x && mc_pos.X < x + _items[i].Width && mc_pos.Y > y && mc_pos.Y < y + _items[i].Height) - _items[i].RaiseOnMouseEnter(e); + items[i].RaiseOnMouseLeave(e); + if (mc_pos.X > x && mc_pos.X < x + items[i].Width && mc_pos.Y > y && mc_pos.Y < y + items[i].Height) + items[i].RaiseOnMouseEnter(e); - if (Orientation == Forms.Orientation.Horizontal) - x += _items[i].Width; - if (Orientation == Forms.Orientation.Vertical) - y += _items[i].Height; + if (Orientation == Orientation.Horizontal) + x += items[i].Width; + if (Orientation == Orientation.Vertical) + y += items[i].Height; } } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); - for (int i = 0; i < _items.Count; i++) + for (int i = 0; i < items.Count; i++) { - if (_items[i].JustVisual) continue; - _items[i].RaiseOnMouseLeave(e); + if (items[i].JustVisual) continue; + items[i].RaiseOnMouseLeave(e); } } protected override void OnMouseUp(MouseEventArgs e) // Click. @@ -121,31 +114,31 @@ protected override void OnMouseUp(MouseEventArgs e) // Click. base.OnMouseUp(e); int prevSelected = -1; - for (int i = 0; i < _items.Count; i++) + for (int i = 0; i < items.Count; i++) { - if (_items[i].Selected) prevSelected = i; - _items[i].Selected = false; + if (items[i].Selected) prevSelected = i; + items[i].Selected = false; } var mc_pos = e.Location; - for (int i = 0, x = Padding.Left, y = Padding.Top; i < _items.Count; i++) + for (int i = 0, x = Padding.Left, y = Padding.Top; i < items.Count; i++) { - if (_items[i].JustVisual) continue; + if (items[i].JustVisual) continue; - if (mc_pos.X > x && mc_pos.X < x + _items[i].Width && mc_pos.Y > y && mc_pos.Y < y + _items[i].Height) + if (mc_pos.X > x && mc_pos.X < x + items[i].Width && mc_pos.Y > y && mc_pos.Y < y + items[i].Height) { if (i != prevSelected) - _items[i].Selected = true; + items[i].Selected = true; - ItemClicked(this, new ToolStripItemClickedEventArgs(_items[i])); - _items[i].RaiseOnMouseUp(e); + ItemClicked(this, new ToolStripItemClickedEventArgs(items[i])); + items[i].RaiseOnMouseUp(e); break; } - if (Orientation == Forms.Orientation.Horizontal) - x += _items[i].Width; - if (Orientation == Forms.Orientation.Vertical) - y += _items[i].Height; + if (Orientation == Orientation.Horizontal) + x += items[i].Width; + if (Orientation == Orientation.Vertical) + y += items[i].Height; } } protected override void OnKeyDown(KeyEventArgs e) @@ -161,7 +154,7 @@ protected override void OnKeyDown(KeyEventArgs e) } protected override void OnPaint(PaintEventArgs e) { - if (OwnerItem != null && OwnerItem.Parent != null && OwnerItem.Parent.Orientation == Forms.Orientation.Horizontal && uwfShadowHandler == null) + if (OwnerItem != null && OwnerItem.Parent != null && OwnerItem.Parent.Orientation == Orientation.Horizontal && uwfShadowHandler == null) { MakeShadow(); } @@ -172,46 +165,54 @@ protected override void OnPaint(PaintEventArgs e) p_args.ClipRectangle = e.ClipRectangle; p_args.Graphics.FillRectangle(brushBack, 0, 0, Width, Height); - if (Orientation == Forms.Orientation.Vertical) + if (Orientation == Orientation.Vertical) p_args.Graphics.DrawLine(verticalLinePen, 30, 2, 30, Height - 2); - for (int i = 0, x = Padding.Left, y = Padding.Top; i < _items.Count; i++) + for (int i = 0, x = Padding.Left, y = Padding.Top; i < items.Count; i++) { - var item = _items[i]; - p_args.ClipRectangle = new Drawing.Rectangle(x, y, item.Width, item.Height); + var item = items[i]; + p_args.ClipRectangle = new Rectangle(x, y, item.Width, item.Height); item.RaiseOnPaint(p_args); if (item.JustVisual) continue; - if (Orientation == Forms.Orientation.Horizontal) + if (Orientation == Orientation.Horizontal) x += item.Width; - if (Orientation == Forms.Orientation.Vertical) + if (Orientation == Orientation.Vertical) y += item.Height; } p_args.Graphics.DrawRectangle(borderPen, 0, 0, Width, Height); } - public event ToolStripItemClickedEventHandler ItemClicked = delegate { }; - - public void ResetSelected() - { - for (int i = 0; i < _items.Count; i++) - _items[i].Selected = false; - } - - /// - /// For menu strips. - /// - internal void MakeShadow() + private void Application_UpClick(object sender, EventArgs e) { - uwfShadowHandler = (g) => + bool reset = true; + var toolStrip = sender as ToolStrip; + if (toolStrip != null) { - var loc = PointToScreen(Point.Empty); - var color = Color.FromArgb(12, 64, 64, 64); - g.Graphics.uwfFillRectangle(color, loc.X - 3, loc.Y, Width + 6, Height + 3); - g.Graphics.uwfFillRectangle(color, loc.X - 2, loc.Y, Width + 4, Height + 2); - g.Graphics.uwfFillRectangle(color, loc.X - 1, loc.Y, Width + 2, Height + 1); - }; + if (toolStrip.OwnerItem != null) + { + var parent = toolStrip.OwnerItem.Parent; + while (true) + { + if (parent == null) break; + if (parent == this) + { + reset = false; + break; + } + + if (parent.OwnerItem == null) break; + + parent = parent.OwnerItem.Parent; + } + } + } + + var mc_pos = PointToClient(MousePosition); + if (!ClientRectangle.Contains(mc_pos) && reset) + for (int i = 0; i < items.Count; i++) + items[i].Selected = false; } } } diff --git a/System/Windows/Forms/TreeView.cs b/System/Windows/Forms/TreeView.cs index f2223c3..7c5bb09 100644 --- a/System/Windows/Forms/TreeView.cs +++ b/System/Windows/Forms/TreeView.cs @@ -47,7 +47,6 @@ public TreeView() ScrollSpeed = 2; SelectionColor = Color.FromArgb(187, 222, 251); SelectionHoverColor = Color.FromArgb(221, 238, 253); - Size = new Size(121, 97); SmoothScrolling = true; Nodes = new TreeNodeCollection(root); @@ -84,6 +83,11 @@ public Color BorderColor internal float ScrollIndex { get { return vScrollBar.Value; } set { vScrollBar.Value = (int)value; } } + protected override Size DefaultSize + { + get { return new Size(121, 97); } + } + public void CollapseAll() { var nodesCount = Nodes.Count; diff --git a/System/Windows/Forms/VScrollBar.cs b/System/Windows/Forms/VScrollBar.cs index 7c93c9e..b251051 100644 --- a/System/Windows/Forms/VScrollBar.cs +++ b/System/Windows/Forms/VScrollBar.cs @@ -9,7 +9,6 @@ public class VScrollBar : ScrollBar public VScrollBar() { scrollOrientation = ScrollOrientation.VerticalScroll; - Size = new Size(15, 80); subtractButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; subtractButton.Image = uwfAppOwner.Resources.CurvedArrowUp; @@ -23,5 +22,10 @@ public VScrollBar() UpdateScrollRect(); } + + protected override Size DefaultSize + { + get { return new Size(15, 80); } + } } }