Windows Form에 원형 단추를 만들었습니다. 버튼은 괜찮아. 유일한 문제는 배경과 다른 색상이되도록 내가 backColor를 goldenRod로 설정하기 위해서입니다. 그러나 단순히 원형 버튼 주위에 "goldenRod"큐브를 만듭니다 ... 어떻게하면 버튼 만 색상이되도록 만들 수 있습니까?Windows Form에 원형 단추 추가
public MainForm(){
InitializeComponent();
myButtonObject start = new myButtonObject();
EventHandler myHandler = new EventHandler(start_Click);
start.Click += myHandler;
start.Location = new System.Drawing.Point(5, 5);
start.Size = new System.Drawing.Size(101, 101);
start.BackColor=System.Drawing.Color.Goldenrod;
this.Controls.Add(start);
`}
void start_Click(Object sender, System.EventArgs e)
{
MessageBox.Show("Start");
}
public class myButtonObject : UserControl
{
// Draw the new button.
protected override void OnPaint(PaintEventArgs e)
{
Graphics graphics = e.Graphics;
Pen myPen = new Pen(Color.Black);
// Draw the button in the form of a circle
graphics.DrawEllipse(myPen, 0, 0, 100, 100);
myPen.Dispose();
}
}
+1 @LarsTech 또한'BackColor'를 재설정해야합니다. 그렇지 않으면'UserControl' 경계를 해당 색상으로 채 웁니다. 또는'OnPaintBackground' 메소드를 오버라이드하십시오. – Xenolightning