mirror of
https://github.com/Hofknecht/SystemTrayMenu.git
synced 2024-09-28 23:31:25 +12:00
#NewBug Fixed slow scrolling
This commit is contained in:
parent
8102a7b787
commit
1f28b5d32f
4 changed files with 43 additions and 6 deletions
|
@ -4,6 +4,7 @@ using System.Linq;
|
|||
using System.Reflection;
|
||||
using System.Windows.Forms;
|
||||
using SystemTrayMenu.Controls;
|
||||
using SystemTrayMenu.Helper;
|
||||
|
||||
namespace SystemTrayMenu
|
||||
{
|
||||
|
@ -53,6 +54,9 @@ namespace SystemTrayMenu
|
|||
dgvCellStyle.SelectionBackColor = MenuDefines.FileHover;
|
||||
dgvCellStyle.SelectionForeColor = Color.Black;
|
||||
this.dgv.DefaultCellStyle = dgvCellStyle;
|
||||
|
||||
VScrollBar scrollBar = dgv.Controls.OfType<VScrollBar>().First();
|
||||
scrollBar.MouseWheel += dgv_MouseWheel;
|
||||
}
|
||||
|
||||
static void SetDoubleBuffer(Control ctl, bool DoubleBuffered)
|
||||
|
@ -209,7 +213,9 @@ namespace SystemTrayMenu
|
|||
|
||||
private void AdjustDataGridViewSize()
|
||||
{
|
||||
dgv.AutoResizeColumns();
|
||||
//dgv.AutoResizeColumns(); //AutoResizeColumns slow ~45ms
|
||||
DataGridViewExtensions.FastAutoSizeColumns(dgv);
|
||||
|
||||
bool scrollbarShown = false;
|
||||
foreach (var scroll in dgv.Controls.OfType<VScrollBar>())
|
||||
{
|
||||
|
@ -254,7 +260,7 @@ namespace SystemTrayMenu
|
|||
}
|
||||
}
|
||||
|
||||
dgv.PerformLayout();
|
||||
Application.DoEvents();
|
||||
MouseWheel.Invoke();
|
||||
}
|
||||
|
||||
|
|
32
Helper/DataGridViewExtensions.cs
Normal file
32
Helper/DataGridViewExtensions.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace SystemTrayMenu.Helper
|
||||
{
|
||||
public static class DataGridViewExtensions
|
||||
{
|
||||
public static void FastAutoSizeColumns(this DataGridView dgv)
|
||||
{
|
||||
var rows = dgv.Rows
|
||||
.Cast<DataGridViewRow>();
|
||||
using (var gfx = dgv.CreateGraphics())
|
||||
{
|
||||
int i = 1;
|
||||
gfx.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
|
||||
float widthMax = dgv.Columns[i].HeaderCell.Size.Width;
|
||||
foreach (DataGridViewRow row in rows)
|
||||
{
|
||||
var checkWidth = gfx.MeasureString(
|
||||
row.Cells[i].Value.ToString() + "_",
|
||||
dgv.RowTemplate.DefaultCellStyle.Font).Width;
|
||||
if (checkWidth > widthMax)
|
||||
{
|
||||
widthMax = checkWidth;
|
||||
}
|
||||
}
|
||||
dgv.Columns[i].Width = (int)(widthMax + 0.5);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,7 +37,7 @@ namespace SystemTrayMenu
|
|||
OpenCloseState openCloseState = OpenCloseState.Default;
|
||||
|
||||
BackgroundWorker worker = new BackgroundWorker();
|
||||
Screen screen = null;
|
||||
Screen screen = Screen.PrimaryScreen;
|
||||
|
||||
public SystemTrayMenu(ref bool cancelAppRun)
|
||||
{
|
||||
|
@ -124,8 +124,6 @@ namespace SystemTrayMenu
|
|||
#endregion
|
||||
|
||||
openCloseState = OpenCloseState.Opening;
|
||||
screen = Screen.PrimaryScreen;
|
||||
|
||||
menuNotifyIcon.LoadingStart();
|
||||
worker.RunWorkerAsync();
|
||||
}
|
||||
|
@ -318,7 +316,7 @@ namespace SystemTrayMenu
|
|||
widthPredecessors -= newWith;
|
||||
}
|
||||
}
|
||||
else if (Screen.PrimaryScreen.Bounds.Width <
|
||||
else if (screen.Bounds.Width <
|
||||
widthPredecessors + menuPredecessor.Width + menu.Width)
|
||||
{
|
||||
directionToRight = true;
|
||||
|
|
|
@ -160,6 +160,7 @@
|
|||
<Compile Include="Controls\RowData.cs" />
|
||||
<Compile Include="Controls\AppContextMenu.cs" />
|
||||
<Compile Include="Helper\BringWindowToTop.cs" />
|
||||
<Compile Include="Helper\DataGridViewExtensions.cs" />
|
||||
<Compile Include="Helper\File\IconReader.cs" />
|
||||
<Compile Include="Helper\File\FileIni.cs" />
|
||||
<Compile Include="Helper\File\FileLnk.cs" />
|
||||
|
|
Loading…
Reference in a new issue