📄 headiconlist_drawer.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Text;
using System.Runtime.InteropServices;
using System.Windows.Forms;
public class headiconlist_drawer : listbox_drawer_base
{
private SolidBrush m_background_brush = new SolidBrush(Color.White);
private int m_item_height = 0x1a;
private SolidBrush m_selected_brush = new SolidBrush(Color.FromArgb(0xff, 0xbc, 0xed, 0xfd));
private bool m_show_focus = true;
private bool m_stretch_textarea;
private StringAlignment m_stringNoIconAlignment = StringAlignment.Center;
public override void draw_background(listbox_widget host, Graphics g)
{
if ((0 < host.ClientRectangle.Width) && (0 < host.ClientRectangle.Height))
{
if (0 < host.Items.Count)
{
Rectangle itemRectangle = host.GetItemRectangle(host.Items.Count - 1);
if (itemRectangle.Bottom >= host.ClientRectangle.Bottom)
{
return;
}
Rectangle rect = Rectangle.FromLTRB(host.ClientRectangle.Left, itemRectangle.Bottom, host.ClientRectangle.Right, host.ClientRectangle.Bottom);
g.SetClip(rect);
}
using (Bitmap image = new Bitmap(host.ClientRectangle.Width, host.ClientRectangle.Height))
{
using (Graphics graphics = Graphics.FromImage(image))
{
graphics.FillRectangle(this.m_background_brush, 0, 0, image.Width, image.Height);
}
g.DrawImage(image, host.ClientRectangle.Location);
}
}
}
public override void draw_host_item(listbox_widget host, DrawItemEventArgs e)
{
Rectangle rect = host.GetItemRectangle(e.Index);
using (Bitmap image = new Bitmap(rect.Width, rect.Height))
{
using (Graphics g = Graphics.FromImage(image))
{
object obj2 = host.Items[e.Index];
if (obj2 is listbox_widget.separator)
{
this.draw_separator(g, Rectangle.FromLTRB(0, 0, rect.Width, rect.Height), (listbox_widget.separator) obj2);
}
else if (obj2 is headicon)
{
this.draw_item_rectangle(g, Rectangle.FromLTRB(0, 0, rect.Width, rect.Height), (headicon) obj2, e.State);
this.draw_item_content(g, Rectangle.FromLTRB(0, 0, rect.Width, rect.Height), (headicon) obj2, e.State);
}
}
e.Graphics.DrawImage(image, rect);
}
}
protected void draw_item_content(Graphics g, Rectangle rect, headicon head, DrawItemState state)
{
if (head != null)
{
if (head.icon != null)
{
g.DrawImage(head.icon, Rectangle.FromLTRB(rect.Left + 1, rect.Top + 1, (rect.Left + this.m_item_height) - 2, rect.Bottom - 1));
}
Rectangle layoutRectangle = Rectangle.FromLTRB(rect.Left + ((this.m_stretch_textarea && (head.icon == null)) ? 0 : this.m_item_height), rect.Top, rect.Right, rect.Bottom);
if (!this.m_stretch_textarea)
{
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.HotkeyPrefix = HotkeyPrefix.None;
format.Trimming = StringTrimming.EllipsisCharacter;
format.FormatFlags = StringFormatFlags.NoWrap;
g.DrawString(head.text, base.font, new SolidBrush(((state & DrawItemState.Selected) == DrawItemState.Selected) ? Color.Black : Color.Black), layoutRectangle, format);
}
else
{
StringFormat format2 = new StringFormat();
format2.Alignment = this.m_stringNoIconAlignment;
format2.LineAlignment = StringAlignment.Center;
format2.HotkeyPrefix = HotkeyPrefix.None;
format2.Trimming = StringTrimming.EllipsisCharacter;
format2.FormatFlags = StringFormatFlags.NoWrap;
g.DrawString(head.text, base.font, new SolidBrush(((state & DrawItemState.Selected) == DrawItemState.Selected) ? Color.Black : Color.Black), layoutRectangle, format2);
}
if (((state & DrawItemState.Focus) == DrawItemState.Focus) && this.m_show_focus)
{
ControlPaint.DrawFocusRectangle(g, layoutRectangle, Color.White, Color.Blue);
}
}
}
protected void draw_item_rectangle(Graphics g, Rectangle rect, headicon head, DrawItemState state)
{
if (!this.m_stretch_textarea && (head.icon != null))
{
g.FillRectangle(this.m_background_brush, Rectangle.FromLTRB(rect.Left, rect.Top, rect.Left + this.m_item_height, rect.Bottom));
}
Rectangle rectangle = Rectangle.FromLTRB(rect.Left + ((this.m_stretch_textarea || (head.icon == null)) ? 0 : this.m_item_height), rect.Top, rect.Right, rect.Bottom);
if ((state & DrawItemState.Selected) == DrawItemState.Selected)
{
g.FillRectangle(this.m_selected_brush, rectangle);
}
else
{
g.FillRectangle(this.m_background_brush, rectangle);
}
}
protected void draw_separator(Graphics g, Rectangle rect, listbox_widget.separator sept)
{
if (sept != null)
{
g.FillRectangle(this.m_background_brush, rect);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
format.HotkeyPrefix = HotkeyPrefix.Show;
format.Trimming = StringTrimming.EllipsisCharacter;
format.FormatFlags = StringFormatFlags.NoWrap;
using (Font font = new Font(base.font, FontStyle.Bold))
{
g.DrawString(sept.name, font, Brushes.Black, rect, format);
}
Rectangle rectangle = Rectangle.FromLTRB(rect.Left + 5, rect.Bottom - 2, rect.Right - 5, rect.Bottom - 1);
using (LinearGradientBrush brush = new LinearGradientBrush(rectangle, Color.Black, Color.White, LinearGradientMode.Horizontal))
{
g.FillRectangle(brush, rectangle);
}
}
}
public override bool get_item_text(listbox_widget host, int index, out string text)
{
object obj2 = host.Items[index];
if (!(obj2 is headicon))
{
text = null;
return false;
}
headicon headicon = (headicon) obj2;
text = headicon.text;
return true;
}
public override bool get_item_tooltip(listbox_widget host, int index, out string tooltip)
{
object obj2 = host.Items[index];
if (!(obj2 is headicon))
{
tooltip = null;
return false;
}
headicon headicon = (headicon) obj2;
if ((headicon.prompt != null) && (headicon.prompt.Length != 0))
{
tooltip = headicon.prompt;
return true;
}
if (headicon.text != null)
{
if (TextRenderer.MeasureText(headicon.text, base.font).Width > (host.ClientRectangle.Width - this.m_item_height))
{
tooltip = headicon.text;
return true;
}
tooltip = null;
return false;
}
tooltip = null;
return false;
}
public override void measure_host_item(listbox_widget host, MeasureItemEventArgs e)
{
object obj2 = host.Items[e.Index];
if (obj2 is listbox_widget.separator)
{
e.ItemHeight = base.font.Height + 10;
}
else
{
e.ItemHeight = this.m_item_height;
}
}
public int item_height
{
get
{
return this.m_item_height;
}
set
{
if ((value != this.m_item_height) && (0 < value))
{
this.m_item_height = value;
base.invalidate_hosts();
}
}
}
public StringAlignment noicon_string_alignment
{
get
{
return this.m_stringNoIconAlignment;
}
set
{
if (value != this.m_stringNoIconAlignment)
{
this.m_stringNoIconAlignment = value;
base.invalidate_hosts();
}
}
}
public bool show_focus
{
get
{
return this.m_show_focus;
}
set
{
if (value != this.m_show_focus)
{
this.m_show_focus = value;
base.invalidate_hosts();
}
}
}
public bool stretch_textarea
{
get
{
return this.m_stretch_textarea;
}
set
{
if (value != this.m_stretch_textarea)
{
this.m_stretch_textarea = value;
base.invalidate_hosts();
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -