양식에 사용자 정의 컨트롤을 표시하려고합니다. usercontrol은 새의 gif 이미지가있는 그림 상자입니다.양식에 Usercontrol이 표시됩니다.
//main form
class Form1
{
//play button
private void gameButton1_Click(object sender, EventArgs e)
{
startPanel.Visible = false;
Game g = new Game(this.gamePanel1);
g.Start();
}
}
class Game
{
//is set to true after starting game
public Game(gamePanel Display)
{
this.Display = Display;
}
bool Running = false;
public gamePanel Display;
public void Start()
{
Thread create_BirdsThread = new Thread(new ThreadStart(create_Birds));
create_BirdsThread.Start();
Running = true;
}
private void create_Birds()
{
while (Running)
{
//Display is a variable from class 'GamePanel'
Display.CreateBirds();
Display.Refresh();
//this is just to test that one bird works
Running = false;
}
}
}
class gamePanel : UserControl
{
public void CreateBirds()
{
yBird y = new yBird();
y.BackColor = System.Drawing.Color.Transparent;
y.Location = new System.Drawing.Point(32, 56);
y.Size = new System.Drawing.Size(96, 65);
y.TabIndex = 1;
if (this.InvokeRequired)
{
this.BeginInvoke((MethodInvoker)delegate()
{
this.Controls.Add(y);
});
}
else
{
this.Controls.Add(y);
}
y.Visible = true;
y.BringToFront();
}
}
을하지만 내 화면에 새를 표시하지 않습니다
내가 이렇게 노력하고 있어요. 이 문제를 해결하는 방법은 무엇입니까?감사합니다.
* 편집 :
내가 내 주요 형태와 Game.Start() 메소드
에
은 당신이 불렀다이 변경? 또한 어떤 종류의 programm, WinForms, WPF ASP, XNA .....를 작성하는지 명확히하기 위해 질문에 태그를 추가하십시오. – TaW
@TaW : 편집 참조 – JoJo
yBird 클래스도 표시 할 수 있습니까? –