You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
112 lines
3.2 KiB
C#
112 lines
3.2 KiB
C#
using System;
|
|
using System.Drawing;
|
|
using System.Windows.Forms;
|
|
using GeoSigmaDrawLib;
|
|
|
|
namespace GeoSigma.SigmaDrawerStyle
|
|
{
|
|
/// <summary>
|
|
/// 符号列表
|
|
/// </summary>
|
|
public class MarkListBox : ListBox
|
|
{
|
|
private int padding = 2;
|
|
private int itemHeight = 24;
|
|
|
|
public event Action<string> LineTypeSelected;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="MarkListBox"/> class.
|
|
/// </summary>
|
|
public MarkListBox()
|
|
{
|
|
this.DrawMode = DrawMode.OwnerDrawFixed;
|
|
this.ItemHeight = itemHeight;
|
|
|
|
if (GeoSigmaWellPoleXY.GetCurveFillSymbolNames(out string[] names))
|
|
{
|
|
this.Items.AddRange(names);
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void OnSelectedIndexChanged(EventArgs e)
|
|
{
|
|
base.OnSelectedIndexChanged(e);
|
|
|
|
if (SelectedIndex >= 0 && SelectedIndex < Items.Count)
|
|
{
|
|
LineTypeSelected?.Invoke(SelectedItem.ToString());
|
|
}
|
|
}
|
|
|
|
/// <inheritdoc/>
|
|
protected override void OnDrawItem(DrawItemEventArgs e)
|
|
{
|
|
if (e.Index < 0 || e.Index >= Items.Count)
|
|
{
|
|
return;
|
|
}
|
|
|
|
string name = Items[e.Index].ToString();
|
|
Rectangle bounds = e.Bounds;
|
|
|
|
// 绘制背景(包括选中效果)
|
|
e.DrawBackground();
|
|
|
|
// 设置图标和文字区域
|
|
int iconSize = bounds.Height - (2 * padding);
|
|
Rectangle imageRect = new Rectangle(bounds.Left + padding, bounds.Top + padding, iconSize, iconSize);
|
|
Rectangle textRect = new Rectangle(imageRect.Right + padding, bounds.Top, bounds.Width - imageRect.Width - (3 * padding), bounds.Height);
|
|
|
|
// 绘制图标
|
|
using (Bitmap bitmap = GetBitmap(name, imageRect.Width, imageRect.Height))
|
|
{
|
|
if (bitmap != null)
|
|
{
|
|
e.Graphics.DrawImage(bitmap, imageRect);
|
|
}
|
|
}
|
|
|
|
// 绘制文字
|
|
TextRenderer.DrawText(
|
|
e.Graphics,
|
|
name,
|
|
this.Font,
|
|
textRect,
|
|
(e.State & DrawItemState.Selected) != 0 ? SystemColors.HighlightText : this.ForeColor,
|
|
TextFormatFlags.VerticalCenter | TextFormatFlags.Left);
|
|
|
|
// 绘制焦点框
|
|
e.DrawFocusRectangle();
|
|
}
|
|
|
|
private Bitmap GetBitmap(string name, int width, int height)
|
|
{
|
|
Bitmap bitmap = new Bitmap(width, height);
|
|
using (Graphics image = Graphics.FromImage(bitmap))
|
|
{
|
|
IntPtr hdc = image.GetHdc();
|
|
bool success = false;
|
|
|
|
try
|
|
{
|
|
success = GeoSigmaWellPoleXY.GetDrawCurveFillSymbol(name, hdc, width, height);
|
|
}
|
|
finally
|
|
{
|
|
image.ReleaseHdc(hdc);
|
|
}
|
|
|
|
if (!success)
|
|
{
|
|
bitmap.Dispose();
|
|
return null;
|
|
}
|
|
}
|
|
|
|
return bitmap;
|
|
}
|
|
}
|
|
}
|