diff --git a/Business/Menus.cs b/Business/Menus.cs index c09082c..756b73d 100644 --- a/Business/Menus.cs +++ b/Business/Menus.cs @@ -215,8 +215,15 @@ namespace SystemTrayMenu.Business keyboardInput.ClosePressed += MenusFadeOut; keyboardInput.RowDeselected += waitToOpenMenu.RowDeselected; - keyboardInput.RowSelected += waitToOpenMenu.RowSelected; keyboardInput.EnterPressed += waitToOpenMenu.EnterOpensInstantly; + keyboardInput.RowSelected += waitToOpenMenu.RowSelected; + keyboardInput.RowSelected += AdjustScrollbarToDisplayedRow; + void AdjustScrollbarToDisplayedRow(DataGridView dgv, int index) + { +#warning to improve arguments, do not use .Parent.Parent.Parent + Menu menu = dgv.Parent.Parent.Parent as Menu; + menu.AdjustScrollbar(); + } timerStillActiveCheck.Interval = 1000; timerStillActiveCheck.Tick += StillActiveTick; @@ -669,6 +676,7 @@ namespace SystemTrayMenu.Business dgv.DataSource = dataTable; dgv.Columns["data"].Visible = false; + dgv.Columns["SortIndex"].Visible = false; } DataGridView dgv = menu.GetDataGridView(); @@ -783,7 +791,7 @@ namespace SystemTrayMenu.Business if (!searchTextChanging) { - dgv.Refresh(); + dgv.Invalidate(); } } @@ -947,6 +955,11 @@ namespace SystemTrayMenu.Business { menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation); } +#warning workaround added also as else, because need adjust scrollbar after search + else + { + menu.AdjustSizeAndLocation(screenBounds, menuPredecessor, startLocation); + } if (i == 0) { diff --git a/Business/WaitToLoadMenu.cs b/Business/WaitToLoadMenu.cs index c317a41..7b53f23 100644 --- a/Business/WaitToLoadMenu.cs +++ b/Business/WaitToLoadMenu.cs @@ -201,10 +201,13 @@ namespace SystemTrayMenu.Handler if (dgv != null && dgv.Rows.Count > rowIndex) { RowData rowData = (RowData)dgv.Rows[rowIndex].Cells[2].Value; - rowData.IsSelected = false; - dgv.Rows[rowIndex].Selected = false; - this.dgv = null; - this.rowIndex = 0; + if (rowData != null) + { + rowData.IsSelected = false; + dgv.Rows[rowIndex].Selected = false; + this.dgv = null; + this.rowIndex = 0; + } } } } diff --git a/Config/MenuDefines.cs b/Config/MenuDefines.cs index 206abe3..6d1517e 100644 --- a/Config/MenuDefines.cs +++ b/Config/MenuDefines.cs @@ -10,7 +10,7 @@ namespace SystemTrayMenu { internal const int MenusMax = 50; internal const int LengthMax = 37; - internal const int Scrollspeed = 4; + internal const int Scrollspeed = 3; public static Color ColorSelectedItem { diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index bb85c3b..a9f8108 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -39,5 +39,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.17.56")] -[assembly: AssemblyFileVersion("1.0.17.56")] +[assembly: AssemblyVersion("1.0.17.57")] +[assembly: AssemblyFileVersion("1.0.17.57")] diff --git a/SystemTrayMenu.csproj b/SystemTrayMenu.csproj index 75f2e4a..8eb1e75 100644 --- a/SystemTrayMenu.csproj +++ b/SystemTrayMenu.csproj @@ -114,6 +114,7 @@ AboutBox.cs + SettingsForm.cs diff --git a/UserInterface/CustomScrollbar/CustomScrollbar.cs b/UserInterface/CustomScrollbar/CustomScrollbar.cs new file mode 100644 index 0000000..a6676e6 --- /dev/null +++ b/UserInterface/CustomScrollbar/CustomScrollbar.cs @@ -0,0 +1,805 @@ +// +// Copyright (c) PlaceholderCompany. All rights reserved. +// + +namespace SystemTrayMenu.UserInterface +{ + using System; + using System.ComponentModel; + using System.Diagnostics; + using System.Drawing; + using System.Windows.Forms; + using System.Windows.Forms.Design; + + [Designer(typeof(ScrollbarControlDesigner))] + public class CustomScrollbar : UserControl + { + private readonly Timer timerMouseStillClicked = new Timer(); + private readonly int arrowHeight = 18; + private readonly int controlWidth = 15; + + private float moLargeChange = 10; + private float moSmallChange = 1; + private int moMinimum = 0; + private int moMaximum = 100; + private int moValue = 0; + private int nClickPoint; + + private float moSliderTop = 0; + private bool moSliderDown = false; + private bool moSliderDragging = false; + private bool arrowUpHovered = false; + private bool sliderHovered = false; + private bool arrowDownHovered = false; + private bool mouseStillClickedMoveUp = false; + private bool mouseStillClickedMoveLarge; + private int timerMouseStillClickedCounter = 0; + private int lastValue = 0; + private bool paintEnabledWasCalled = false; + private bool paintEnabled = false; + + public CustomScrollbar() + { + InitializeComponent(); + SetStyle(ControlStyles.ResizeRedraw, true); + SetStyle(ControlStyles.AllPaintingInWmPaint, true); + SetStyle(ControlStyles.DoubleBuffer, true); + + Width = controlWidth; + MinimumSize = new Size(controlWidth, arrowHeight + arrowHeight + GetScrollbarHeight()); + int GetScrollbarHeight() + { + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fThumbHeight = (float)LargeChange / Maximum * nTrackHeight; + int nThumbHeight = (int)fThumbHeight; + + if (nThumbHeight > nTrackHeight) + { + nThumbHeight = nTrackHeight; + } + + if (nThumbHeight < 56) + { + nThumbHeight = 56; + } + + return nThumbHeight; + } + + timerMouseStillClicked.Interval = 30; + timerMouseStillClicked.Tick += TimerMouseStillClicked_Tick; + } + + public new event EventHandler Scroll = null; + + public event EventHandler ValueChanged = null; + + [EditorBrowsable(EditorBrowsableState.Always)] + [Browsable(true)] + [DefaultValue(false)] + [Category("Behavior")] + [Description("LargeChange")] + public float LargeChange + { + get + { + return moLargeChange; + } + + set + { + moLargeChange = value; + Invalidate(); + } + } + + [EditorBrowsable(EditorBrowsableState.Always)] + [Browsable(true)] + [DefaultValue(false)] + [Category("Behavior")] + [Description("SmallChange")] + public float SmallChange + { + get + { + return moSmallChange; + } + + set + { + moSmallChange = value; + Invalidate(); + } + } + + [EditorBrowsable(EditorBrowsableState.Always)] + [Browsable(true)] + [DefaultValue(false)] + [Category("Behavior")] + [Description("Minimum")] + public int Minimum + { + get + { + return moMinimum; + } + + set + { + moMinimum = value; + Invalidate(); + } + } + + [EditorBrowsable(EditorBrowsableState.Always)] + [Browsable(true)] + [DefaultValue(false)] + [Category("Behavior")] + [Description("Maximum")] + public int Maximum + { + get + { + return moMaximum; + } + + set + { + moMaximum = value; + Invalidate(); + } + } + + [EditorBrowsable(EditorBrowsableState.Always)] + [Browsable(true)] + [DefaultValue(false)] + [Category("Behavior")] + [Description("Value")] + public int Value + { + get + { + return moValue; + } + + set + { + moValue = value; + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fThumbHeight = (float)LargeChange / Maximum * nTrackHeight; + int nThumbHeight = (int)fThumbHeight; + if (nThumbHeight > nTrackHeight) + { + nThumbHeight = nTrackHeight; + fThumbHeight = nTrackHeight; + } + + if (nThumbHeight < 56) + { + nThumbHeight = 56; + fThumbHeight = 56; + } + + int nPixelRange = nTrackHeight - nThumbHeight; + int nRealRange = Maximum - Minimum - (int)LargeChange; + float fPerc = 0.0f; + if (nRealRange != 0) + { + fPerc = moValue / (float)nRealRange; + } + + float fTop = fPerc * nPixelRange; + moSliderTop = (int)fTop; + Invalidate(); + } + } + + public int Delta + { + get + { + return Value - lastValue; + } + } + + public override bool AutoSize + { + get + { + return base.AutoSize; + } + + set + { + base.AutoSize = value; + if (base.AutoSize) + { + Width = controlWidth; + } + } + } + + public void CustomScrollbar_MouseWheel(object sender, MouseEventArgs e) + { + if (e.Delta > 0) + { + MoveUp(SmallChange * MenuDefines.Scrollspeed); + } + else + { + MoveDown(SmallChange * MenuDefines.Scrollspeed); + } + } + + internal void Reset() + { + moSliderTop = 0; + moSliderDown = false; + moSliderDragging = false; + arrowUpHovered = false; + sliderHovered = false; + arrowDownHovered = false; + mouseStillClickedMoveUp = false; + mouseStillClickedMoveLarge = false; + timerMouseStillClickedCounter = 0; + lastValue = 0; + } + + /// + /// Show the control + /// (workaround, because visible = false, was causing appearing scrollbars). + /// + internal void PaintEnable() + { + Enabled = true; + if (!paintEnabled) + { + paintEnabledWasCalled = true; + } + + paintEnabled = true; + Invalidate(); + } + + /// + /// Hide the control + /// (workaround, because visible = false, was causing appearing scrollbars). + /// + internal void PaintDisable() + { + if (!paintEnabledWasCalled) + { + Enabled = false; + Size = new Size(0, 0); + } + + paintEnabled = false; + Invalidate(); + } + + protected override void Dispose(bool disposing) + { + timerMouseStillClicked.Dispose(); + base.Dispose(disposing); + } + + protected override void OnPaint(PaintEventArgs e) + { + int heightArrow = 18; + + e.Graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor; + + Color colorArrows; + Color colorArrowsHover; + Color colorSlider; + Color colorSliderHover; + Color colorSliderDragging; + Color colorScrollbarBorder; + if (Config.IsDarkMode()) + { + colorArrows = Color.FromArgb(103, 103, 103); +#warning consider as arrowHover, normally colorArrows not changes only background + colorArrowsHover = Color.FromArgb(55, 55, 55); + colorSlider = Color.FromArgb(77, 77, 77); + colorSliderHover = Color.FromArgb(122, 122, 122); + colorSliderDragging = Color.FromArgb(166, 166, 166); +#warning remove border ? replace with background + colorScrollbarBorder = Color.FromArgb(23, 23, 23); + } + else + { + colorArrows = Color.FromArgb(100, 100, 100); + colorArrowsHover = Color.FromArgb(0, 0, 0); + colorSlider = Color.FromArgb(205, 205, 205); + colorSliderHover = Color.FromArgb(166, 166, 166); + colorSliderDragging = Color.FromArgb(96, 96, 96); + colorScrollbarBorder = Color.FromArgb(255, 255, 255); + } + + if (!paintEnabled) + { + e.Graphics.FillRectangle( + new SolidBrush(colorScrollbarBorder), + new Rectangle(0, 0, Width, Height)); + return; + } + + // Draw background + Brush brushScrollbarBorder = new SolidBrush(colorScrollbarBorder); + e.Graphics.FillRectangle(brushScrollbarBorder, new Rectangle(0, 0, Width, Height)); + + // Draw arrowUp + Pen penArrowUp; + if (arrowUpHovered) + { + penArrowUp = new Pen(colorArrowsHover, 2.5F); + } + else + { + penArrowUp = new Pen(colorArrows, 2.5F); + } + + int widthDevidedBy2 = Width / 2; + int widthDevidedBy6 = Width / 6; + int widthDevidedBy2PluswidthDevidedBy8 = widthDevidedBy2 + (Width / 8); + PointF pointArrowUp1 = new PointF(widthDevidedBy2 - widthDevidedBy6, widthDevidedBy2PluswidthDevidedBy8); + PointF pointArrowUp2 = new PointF(widthDevidedBy2 + widthDevidedBy6, widthDevidedBy2PluswidthDevidedBy8); + PointF pointArrowUp3 = new PointF(widthDevidedBy2, widthDevidedBy2PluswidthDevidedBy8 - widthDevidedBy6); + PointF pointArrowUp4 = pointArrowUp1; + PointF[] curvePoints = + { + pointArrowUp1, + pointArrowUp2, + pointArrowUp3, + pointArrowUp4, + }; + e.Graphics.DrawPolygon(penArrowUp, curvePoints); + + // draw thumb + int nTrackHeight = Height - (heightArrow * 2); + float fThumbHeight = (float)LargeChange / Maximum * nTrackHeight; + int nThumbHeight = (int)fThumbHeight; + + if (nThumbHeight > nTrackHeight) + { + nThumbHeight = nTrackHeight; + fThumbHeight = nTrackHeight; + } + + if (nThumbHeight < 56) + { + nThumbHeight = 56; + fThumbHeight = 56; + } + + int nTop = (int)moSliderTop; + nTop += arrowHeight; + + SolidBrush solidBrushSlider; + if (moSliderDragging) + { + solidBrushSlider = new SolidBrush(colorSliderDragging); + } + else if (sliderHovered) + { + solidBrushSlider = new SolidBrush(colorSliderHover); + } + else + { + solidBrushSlider = new SolidBrush(colorSlider); + } + + Rectangle rectangleSlider = new Rectangle(1, nTop, Width - 2, nThumbHeight); + e.Graphics.FillRectangle(solidBrushSlider, rectangleSlider); + + // Draw arrowDown + Pen penArrowDown; + if (arrowDownHovered) + { + penArrowDown = new Pen(colorArrowsHover, 2.5F); + } + else + { + penArrowDown = new Pen(colorArrows, 2.5F); + } + + PointF pointArrowDown1 = new PointF(widthDevidedBy2 - widthDevidedBy6, Height - widthDevidedBy2PluswidthDevidedBy8); + PointF pointArrowDown2 = new PointF(widthDevidedBy2 + widthDevidedBy6, Height - widthDevidedBy2PluswidthDevidedBy8); + PointF pointArrowDown3 = new PointF(widthDevidedBy2, Height - widthDevidedBy2PluswidthDevidedBy8 + widthDevidedBy6); + PointF pointArrowDown4 = pointArrowDown1; + PointF[] curvePointsArrowDown = + { + pointArrowDown1, + pointArrowDown2, + pointArrowDown3, + pointArrowDown4, + }; + + e.Graphics.DrawPolygon(penArrowDown, curvePointsArrowDown); + } + + private void TimerMouseStillClicked_Tick(object sender, EventArgs e) + { + timerMouseStillClickedCounter++; + + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fThumbHeight = (float)LargeChange / Maximum * nTrackHeight; + int nScrollbarHeight = (int)fThumbHeight; + + if (nScrollbarHeight > nTrackHeight) + { + nScrollbarHeight = nTrackHeight; + } + + if (nScrollbarHeight < 56) + { + nScrollbarHeight = 56; + } + + int nTop = (int)moSliderTop; + nTop += arrowHeight; + Point ptPoint = PointToClient(Cursor.Position); + Rectangle thumbrect = new Rectangle(new Point(0, nTop), new Size(controlWidth + 1, nScrollbarHeight)); + if (thumbrect.Contains(ptPoint)) + { + timerMouseStillClicked.Stop(); + } + else if (timerMouseStillClickedCounter > 6) + { + float change; + if (mouseStillClickedMoveLarge) + { + change = SmallChange * MenuDefines.Scrollspeed; + } + else + { + change = SmallChange; + } + + if (mouseStillClickedMoveUp) + { + MoveUp(change); + } + else + { + MoveDown(change); + } + } + } + + private void InitializeComponent() + { + SuspendLayout(); + Name = "CustomScrollbar"; + MouseDown += CustomScrollbar_MouseDown; + MouseMove += CustomScrollbar_MouseMove; + MouseUp += CustomScrollbar_MouseUp; + MouseLeave += CustomScrollbar_MouseLeave; + + // this.MouseWheel += CustomScrollbar_MouseWheel; + ResumeLayout(false); + } + + private void CustomScrollbar_MouseLeave(object sender, EventArgs e) + { + arrowUpHovered = false; + sliderHovered = false; + arrowDownHovered = false; + Refresh(); + } + + private void CustomScrollbar_MouseDown(object sender, MouseEventArgs e) + { + Point ptPoint = PointToClient(Cursor.Position); + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fThumbHeight = (float)LargeChange / Maximum * nTrackHeight; + int nScrollbarHeight = (int)fThumbHeight; + + if (nScrollbarHeight > nTrackHeight) + { + nScrollbarHeight = nTrackHeight; + } + + if (nScrollbarHeight < 56) + { + nScrollbarHeight = 56; + } + + int nTop = (int)moSliderTop; + nTop += arrowHeight; + + Rectangle thumbrect = new Rectangle(new Point(0, nTop), new Size(controlWidth + 1, nScrollbarHeight)); + Rectangle trackRectangle = new Rectangle(new Point(0, arrowHeight), new Size(controlWidth + 1, nTrackHeight)); + if (thumbrect.Contains(ptPoint)) + { + nClickPoint = ptPoint.Y - nTop; + moSliderDown = true; + } + else if (trackRectangle.Contains(ptPoint)) + { + if (e.Y < thumbrect.Y) + { + MoveUp(Height); + mouseStillClickedMoveUp = true; + } + else + { + MoveDown(Height); + mouseStillClickedMoveUp = false; + } + + mouseStillClickedMoveLarge = true; + timerMouseStillClickedCounter = 0; + timerMouseStillClicked.Start(); + } + + Rectangle uparrowrect = new Rectangle(new Point(0, 0), new Size(controlWidth + 1, arrowHeight)); + if (uparrowrect.Contains(ptPoint)) + { + MoveUp(SmallChange); + mouseStillClickedMoveUp = true; + mouseStillClickedMoveLarge = false; + timerMouseStillClickedCounter = 0; + timerMouseStillClicked.Start(); + } + + Rectangle downarrowrect = new Rectangle(new Point(0, arrowHeight + nTrackHeight), new Size(controlWidth + 1, arrowHeight)); + if (downarrowrect.Contains(ptPoint)) + { + MoveDown(SmallChange); + mouseStillClickedMoveUp = false; + mouseStillClickedMoveLarge = false; + timerMouseStillClickedCounter = 0; + timerMouseStillClicked.Start(); + } + } + + private void MoveDown(float change) + { + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fThumbHeight = (float)LargeChange / Maximum * nTrackHeight; + int nThumbHeight = (int)fThumbHeight; + + if (nThumbHeight > nTrackHeight) + { + nThumbHeight = nTrackHeight; + fThumbHeight = nTrackHeight; + } + + if (nThumbHeight < 56) + { + nThumbHeight = 56; + fThumbHeight = 56; + } + + int nRealRange = Maximum - Minimum - (int)LargeChange; + int nPixelRange = nTrackHeight - nThumbHeight; + if (nRealRange > 0) + { + if (nPixelRange > 0) + { + float changeForOneItem = (change * nPixelRange) / (Maximum - LargeChange); + + if ((moSliderTop + changeForOneItem) > nPixelRange) + { + moSliderTop = nPixelRange; + } + else + { + moSliderTop += changeForOneItem; + } + + // figure out value + float fPerc = moSliderTop / nPixelRange; + float fValue = fPerc * (Maximum - LargeChange); + + moValue = (int)fValue; + + if (Value != lastValue) + { + ValueChanged?.Invoke(this, new EventArgs()); + Scroll?.Invoke(this, new EventArgs()); + lastValue = Value; + } + + Invalidate(); + } + } + } + + private void MoveUp(float change) + { + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fSliderHeight = (float)LargeChange / Maximum * nTrackHeight; + int nSliderHeight = (int)fSliderHeight; + + if (nSliderHeight > nTrackHeight) + { + nSliderHeight = nTrackHeight; + fSliderHeight = nTrackHeight; + } + + if (nSliderHeight < 56) + { + nSliderHeight = 56; + fSliderHeight = 56; + } + + int nRealRange = Maximum - Minimum - (int)LargeChange; + int nPixelRange = nTrackHeight - nSliderHeight; + if (nRealRange > 0) + { + if (nPixelRange > 0) + { + float changeForOneItem = (change * nPixelRange) / (Maximum - LargeChange); + + if ((moSliderTop - changeForOneItem) < 0) + { + moSliderTop = 0; + } + else + { + moSliderTop -= changeForOneItem; + } + + // figure out value + float fPerc = moSliderTop / nPixelRange; + float fValue = fPerc * (Maximum - LargeChange); + + moValue = (int)fValue; + + if (Value != lastValue) + { + ValueChanged?.Invoke(this, new EventArgs()); + Scroll?.Invoke(this, new EventArgs()); + lastValue = Value; + } + + Invalidate(); + } + } + } + + private void CustomScrollbar_MouseUp(object sender, MouseEventArgs e) + { + moSliderDown = false; + moSliderDragging = false; + timerMouseStillClicked.Stop(); + } + + private void CustomScrollbar_MouseMove(object sender, MouseEventArgs e) + { + if (moSliderDown == true) + { + moSliderDragging = true; + } + + if (moSliderDragging) + { + MoveThumb(e.Y); + } + + if (Value != lastValue) + { + ValueChanged?.Invoke(this, new EventArgs()); + Scroll?.Invoke(this, new EventArgs()); + lastValue = Value; + } + + // Remember hovered control + Point ptPoint = PointToClient(Cursor.Position); + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fSliderHeight = (float)LargeChange / Maximum * nTrackHeight; + int nSliderHeight = (int)fSliderHeight; + + if (nSliderHeight > nTrackHeight) + { + nSliderHeight = nTrackHeight; + } + + if (nSliderHeight < 56) + { + nSliderHeight = 56; + } + + int nTop = (int)moSliderTop; + nTop += arrowHeight; + + Rectangle scrollbarbrect = new Rectangle(new Point(0, nTop), new Size(controlWidth + 1, nSliderHeight)); + Rectangle trackRectangle = new Rectangle(new Point(0, arrowHeight), new Size(controlWidth + 1, nTrackHeight)); + if (scrollbarbrect.Contains(ptPoint)) + { + if (e.Button != MouseButtons.Left) + { + arrowUpHovered = false; + sliderHovered = true; + arrowDownHovered = false; + } + } + else if (trackRectangle.Contains(ptPoint)) + { + if (e.Y < scrollbarbrect.Y) + { + arrowUpHovered = false; + sliderHovered = false; + arrowDownHovered = false; + } + else + { + arrowUpHovered = false; + sliderHovered = false; + arrowDownHovered = false; + } + } + + Rectangle uparrowrect = new Rectangle(new Point(0, 0), new Size(controlWidth + 1, arrowHeight)); + if (uparrowrect.Contains(ptPoint)) + { + arrowUpHovered = true; + sliderHovered = false; + arrowDownHovered = false; + } + + Rectangle downarrowrect = new Rectangle(new Point(0, arrowHeight + nTrackHeight), new Size(controlWidth + 1, arrowHeight)); + if (downarrowrect.Contains(ptPoint)) + { + arrowUpHovered = false; + sliderHovered = false; + arrowDownHovered = true; + } + + Invalidate(); + } + + private void MoveThumb(int y) + { + int nRealRange = Maximum - Minimum; + int nTrackHeight = Height - (arrowHeight + arrowHeight); + float fSliderHeight = (float)LargeChange / Maximum * nTrackHeight; + int nSliderHeight = (int)fSliderHeight; + + if (nSliderHeight > nTrackHeight) + { + nSliderHeight = nTrackHeight; + } + + if (nSliderHeight < 56) + { + nSliderHeight = 56; + } + + int nSpot = nClickPoint; + + int nPixelRange = nTrackHeight - nSliderHeight; + if (moSliderDown && nRealRange > 0) + { + if (nPixelRange > 0) + { + int nNewThumbTop = y - (arrowHeight + nSpot); + + if (nNewThumbTop < 0) + { + moSliderTop = nNewThumbTop = 0; + } + else if (nNewThumbTop > nPixelRange) + { + moSliderTop = nNewThumbTop = nPixelRange; + } + else + { + moSliderTop = y - (arrowHeight + nSpot); + } + + // figure out value + float fPerc = moSliderTop / nPixelRange; + float fValue = fPerc * (Maximum - LargeChange); + moValue = (int)fValue; + + Application.DoEvents(); + + Invalidate(); + } + } + } + } +} \ No newline at end of file diff --git a/UserInterface/CustomScrollbar/CustomScrollbar.resx b/UserInterface/CustomScrollbar/CustomScrollbar.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/UserInterface/CustomScrollbar/CustomScrollbar.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs b/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs new file mode 100644 index 0000000..89febfd --- /dev/null +++ b/UserInterface/CustomScrollbar/ScrollbarControlDesigner.cs @@ -0,0 +1,39 @@ +// +// Copyright (c) PlaceholderCompany. All rights reserved. +// + +namespace SystemTrayMenu.UserInterface +{ + using System; + using System.ComponentModel; + using System.Diagnostics; + using System.Drawing; + using System.Windows.Forms; + using System.Windows.Forms.Design; + + internal class ScrollbarControlDesigner : ControlDesigner + { + public override SelectionRules SelectionRules + { + get + { + SelectionRules selectionRules = base.SelectionRules; + PropertyDescriptor propDescriptor = TypeDescriptor.GetProperties(Component)["AutoSize"]; + if (propDescriptor != null) + { + bool autoSize = (bool)propDescriptor.GetValue(Component); + if (autoSize) + { + selectionRules = SelectionRules.Visible | SelectionRules.Moveable | SelectionRules.BottomSizeable | SelectionRules.TopSizeable; + } + else + { + selectionRules = SelectionRules.Visible | SelectionRules.AllSizeable | SelectionRules.Moveable; + } + } + + return selectionRules; + } + } + } +} \ No newline at end of file diff --git a/UserInterface/Menu.Designer.cs b/UserInterface/Menu.Designer.cs index 6cfbf97..439343f 100644 --- a/UserInterface/Menu.Designer.cs +++ b/UserInterface/Menu.Designer.cs @@ -18,6 +18,7 @@ components.Dispose(); } fading.Dispose(); + customScrollbar.Dispose(); base.Dispose(disposing); } @@ -29,49 +30,52 @@ /// private void InitializeComponent() { - System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); + this.components = new System.ComponentModel.Container(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle3 = new System.Windows.Forms.DataGridViewCellStyle(); - this.tableLayoutPanel = new System.Windows.Forms.TableLayoutPanel(); + System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); + this.tableLayoutPanelDgvAndScrollbar = new System.Windows.Forms.TableLayoutPanel(); this.labelTitle = new SystemTrayMenu.UserInterface.LabelNoCopy(); this.ColumnText = new System.Windows.Forms.DataGridViewTextBoxColumn(); this.ColumnIcon = new System.Windows.Forms.DataGridViewImageColumn(); this.dgv = new System.Windows.Forms.DataGridView(); - this.pictureBoxSearch = new System.Windows.Forms.PictureBox(); - this.textBoxSearch = new System.Windows.Forms.TextBox(); this.tableLayoutPanelSearch = new System.Windows.Forms.TableLayoutPanel(); - this.tableLayoutPanel.SuspendLayout(); + this.textBoxSearch = new System.Windows.Forms.TextBox(); + this.pictureBoxSearch = new System.Windows.Forms.PictureBox(); + this.tableLayoutPanelMenu = new System.Windows.Forms.TableLayoutPanel(); + this.customScrollbar = new UserInterface.CustomScrollbar(); + this.tableLayoutPanelDgvAndScrollbar.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.dgv)).BeginInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxSearch)).BeginInit(); this.tableLayoutPanelSearch.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxSearch)).BeginInit(); + this.tableLayoutPanelMenu.SuspendLayout(); this.SuspendLayout(); // - // tableLayoutPanel + // tableLayoutPanelDgvAndScrollbar // - this.tableLayoutPanel.AutoScroll = true; - this.tableLayoutPanel.AutoSize = true; - this.tableLayoutPanel.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanel.ColumnCount = 1; - this.tableLayoutPanel.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tableLayoutPanel.Controls.Add(this.labelTitle, 0, 0); - this.tableLayoutPanel.Controls.Add(this.dgv, 0, 1); - this.tableLayoutPanel.Controls.Add(this.tableLayoutPanelSearch, 0, 2); - this.tableLayoutPanel.Location = new System.Drawing.Point(1, 1); - this.tableLayoutPanel.Margin = new System.Windows.Forms.Padding(0); - this.tableLayoutPanel.Name = "tableLayoutPanel"; - this.tableLayoutPanel.RowCount = 3; - this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanel.Size = new System.Drawing.Size(83, 182); - this.tableLayoutPanel.TabIndex = 3; - this.tableLayoutPanel.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel); + this.tableLayoutPanelDgvAndScrollbar.AutoScroll = true; + this.tableLayoutPanelDgvAndScrollbar.AutoSize = true; + this.tableLayoutPanelDgvAndScrollbar.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.tableLayoutPanelDgvAndScrollbar.ColumnCount = 2; + this.tableLayoutPanelDgvAndScrollbar.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanelDgvAndScrollbar.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanelDgvAndScrollbar.Controls.Add(this.customScrollbar, 1, 0); + this.tableLayoutPanelDgvAndScrollbar.Controls.Add(this.dgv, 0, 0); + this.tableLayoutPanelDgvAndScrollbar.Location = new System.Drawing.Point(0, 0); + this.tableLayoutPanelDgvAndScrollbar.Margin = new System.Windows.Forms.Padding(0); + this.tableLayoutPanelDgvAndScrollbar.Name = "tableLayoutPanelDgvAndScrollbar"; + this.tableLayoutPanelDgvAndScrollbar.RowCount = 1; + this.tableLayoutPanelDgvAndScrollbar.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanelDgvAndScrollbar.Size = new System.Drawing.Size(70, 40); + this.tableLayoutPanelDgvAndScrollbar.TabIndex = 3; + this.tableLayoutPanelDgvAndScrollbar.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel); // // labelTitle // - this.labelTitle.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); this.labelTitle.AutoEllipsis = true; this.labelTitle.AutoSize = true; + this.labelTitle.Dock = System.Windows.Forms.DockStyle.Fill; this.labelTitle.BackColor = System.Drawing.Color.Azure; this.labelTitle.Font = new System.Drawing.Font("Segoe UI", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.labelTitle.ForeColor = System.Drawing.Color.Black; @@ -79,7 +83,7 @@ this.labelTitle.Margin = new System.Windows.Forms.Padding(0); this.labelTitle.Name = "labelTitle"; this.labelTitle.Padding = new System.Windows.Forms.Padding(3, 0, 0, 1); - this.labelTitle.Size = new System.Drawing.Size(83, 14); + this.labelTitle.Size = new System.Drawing.Size(70, 14); this.labelTitle.TabIndex = 2; this.labelTitle.Text = "STM"; this.labelTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; @@ -101,7 +105,7 @@ this.ColumnText.ReadOnly = true; this.ColumnText.Resizable = System.Windows.Forms.DataGridViewTriState.False; this.ColumnText.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.Programmatic; - this.ColumnText.Width = 50; + this.ColumnText.Width = 25; // // ColumnIcon // @@ -146,16 +150,36 @@ this.dgv.RowTemplate.DefaultCellStyle.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.dgv.RowTemplate.Height = 20; this.dgv.RowTemplate.ReadOnly = true; - this.dgv.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; + this.dgv.ScrollBars = System.Windows.Forms.ScrollBars.None; this.dgv.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; this.dgv.ShowCellErrors = false; this.dgv.ShowCellToolTips = false; this.dgv.ShowEditingIcon = false; this.dgv.ShowRowErrors = false; - this.dgv.Size = new System.Drawing.Size(83, 145); + this.dgv.Size = new System.Drawing.Size(55, 40); this.dgv.TabIndex = 4; this.dgv.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel); // + // tableLayoutPanelSearch + // + this.tableLayoutPanelSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); + this.tableLayoutPanelSearch.AutoSize = true; + this.tableLayoutPanelSearch.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.tableLayoutPanelSearch.BackColor = System.Drawing.Color.White; + this.tableLayoutPanelSearch.ColumnCount = 2; + this.tableLayoutPanelSearch.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanelSearch.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanelSearch.Controls.Add(this.textBoxSearch, 1, 0); + this.tableLayoutPanelSearch.Controls.Add(this.pictureBoxSearch, 0, 0); + this.tableLayoutPanelSearch.Location = new System.Drawing.Point(0, 146); + this.tableLayoutPanelSearch.Margin = new System.Windows.Forms.Padding(0, 1, 0, 0); + this.tableLayoutPanelSearch.Name = "tableLayoutPanelSearch"; + this.tableLayoutPanelSearch.RowCount = 1; + this.tableLayoutPanelSearch.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanelSearch.Size = new System.Drawing.Size(70, 22); + this.tableLayoutPanelSearch.TabIndex = 5; + this.tableLayoutPanelSearch.MouseWheel += new System.Windows.Forms.MouseEventHandler(this.DgvMouseWheel); + // // pictureBoxSearch // this.pictureBoxSearch.BackColor = System.Drawing.Color.White; @@ -181,24 +205,31 @@ this.textBoxSearch.TextChanged += new System.EventHandler(this.TextBoxSearch_TextChanged); this.textBoxSearch.ContextMenuStrip = new System.Windows.Forms.ContextMenuStrip(); // - // tableLayoutPanelSearch + // tableLayoutPanelMenu // - this.tableLayoutPanelSearch.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right))); - this.tableLayoutPanelSearch.AutoSize = true; - this.tableLayoutPanelSearch.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; - this.tableLayoutPanelSearch.BackColor = System.Drawing.Color.White; - this.tableLayoutPanelSearch.ColumnCount = 2; - this.tableLayoutPanelSearch.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tableLayoutPanelSearch.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); - this.tableLayoutPanelSearch.Controls.Add(this.textBoxSearch, 1, 0); - this.tableLayoutPanelSearch.Controls.Add(this.pictureBoxSearch, 0, 0); - this.tableLayoutPanelSearch.Location = new System.Drawing.Point(0, 160); - this.tableLayoutPanelSearch.Margin = new System.Windows.Forms.Padding(0, 1, 0, 0); - this.tableLayoutPanelSearch.Name = "tableLayoutPanelSearch"; - this.tableLayoutPanelSearch.RowCount = 1; - this.tableLayoutPanelSearch.RowStyles.Add(new System.Windows.Forms.RowStyle()); - this.tableLayoutPanelSearch.Size = new System.Drawing.Size(83, 22); - this.tableLayoutPanelSearch.TabIndex = 5; + this.tableLayoutPanelMenu.AutoSize = true; + this.tableLayoutPanelMenu.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; + this.tableLayoutPanelMenu.ColumnCount = 1; + this.tableLayoutPanelMenu.ColumnStyles.Add(new System.Windows.Forms.ColumnStyle()); + this.tableLayoutPanelMenu.Controls.Add(this.labelTitle, 0, 0); + this.tableLayoutPanelMenu.Controls.Add(this.tableLayoutPanelSearch, 0, 2); + this.tableLayoutPanelMenu.Controls.Add(this.tableLayoutPanelDgvAndScrollbar, 0, 1); + this.tableLayoutPanelMenu.Location = new System.Drawing.Point(1, 1); + this.tableLayoutPanelMenu.Margin = new System.Windows.Forms.Padding(0); + this.tableLayoutPanelMenu.Name = "tableLayoutPanelMenu"; + this.tableLayoutPanelMenu.RowCount = 3; + this.tableLayoutPanelMenu.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanelMenu.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanelMenu.RowStyles.Add(new System.Windows.Forms.RowStyle()); + this.tableLayoutPanelMenu.Size = new System.Drawing.Size(70, 76); + this.tableLayoutPanelMenu.TabIndex = 4; + // + // customScrollbar + // + this.customScrollbar.Location = new System.Drawing.Point(0, 0); + this.customScrollbar.Name = "customScrollbar"; + this.customScrollbar.Size = new System.Drawing.Size(15, 40); + this.customScrollbar.TabIndex = 5; // // Menu // @@ -208,7 +239,7 @@ this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink; this.BackColor = System.Drawing.Color.Black; this.ClientSize = new System.Drawing.Size(331, 360); - this.Controls.Add(this.tableLayoutPanel); + this.Controls.Add(this.tableLayoutPanelMenu); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; this.Name = "Menu"; this.Opacity = 0.01D; @@ -217,12 +248,13 @@ this.StartPosition = System.Windows.Forms.FormStartPosition.Manual; this.Text = "SystemTrayMenu"; this.TopMost = true; - this.tableLayoutPanel.ResumeLayout(false); - this.tableLayoutPanel.PerformLayout(); + this.tableLayoutPanelDgvAndScrollbar.ResumeLayout(false); ((System.ComponentModel.ISupportInitialize)(this.dgv)).EndInit(); - ((System.ComponentModel.ISupportInitialize)(this.pictureBoxSearch)).EndInit(); this.tableLayoutPanelSearch.ResumeLayout(false); this.tableLayoutPanelSearch.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)(this.pictureBoxSearch)).EndInit(); + this.tableLayoutPanelMenu.ResumeLayout(false); + this.tableLayoutPanelMenu.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -230,12 +262,14 @@ #endregion private SystemTrayMenu.UserInterface.LabelNoCopy labelTitle; - private System.Windows.Forms.TableLayoutPanel tableLayoutPanel; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelDgvAndScrollbar; private System.Windows.Forms.DataGridView dgv; private System.Windows.Forms.DataGridViewImageColumn ColumnIcon; private System.Windows.Forms.DataGridViewTextBoxColumn ColumnText; private System.Windows.Forms.TableLayoutPanel tableLayoutPanelSearch; private System.Windows.Forms.TextBox textBoxSearch; private System.Windows.Forms.PictureBox pictureBoxSearch; + private UserInterface.CustomScrollbar customScrollbar; + private System.Windows.Forms.TableLayoutPanel tableLayoutPanelMenu; } } \ No newline at end of file diff --git a/UserInterface/Menu.cs b/UserInterface/Menu.cs index ddec525..19abae9 100644 --- a/UserInterface/Menu.cs +++ b/UserInterface/Menu.cs @@ -95,23 +95,37 @@ namespace SystemTrayMenu.UserInterface } labelTitle.BackColor = titleBackColor; - tableLayoutPanel.BackColor = backColor; + tableLayoutPanelDgvAndScrollbar.BackColor = backColor; dgv.BackgroundColor = backColor; textBoxSearch.BackColor = backColorSearch; pictureBoxSearch.BackColor = backColorSearch; tableLayoutPanelSearch.BackColor = backColorSearch; - - DataGridViewCellStyle dgvCellStyle = new DataGridViewCellStyle + dgv.DefaultCellStyle = new DataGridViewCellStyle { SelectionForeColor = foreColor, ForeColor = foreColor, BackColor = backColor, }; - dgv.DefaultCellStyle = dgvCellStyle; - VScrollBar scrollBar = dgv.Controls.OfType().First(); - scrollBar.MouseWheel += DgvMouseWheel; - scrollBar.MouseEnter += ControlsMouseEnter; + customScrollbar.GotFocus += CustomScrollbar_GotFocus; + void CustomScrollbar_GotFocus(object sender, EventArgs e) + { + textBoxSearch.Focus(); + } + + customScrollbar.Margin = new Padding(0); + customScrollbar.Scroll += CustomScrollbar_Scroll; + void CustomScrollbar_Scroll(object sender, EventArgs e) + { + decimal firstIndex = customScrollbar.Value * dgv.Rows.Count / (decimal)customScrollbar.Maximum; + int firstIndexRounded = (int)Math.Round(firstIndex, 0, MidpointRounding.AwayFromZero); + if (firstIndexRounded > -1 && firstIndexRounded < dgv.RowCount) + { + dgv.FirstDisplayedScrollingRowIndex = firstIndexRounded; + } + } + + customScrollbar.MouseEnter += ControlsMouseEnter; dgv.MouseEnter += ControlsMouseEnter; labelTitle.MouseEnter += ControlsMouseEnter; void ControlsMouseEnter(object sender, EventArgs e) @@ -119,7 +133,7 @@ namespace SystemTrayMenu.UserInterface MouseEnter?.Invoke(); } - scrollBar.MouseLeave += ControlsMouseLeave; + customScrollbar.MouseLeave += ControlsMouseLeave; dgv.MouseLeave += ControlsMouseLeave; labelTitle.MouseLeave += ControlsMouseLeave; void ControlsMouseLeave(object sender, EventArgs e) @@ -416,6 +430,14 @@ namespace SystemTrayMenu.UserInterface textBoxSearch.Focus(); } + internal void AdjustScrollbar() + { + customScrollbar.Value = (int)Math.Round( + dgv.FirstDisplayedScrollingRowIndex * (decimal)customScrollbar.Maximum / dgv.Rows.Count, + 0, + MidpointRounding.AwayFromZero); + } + protected override bool ProcessCmdKey(ref Message msg, Keys keys) { switch (keys) @@ -482,43 +504,66 @@ namespace SystemTrayMenu.UserInterface } DataTable data = (DataTable)dgv.DataSource; + int dgvHeightNew = dgv.Rows.GetRowsHeight(DataGridViewElementStates.None); // Height of all rows + int dgvHeightMax = screenHeightMax - (Height - dgv.Height); // except dgv + + if (dgvHeightMax > Properties.Settings.Default.MaximumMenuHeight) + { + dgvHeightMax = Properties.Settings.Default.MaximumMenuHeight; + } + + if (dgvHeightNew > dgvHeightMax) + { + // Make all rows fit into the screen + customScrollbar.PaintEnable(); + if (customScrollbar.Maximum != dgvHeightNew) + { + customScrollbar.Reset(); + customScrollbar.Height = dgvHeightMax; + customScrollbar.Minimum = 0; + customScrollbar.Maximum = dgvHeightNew; + customScrollbar.LargeChange = (customScrollbar.Maximum / (float)customScrollbar.Height) + dgvHeightMax; + customScrollbar.SmallChange = dgv.RowTemplate.Height; + } + + dgvHeightNew = dgvHeightMax; + } + else + { + customScrollbar.PaintDisable(); + } + if (string.IsNullOrEmpty(data.DefaultView.RowFilter)) { - int dgvHeight = dgv.Rows.GetRowsHeight(DataGridViewElementStates.None); // Height of all rows - int dgvHeightMax = screenHeightMax - (Height - dgv.Height); // except dgv - - if (dgvHeightMax > Properties.Settings.Default.MaximumMenuHeight) - { - dgvHeightMax = Properties.Settings.Default.MaximumMenuHeight; - } - - if (dgvHeight > dgvHeightMax) - { - // Make all rows fit into the screen - dgvHeight = dgvHeightMax; - } - - dgv.Height = dgvHeight; + dgv.Height = dgvHeightNew; } } private void AdjustDataGridViewWidth() { DataGridViewExtensions.FastAutoSizeColumns(dgv); - int newWidth = dgv.Columns[0].Width + dgv.Columns[1].Width; - if (IsScrollbarShown()) + + if (dgv.Columns[1].Width < 60) { - newWidth += SystemInformation.VerticalScrollBarWidth; + dgv.Columns[1].Width = 60; } - if (labelTitle.Width > newWidth) + int widthIcon = dgv.Columns[0].Width; + int widthText = dgv.Columns[1].Width; + int widthScrollbar = 0; + if (customScrollbar.Enabled) { - dgv.Width = labelTitle.Width; - dgv.Columns[1].Width = labelTitle.Width - dgv.Columns[0].Width; + widthScrollbar = customScrollbar.Width; + } + + if (labelTitle.Width > (widthIcon + widthText + widthScrollbar)) + { + dgv.Width = labelTitle.Width - widthScrollbar; + dgv.Columns[1].Width = labelTitle.Width - widthIcon - widthScrollbar; } else { - dgv.Width = newWidth; + dgv.Width = widthIcon + widthText; } // Only scaling correct with Sans Serif for textBoxSearch. Workaround: @@ -528,57 +573,12 @@ namespace SystemTrayMenu.UserInterface FontStyle.Regular, GraphicsUnit.Point, 0); - - // Ancor not working like in the label - textBoxSearch.Width = newWidth - - pictureBoxSearch.Width - - pictureBoxSearch.Margin.Horizontal - - textBoxSearch.Margin.Horizontal; - } - - private bool IsScrollbarShown() - { - bool isScrollbarShown = false; - foreach (VScrollBar scroll in dgv.Controls.OfType()) - { - if (scroll.Visible) - { - isScrollbarShown = true; - } - } - - return isScrollbarShown; } private void DgvMouseWheel(object sender, MouseEventArgs e) { ((HandledMouseEventArgs)e).Handled = true; - int scrollspeed = MenuDefines.Scrollspeed; - if (e.Delta < 0) - { - if (dgv.FirstDisplayedScrollingRowIndex < dgv.Rows.Count - scrollspeed) - { - dgv.FirstDisplayedScrollingRowIndex += scrollspeed; - } - else - { - dgv.FirstDisplayedScrollingRowIndex = dgv.Rows.Count - 1; - } - } - else - { - if (dgv.FirstDisplayedScrollingRowIndex > 0 + scrollspeed) - { - dgv.FirstDisplayedScrollingRowIndex -= scrollspeed; - } - else - { - dgv.FirstDisplayedScrollingRowIndex = 0; - } - } - - dgv.Invalidate(); - + customScrollbar.CustomScrollbar_MouseWheel(sender, e); MouseWheel?.Invoke(); } @@ -602,6 +602,8 @@ namespace SystemTrayMenu.UserInterface private void TextBoxSearch_TextChanged(object sender, EventArgs e) { + customScrollbar.Value = 0; + DataTable data = (DataTable)dgv.DataSource; string filterField = dgv.Columns[1].Name; SearchTextChanging?.Invoke(); diff --git a/UserInterface/Menu.resx b/UserInterface/Menu.resx index b1c3d17..f298a7b 100644 --- a/UserInterface/Menu.resx +++ b/UserInterface/Menu.resx @@ -1,64 +1,4 @@ - - - + @@ -117,10 +57,4 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - True - - - True - \ No newline at end of file diff --git a/UserInterface/SettingsForm.cs b/UserInterface/SettingsForm.cs index 6129a32..a31feef 100644 --- a/UserInterface/SettingsForm.cs +++ b/UserInterface/SettingsForm.cs @@ -160,7 +160,7 @@ namespace SystemTrayMenu.UserInterface numericUpDownMenuWidth.Increment = 10; numericUpDownMenuWidth.Value = Settings.Default.MaximumMenuWidth; - numericUpDownMenuHeight.Minimum = 100; + numericUpDownMenuHeight.Minimum = 200; numericUpDownMenuHeight.Maximum = 4000; numericUpDownMenuHeight.Increment = 10; numericUpDownMenuHeight.Value = Settings.Default.MaximumMenuHeight; diff --git a/stylecop.json b/stylecop.json index ef95ea9..795ed52 100644 --- a/stylecop.json +++ b/stylecop.json @@ -8,7 +8,7 @@ "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json", "settings": { "documentationRules": { - "companyName": "TAMAHO" + "companyName": "SystemTrayMenu" } } }