* UIListBox:增加文字水平对齐方向

This commit is contained in:
Sunny 2020-12-23 21:08:29 +08:00
parent f90a994969
commit 1def456323
3 changed files with 39 additions and 0 deletions

Binary file not shown.

View File

@ -305,6 +305,24 @@ namespace Sunny.UI
return false;
}
public bool GetNearestPointX(Point p, int offset, out double x, out double y, out int index)
{
x = 0;
y = 0;
index = -1;
if (PointsX.Count == 0) return false;
index = PointsX.BinarySearchNearIndex(p.X);
if (p.X >= PointsX[index] - offset && p.X <= PointsX[index] + offset)
{
x = XData[index];
y = YData[index];
return true;
}
return false;
}
public void Clear()
{
XData.Clear();

View File

@ -69,6 +69,14 @@ namespace Sunny.UI
timer.Start();
}
[DefaultValue(StringAlignment.Near)]
[Description("列表项高度"), Category("SunnyUI")]
public new StringAlignment TextAlignment
{
get => listbox.TextAlignment;
set => listbox.TextAlignment = value;
}
protected override void OnContextMenuStripChanged(EventArgs e)
{
base.OnContextMenuStripChanged(e);
@ -503,6 +511,18 @@ namespace Sunny.UI
public event OnBeforeDrawItem AfterDrawItem;
private StringAlignment textAlignment = StringAlignment.Near;
public StringAlignment TextAlignment
{
get => textAlignment;
set
{
textAlignment = value;
Invalidate();
}
}
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
@ -526,6 +546,7 @@ namespace Sunny.UI
StringFormat sStringFormat = new StringFormat();
sStringFormat.LineAlignment = StringAlignment.Center;
sStringFormat.Alignment = textAlignment;
bool isSelected = (e.State & DrawItemState.Selected) == DrawItemState.Selected;
Color backColor = isSelected ? ItemSelectBackColor : BackColor;