2014-02-05 46 views
0

所以,我有我試圖建立一個if語句,以便當BallTargetTarget將採取對Ball的彩色屏幕(Ball & Target)左右移動的兩個對象(黑色)。GET對象顏色if語句

問題是應用程序背景正在改變,而不是目標顏色。有人能看到我出錯的地方嗎?

代碼

if (Ball.Bounds.IntersectsWith(Target.Bounds)) 
{ 
    this.BackColor = Color.Black; 
} 
else 
{ 
    this.BackColor = Color.Red; 
} 

回答

2

那麼你需要設置Target的顏色,不this(這顯然是指向你的主窗口)。

if (Ball.Bounds.IntersectsWith(Target.Bounds)) 
{ 
    Target.BackColor = Color.Black; 
} 
else 
{ 
    Target.BackColor = Color.Red; 
} 
+0

很簡單,謝謝。 – Beep