如何将列表框的背景设置为tranpesent [英] How to set backcolor of listbox to tranpesent

查看:99
本文介绍了如何将列表框的背景设置为tranpesent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在WinForm C#中有一个列表框。如何将此列表框的背景颜色设置为tranpesent?



我试过

  private   void  Form2_Load( object  sender,EventArgs e)
{
listbox1.BackColor = Color.Transparent;
}





但它不起作用!

解决方案

< blockquote>透明不会按照您的想法执行。尝试阅读它上面的文档。



透明告诉控件采用父容器控件的背景属性。它不会使控件真正透明。它只是通过使控件背景与容器背景的属性相匹配来给出错觉。



Google [ ^ ]


我怀疑这是你想要的,但是如果你想让ListBox在表单中显示为一个剪切,你可以将Form的TransparencyKey属性设置为一些Color,并将ListBox BackColor属性设置为相同的颜色。



当然,其他方法可以做到这一点,因为Dave推荐给你的链接会显示你,涉及对ListBox进行子类化。



根据我对Win Forms的体验,我从未发现任何使用透明度的任何令人满意的结果。

I have a listbox in WinForm C#. How do I set the backcolor of this listbox to tranpesent?

I tried

private void Form2_Load(object sender, EventArgs e)
{
    listbox1.BackColor = Color.Transparent;
}



But it doesn't work!

解决方案

Transparent doesn't do what you think it does. Try reading the documentation on it.

Transparent tells the control to take on the background properties of the parent container control. It does NOT make the control really transparent. It just gives the illusion by making the control background match the properties of the container background.

Google[^]


I doubt this is what you want, but if you want to have the ListBox appear as a cut-out in the Form, you can set the TransparencyKey property of the Form to some Color, and set the ListBox BackColor property to the same Color.

Of course, the other ways to do this, as the links that Dave referred you to will show you, involve sub-classing the ListBox.

In my experience with Win Forms, I've never found any satisfactory results with any attempt at using transparency.


这篇关于如何将列表框的背景设置为tranpesent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆