📄 gimagecombox.cs
字号:
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Diagnostics;
using System.ComponentModel.Design;
using System.Drawing.Design;
namespace gowk.controls
{
/// <summary>
/// GImageCombox 的摘要说明。
/// </summary>
public class GImageCombox:GComboxBase
{
public GImageCombox():base()
{
this.EditControl=new Control();
this.EditControl.Visible=false;
this.SelectedIndexChanged+=new EventHandler(GImageCombox_SelectedIndexChanged);
this.BackColor=Color.White;
}
protected override void OnDrawItem(System.Windows.Forms.DrawItemEventArgs e)
{
if(e.Index==-1)return;
bool focus=(e.State & DrawItemState.Focus)==DrawItemState.Focus;
GComboxItem item=(GComboxItem)this.Items[e.Index];
Rectangle imgRect=e.Bounds;
imgRect.Inflate(-2,-2);
if(focus)
{
imgRect.Offset(-1,-1);
// e.Graphics.FillRectangle(new SolidBrush(System.Drawing.SystemColors.Control),e.Bounds);
}
e.Graphics.FillRectangle(new SolidBrush(this.BackColor),e.Bounds);
//draw image
if(item.Image!=null)
{
e.Graphics.DrawImage(item.Image,imgRect);
}
if(focus)
e.DrawFocusRectangle();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
this.OnDrawItem(new DrawItemEventArgs(e.Graphics,this.Font,this.ClientRectangle,this.SelectedIndex,DrawItemState.Default));
}
private void GImageCombox_SelectedIndexChanged(object sender, EventArgs e)
{
this.Invalidate();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -