Skip to content

Commit

Permalink
Added mouse hold feature to increase and decrease MetroSetNumeric val…
Browse files Browse the repository at this point in the history
…ue, Fix #20, Fix #22
  • Loading branch information
N-a-r-w-i-n committed Oct 18, 2019
1 parent 9675647 commit 0555d16
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 118 deletions.
9 changes: 4 additions & 5 deletions MetroSet UI Example/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 49 additions & 16 deletions MetroSet UI/Controls/MetroSetNumeric.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Timer = System.Timers.Timer;

namespace MetroSet_UI.Controls
{
Expand Down Expand Up @@ -114,6 +115,7 @@ public StyleManager StyleManager
private StyleManager _styleManager;
private Point _point;
private int _value;
private readonly Timer _holdTimer;

#endregion Internal Vars

Expand All @@ -132,6 +134,13 @@ public MetroSetNumeric()
_utl = new Utilites();
ApplyTheme();
_point = new Point(0, 0);
_holdTimer = new Timer()
{
Interval = 10,
AutoReset = true,
Enabled = false
};
_holdTimer.Elapsed += HoldTimer_Tick;
}

#endregion Constructors
Expand Down Expand Up @@ -294,7 +303,7 @@ public int Value
}

[Browsable(false)]
public override Color BackColor => Color.Transparent;
public sealed override Color BackColor => Color.Transparent;

/// <summary>
/// Gets or sets the control backcolor.
Expand Down Expand Up @@ -351,11 +360,10 @@ protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
_point = e.Location;
if (_point.X > Width - 50)
{
Cursor = Cursors.Hand;
}
Invalidate();
Cursor = _point.X > Width - 50 ? Cursors.Hand : Cursors.IBeam;


}

/// <summary>
Expand All @@ -365,17 +373,7 @@ protected override void OnMouseMove(MouseEventArgs e)
protected override void OnClick(EventArgs e)
{
base.OnClick(e);
if (_point.X <= Width - 45 || _point.X >= Width - 3) return;
if (_point.X > Width - 45 && _point.X < Width - 25)
{
if (Value + 1 <= Maximum)
Value += 1;
}
else
{
if (Value - 1 >= Minimum)
Value -= 1;
}
Revaluate();
}

/// <summary>
Expand Down Expand Up @@ -404,7 +402,42 @@ protected override void OnResize(EventArgs e)
Height = 26;
}

protected override void OnMouseDown(MouseEventArgs e)
{
base.OnMouseDown(e);
if (_point.X <= Width - 45 || _point.X >= Width - 3) return;
if (e.Button == MouseButtons.Left)
{
_holdTimer.Enabled = true;
}

Invalidate();
}

protected override void OnMouseUp(MouseEventArgs e)
{
_holdTimer.Enabled = false;
}

private void HoldTimer_Tick(object sender, EventArgs args)
{
Revaluate();
}

private void Revaluate()
{
if (_point.X <= Width - 45 || _point.X >= Width - 3) return;
if (_point.X > Width - 45 && _point.X < Width - 25)
{
if (Value + 1 <= Maximum)
Value += 1;
}
else
{
if (Value - 1 >= Minimum)
Value -= 1;
}
}

#endregion

Expand Down
32 changes: 7 additions & 25 deletions MetroSet UI/Controls/MetroSetRichTextBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,31 +126,6 @@ public StyleManager StyleManager

private RichTextBox T = new RichTextBox();

private RichTextBox _T
{
get => _T;
set
{
if (_T != null)
{
_T.MouseHover -= T_MouseHover;
_T.MouseUp -= T_MouseUp;
_T.MouseLeave -= T_Leave;
_T.MouseEnter -= T_Enter;
_T.KeyDown -= T_KeyDown;
_T.TextChanged -= T_TextChanged;
}
_T = value;
if (_T == null) return;
_T.MouseHover += T_MouseHover;
_T.MouseUp += T_MouseUp;
_T.Leave += T_Leave;
_T.Enter += T_Enter;
_T.KeyDown += T_KeyDown;
_T.TextChanged += T_TextChanged;
}
}

#endregion Base RichTextBox

#endregion Internal Vars
Expand Down Expand Up @@ -196,6 +171,13 @@ private void T_Defaults()
T.Font = Font;
T.Size = new Size(Width, Height);

T.MouseHover += T_MouseHover;
T.MouseUp += T_MouseUp;
T.Leave += T_Leave;
T.Enter += T_Enter;
T.KeyDown += T_KeyDown;
T.TextChanged += T_TextChanged;

}

#endregion Constructors
Expand Down
Loading

0 comments on commit 0555d16

Please sign in to comment.