Fix height issue of nav list items on high dpi

This commit is contained in:
2024-09-07 20:44:23 +08:00
parent b37016a49c
commit fafff8090f
2 changed files with 10 additions and 2 deletions

View File

@ -63,6 +63,7 @@ namespace GrasscutterTools.Forms
this.ListPages.FormattingEnabled = true;
this.ListPages.Name = "ListPages";
this.ListPages.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.ListPages_DrawItem);
this.ListPages.MeasureItem += new System.Windows.Forms.MeasureItemEventHandler(this.ListPages_MeasureItem);
this.ListPages.SelectedIndexChanged += new System.EventHandler(this.ListPages_SelectedIndexChanged);
this.ListPages.SizeChanged += new System.EventHandler(this.ListPages_SizeChanged);
//

View File

@ -399,8 +399,6 @@ namespace GrasscutterTools.Forms
/// <summary>
/// 导航列表项居中绘制
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ListPages_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
@ -413,6 +411,15 @@ namespace GrasscutterTools.Forms
e.Graphics.DrawString(ListPages.Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds, strFmt);
}
/// <summary>
/// 导航列表高度测量
/// </summary>
private void ListPages_MeasureItem(object sender, MeasureItemEventArgs e)
{
// 列表项高度为字体高度1.5倍
e.ItemHeight = ListPages.Font.Height * 3 / 2;
}
/// <summary>
/// 导航列表大小改变时触发
/// </summary>