3个回答
展开全部
//自定义控件, 然后在工具箱拖过来用 再把BackColor 设置为Transparent
public partial class TransparentListBox : ListBox
{
public TransparentListBox()
{
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
}
protected override void OnSelectedIndexChanged(EventArgs e)
{
this.Invalidate();
base.OnSelectedIndexChanged(e);
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.Focused && this.SelectedItem != null)
{
Rectangle itemRect = this.GetItemRectangle(this.SelectedIndex);
e.Graphics.FillRectangle(Brushes.Green, itemRect);
}
for (int i = 0; i < Items.Count; i++)
{
e.Graphics.DrawString(this.GetItemText(Items[i]), this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i));
}
base.OnPaint(e);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询