C#中把ListBox中的背景改为透明的代码,谁能提供? 就是我想把ListBox的背景编程时透明的,我知道是重写它里面的OnPaint方法可是,我是新手,不会写,谁会写?谢谢帮忙! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用写,将窗体的Transparencykey设置成ListBox的背景色就可以了。 设置背景图片或Transparent ListBox不支持透明背景.这需要你自己做一个类似LISTBOX的自定义控件. 我主要就是想让ListBox的背景改为透明的,我窗体添加了一张背景,怎么改呀。 就是呀,ListBox不能通过属性设置成透明,需要重写,可我不会若真能设置,又该怎么做高手请指点!!!谢谢 貌似,你是GDI+的高手,可否帮忙? 想法不错,下看dilike大哥怎么解决 把ListView的背景改成你窗口里没有的颜色,比如没有Red就改成Red,然后设置Form的 Transparencykey=Color.Red 就行了 ListBox中没有吧背景设置为透明的功能,除非重新写他里面的一个方法,好像是OnPaint可是我不会重写希望高手指教 //仅供参考 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(this.Items[i]), this.Font, new SolidBrush(this.ForeColor), this.GetItemRectangle(i)); } base.OnPaint(e); } } Windows Mobile 上 不支持 GetItemRectangle() 呀 ! 那Windows Mobile 上该么样实现呢? 请问楼主您怎么解决的?我也把那位大哥的代码放了进去,但无法实现透明,是不是重写的OnPaint方法里面的代码需要改动?能将代码给我看看吗?谢谢! 你们谁有那个OnPaint方法的源代码?谢谢! stringsplitoptions 无效 一个郁闷的问题,求教 求正则表达式。 关于设置form窗口图标的问题 请问这个为什么插不入数据库呢? C#应用程序如何做成窗户端程序 ++++++求解决一个从基类库派生类应用时出现在的一个问题!++++++ 猜想System.Diagnostics.Process内部执行机制 你的几分钟,会让祖国更强大!!! 线程中的回调函数如何获得返回值,请高手开悟,在线等...... web应用程序如何同步域用户 WinForm 类似360的悬浮提示如何做的? [图]
或Transparent
若真能设置,又该怎么做
高手请指点!!!
谢谢
Transparencykey=Color.Red
就行了
可是我不会重写
希望高手指教
//仅供参考
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(this.Items[i]), this.Font,
new SolidBrush(this.ForeColor), this.GetItemRectangle(i));
}
base.OnPaint(e);
} }
方法里面的代码需要改动?能将代码给我看看吗?
谢谢!