: .NET CF 지정 컨트롤 : RoundedGroupBoxGDI RoundRect : 둥근 사각형의 외부에 투명하게
모든 컨트롤이 정사각형 때문에,도를 둥근 사각형 밖에서 모서리를 그립니다. 사각형 외부에이 공간을 투명하게 만들려면 어떻게해야합니까?
의 OnPaint 방법은 다음과 같습니다
protected override void OnPaint(PaintEventArgs e)
{
int outerBrushColor = HelperMethods.ColorToWin32(m_outerColor);
int innerBrushColor = HelperMethods.ColorToWin32(this.BackColor);
IntPtr hdc = e.Graphics.GetHdc();
try
{
IntPtr hbrOuter = NativeMethods.CreateSolidBrush(outerBrushColor);
IntPtr hOldBrush = NativeMethods.SelectObject(hdc, hbrOuter);
NativeMethods.RoundRect(hdc, 0, 0, this.Width, this.Height, m_diametro, m_diametro);
IntPtr hbrInner = NativeMethods.CreateSolidBrush(innerBrushColor);
NativeMethods.SelectObject(hdc, hbrInner);
NativeMethods.RoundRect(hdc, 0, 18, this.Width, this.Height, m_diametro, m_diametro);
NativeMethods.SelectObject(hdc, hOldBrush);
NativeMethods.DeleteObject(hbrOuter);
NativeMethods.DeleteObject(hbrInner);
}
finally
{
e.Graphics.ReleaseHdc(hdc);
}
if (!string.IsNullOrEmpty(m_roundedGroupBoxText))
{
Font titleFont = new Font("Tahoma", 9.0F, FontStyle.Bold);
Brush titleBrush = new SolidBrush(this.BackColor);
try
{
e.Graphics.DrawString(m_roundedGroupBoxText, titleFont, titleBrush, 14.0F, 2.0F);
}
finally
{
titleFont.Dispose();
titleBrush.Dispose();
}
}
base.OnPaint(e);
}
OnPaintBackground는 다음과 같습니다
protected override void OnPaintBackground(PaintEventArgs e)
{
if (this.Parent != null)
{
SolidBrush backBrush = new SolidBrush(this.Parent.BackColor);
try
{
e.Graphics.FillRectangle(backBrush, 0, 0, this.Width, this.Height);
}
finally
{
backBrush.Dispose();
}
}
}
감사합니다!
컨트롤이 여전히 투명 영역에서 입력을 받기 때문에 포스터에는 작동하지 않을 수 있습니다. 이 문제를 방지하려면 CreateRectRgn (http://msdn.microsoft.com/en-us/library/ms908184.aspx) 또는 ExtCreateRegion (http://msdn.microsoft.com/en-us/library/aa920742.aspx) 함수가 사용되어야합니다. –
질문에 "나는 어떻게 지역을 입력을받지 못하게 할 것인가"가 아니라 "나는 어떻게 regoin을 투명하게 만들지"하는 것처럼 보인다. 후자의 경우 CreateRectRegion은 CF 개발자에게별로 유용하지 않습니다. – ctacke
영역을 투명하게 만들고 싶습니다. SetColorKey는 e.Graphics.GetHdc()를 사용하기 때문에 작동하지 않습니다. 투명도가있는 이미지를 그리는 데 사용합니다. – VansFannel