2012-11-12 2 views
0

checkBox을 텍스트와 틱의 맞춤 색상으로 그릴 수 있는지 궁금합니다. WndProc을 무시하고 WM_PAINT을 사용하여 가능하다고 들었지만 경험이 없습니다.다시 그릴 체크 박스

누군가 올바른 방향으로 나를 가리킬 수 있습니까?

+0

그렇다면 BackColor 및 ForeColor 속성을 사용하지 않는 이유는 무엇입니까? –

+0

예를 들어 진드기의 색상과 검정색의 색상을 원합니다. backColor/foreColor를 사용하여이 작업을 수행 할 수 없습니다. – p0enkie

+0

이것이 올바른 방향입니다. http://social.msdn.microsoft.com/Forums/en-US/winformsdesigner/thread/27932a94-b63b-4293-ae82-f10171691888/ – Blachshma

답변

2

여기 당신이 체크 박스를 다시 그릴 수있는 방법의 매우 기본적인 예이다 : 그것은 작동

public class CustomCheckBox : CheckBox 
    { 
     public CustomCheckBox() 
     { 
      this.SetStyle(ControlStyles.UserPaint, true); 
      this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); 
     } 

     protected override void OnPaint(PaintEventArgs pevent) 
     { 
      base.OnPaint(pevent); 
      if (this.Checked) 
      { 
       pevent.Graphics.FillRectangle(new SolidBrush(Color.Blue), new Rectangle(0, 0, 16, 16)); 
      } 
      else 
      { 
       pevent.Graphics.FillRectangle(new SolidBrush(Color.Red), new Rectangle(0, 0, 16, 16)); 
      } 
     } 
    } 

하지만 가장자리 주위의 매우 거친! 그러나 그것은 매우 기본적으로 사용자 정의 컨트롤을 그릴 수있는 방법을 보여줍니다.