0
我在WindowsForms中有一个组合框,并且我手动绘制了项目。每个项目由图片和文字组成,因此项目为34 px高度。组合框DropDownList和图片和文字中的项目
我想将DropDownStyle的ComboBox设置为DropDownList以启用用户输入。但是当我选择一些项目时,它会变形,因为图片和文字是可见的。如果用户选择某个项目,我只想显示文本。
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
if (e.Index > -1)
{
Piece item = this.Items[e.Index] as Piece;
e.Graphics.FillRectangle(Brushes.Gray, new Rectangle(e.Bounds.Left + 6, e.Bounds.Top + 6, 22, 22));
e.Graphics.DrawImage(item.Image, new Rectangle(e.Bounds.Left + 7, e.Bounds.Top + 7, 20, 20));
e.Graphics.DrawString(item.Title, e.Font,
new SolidBrush(e.ForeColor), e.Bounds.Left + 34, e.Bounds.Top + 10);
}
e.DrawFocusRectangle();
}
感谢
1)我的意思是设定DropDownStyle = ComboBoxStyle.DropDownList 2)http://www.imagebam.com/image/26d4f1121064349这是确定,我绘制项目。 http://www.imagebam.com/image/58139c121064355我看到这个,当我选择一些项目 – austinem 2011-02-25 14:42:34
你的图像没有损坏,他们被剪辑。你只用15-20的控制就可以画出32像素的高画质。要有不同的绘制逻辑,请关闭e.State - 查看我更新的帖子。 – 2011-02-25 19:12:28