就是我想把ListBox的背景编程时透明的,我知道是重写它里面的OnPaint方法
可是,我是新手,不会写,谁会写?
谢谢帮忙!

解决方案 »

  1.   

    不用写,将窗体的Transparencykey设置成ListBox的背景色就可以了。
      

  2.   

    设置背景图片
    或Transparent
      

  3.   

    ListBox不支持透明背景.这需要你自己做一个类似LISTBOX的自定义控件.
      

  4.   

    我主要就是想让ListBox的背景改为透明的,我窗体添加了一张背景,怎么改呀。
      

  5.   

    就是呀,ListBox不能通过属性设置成透明,需要重写,可我不会
    若真能设置,又该怎么做
    高手请指点!!!
    谢谢
      

  6.   

    貌似,你是GDI+的高手,可否帮忙?
      

  7.   

    想法不错,下看dilike大哥怎么解决
      

  8.   

    把ListView的背景改成你窗口里没有的颜色,比如没有Red就改成Red,然后设置Form的
        Transparencykey=Color.Red
        就行了
      

  9.   

    ListBox中没有吧背景设置为透明的功能,除非重新写他里面的一个方法,好像是OnPaint
    可是我不会重写
    希望高手指教
      

  10.   


    //仅供参考
        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);
            }    }
      

  11.   

    Windows Mobile  上 不支持 GetItemRectangle() 呀 ! 那Windows  Mobile 上该么样实现呢?
      

  12.   

    请问楼主您怎么解决的?我也把那位大哥的代码放了进去,但无法实现透明,是不是重写的OnPaint
    方法里面的代码需要改动?能将代码给我看看吗?
    谢谢!
      

  13.   

    你们谁有那个OnPaint方法的源代码?谢谢!