我自定义一个控件,我想在控件内显示一个球,怎样让球的周围透明。
我用this.drawimage方法找不到透明项。

解决方案 »

  1.   


    //设置透明在构造函数里写
    SetStyle(ControlStyles.SupportsTransparentBackColor, true);
    this.BackColor = Color.Transparent;
      

  2.   

    this.TransparencyKey = this.BackColor(你想透明的颜色,比如COLOR.WHITE);
      

  3.   

    我在msdn中查到了usint system.draw.imageing;// Create image.
    Image newImage = imagePaint;// Create rectangle for source image.
    Rectangle srcRect = new Rectangle(new Point(0,0),imageFore.Size );
    GraphicsUnit units = GraphicsUnit.Pixel;// Create parallelogram for drawing adjusted image.
    Point ulCorner2 = new Point(0, 0);
    Point urCorner2 = new Point(imagePaint.Width, 0);
    Point llCorner2 = new Point(0, imagePaint.Height);
    Point[] destPara2 = { ulCorner2, urCorner2, llCorner2 };// Create image attributes and set large gamma.
    ImageAttributes imageAttr = new ImageAttributes();
    imageAttr.SetColorKey(Color.White, Color.White);// Draw adjusted image to screen.
    e.Graphics.DrawImage(newImage, destPara2, srcRect, units, imageAttr);