[C#] - 사용자 컨트롤 투명 처리 ( User Control with transparent background )
C# 2008. 3. 3. 00:10 |사용자 컨트롤 배경 투명색으로 처리 하기
이 부분은 뒷 배경을 투명으로 바꾸기는 하지만 Flicker 처리가 되지 않아서
이동시 잔상이 생기게 되네요.
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace transcontroldemo
{
/// <summary>
/// Summary description for TransPanel.
/// </summary>
public class TransPanel : Panel
{
public TransPanel()
{
//
// TODO: Add constructor logic here
//
}
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x00000020; //WS_EX_TRANSPARENT
return cp;
}
}
protected void InvalidateEx()
{
if (Parent == null)
return;
Rectangle rc = new Rectangle(this.Location, this.Size);
Parent.Invalidate(rc, true);
}
protected override void OnPaintBackground(PaintEventArgs pevent)
{
//do not allow the background to be painted
}
protected override void OnResize(EventArgs eventargs)
{
this.InvalidateEx();
}
Random r = new Random();
protected override void OnPaint(PaintEventArgs e)
{
int h = this.Height / 2;
int w = this.Width;
Pen p = new Pen(Color.White, 2);
e.Graphics.DrawLine( p, 0,h, w, 0);
p.Dispose();
}
}
}