나는 내 자신의 "ThemeManager"클래스를 사용하여 양식의 스타일을 지정하는 응용 프로그램을 가지고 있습니다. 상당히 기본적인 것들 - 저는 웹 응용 프로그램을 위해 CSS 작업을하는 데 익숙합니다.이 양식을 응용 프로그램 (WPF 일 수는 없습니다)으로 작성하고 있습니다. , 내가 양식을 전달할 수있는 ThemeManager 클래스를 사용하여 양식을 스타일링하고있어 이와 같이양식의 onPaint 이벤트를 사용자 정의 클래스로 이동하는 방법은 무엇입니까?
는 스타일 수 :
예를 테마 관리자에서 :
public void setTheme(Form sender)
{
// Set background and foreground colors
sender.BackColor = ColorTranslator.FromHtml("#222222");
sender.ForeColor = ColorTranslator.FromHtml("#A6CE39");
// Loop through controls on form
foreach (Control c in sender.Controls)
{
if (c is Button) // Set the button style
{
Button btn = c as Button;
btn.BackColor = ColorTranslator.FromHtml("#222222");
btn.FlatStyle = FlatStyle.Flat;
btn.FlatAppearance.BorderSize = 0;
}
if ((c is ComboBox) || (c is TextBox)) // Set dropdown and textbox style
{
c.ForeColor = ColorTranslator.FromHtml("#A6CE39");
c.BackColor = ColorTranslator.FromHtml("#2e2e2e");
}
}
}
양식을 제목 표시 줄과 테두리가 없지만 매우 간단한 테두리를 설정하고 싶습니다. 디자이너에두고
public void RemoteControl_Paint(object sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(ColorTranslator.FromHtml("#A6CE39"), 3),
this.DisplayRectangle);
}
을 : 순간 나는 각 폼에의 OnPaint 이벤트를 설정하여이 작업을 수행 할
this.Paint += new System.Windows.Forms.PaintEventHandler(this.RemoteControl_Paint);
는 그러나, 나는 각 양식에이 작업을 수행 할 수 있고, 반면에 내가 좋겠 오히려 테마 매니저를 통해하십시오.
나는 그림 참고 방법이 추가 시도했다 :
sender.Paint += new PaintEventHandler(MyForm_Paint);
그리고 ThemeManager.cs 클래스에이 방법을 추가 :
private void MyForm_Paint(Form sender, PaintEventArgs e)
{
e.Graphics.DrawRectangle(new Pen(ColorTranslator.FromHtml("#A6CE39"), 3),
sender.DisplayRectangle);
}
이 작동하지 않습니다 - 내가 과부하를 얻을 수 오류 :
No overload for 'MyForm_Paint' matches delegate 'System.Windows.Forms.PaintEventHandler'
어떻게하면됩니까?
Spot on! 대단히 고마워요. – Ben