-1
對於我的其中一個項目,我需要編寫一個程序來顯示產品列表,並在其左側顯示一個支票和/或十字。我把一切都整理,除了部分 我也碰到過這個問題的形式:c#中的窗體錯誤
class Presentation
{
static Form Window = new Form();
static public void Configuration()
{
Window.Height = 800;
Window.Width = 800;
Window.Text = "Homework";
Graphics draw = Window.CreateGraphics();
Window.Paint += Window_Paint();
Window.Show();
}
void Window_Paint(System.Object sender, PaintEventArgs e)
{
AnyOtherConfigurations(e);
}
static public void AnyOtherConfigurations(PaintEventArgs e)
{
Pen pen1 = new Pen(Color.Red);
Font font = new Font(FontFamily.GenericSansSerif, 8,
FontStyle.Regular, GraphicsUnit.Millimeter);
Graphics draw = Window.CreateGraphics();
e.Graphics.FillEllipse(new SolidBrush(Color.Yellow),x,y,80,80);
draw.DrawRectangle(pen1, 0, 0, 90, 90);
}
}
它給我,說錯誤:
CS7036 There is no argument given that corresponds to the required formal parameter 'sender' of 'UserQuery.Presentation.Window_Paint(object, PaintEventArgs)'
CS0029 Cannot implicitly convert type 'void' to 'System.Windows.Forms.PaintEventHandler'
任何人都可以提出一個原因,這可能發生,給我建議如何解決它?
當您附加事件時,您將調用帶有零參數的「Window_Paint」。刪除parntheses:此時你不想打電話給你的處理程序。 – Richard
_Graphics draw = Window.CreateGraphics(); _和_Graphics draw = Window.CreateGraphics(); _永遠不要這樣!結果將不會持續!使用已經擁有的'PaintArgs'中的'e.Graphics'! - 切勿使用'control.CreateGraphics'!切勿嘗試緩存'Graphics'對象!可以使用'e.Graphics'參數使用'Graphics g = Graphics.FromImage(bmp)'或者在控件的Paint事件中繪製一個'Bitmap bmp'。 – TaW
你可以測試你的持久性通過做一個最小化/最大化序列的圖形 – TaW