我需要移動一個PictureBox表單內。該picturebox是Fantasma1。從圖片框的形式出去C#
這是我做的,當一個定時器(移動圖片框)蜱:
private void Move_Tick(object sender, EventArgs e)
{
Completamento.Increment(1);
while (Fantasma1.Location.X < MAX.X)
Fantasma1.Location = new System.Drawing.Point(Fantasma1.Location.X + 1, Fantasma1.Location.Y);
Move.Stop();
MessageBox.Show("Location: " + Fantasma1.Location.X + ";" + Fantasma1.Location.Y + ", larghezza del form: " + this.Width + ", dimensione della picture: " + Fantasma1.Width);
}
在窗體的構造函數中我做:
MAX.X = this.Width - Fantasma1.Size.Width;
我認爲這個解決方案是正確的,但我的圖片框從表單中退出。 任何人都可以幫助我嗎?
你能告訴你的'Form'的完整構造?我猜你在調用InitializeComponent之前設置了'MAX.X = ...'。因此'this.Width'以及'Fantasma1.Size.Width'可能還沒有被正確設置,導致錯誤的'MAX.X'。 –
不,'MAX.X'被設置在'InitializeComponent'之後。 '公共Form1中() { 的InitializeComponent(); MAX.X = this.Width - Fantasma1.Size.Width; }' – Clyky
您是否調試過您的代碼?使用什麼值?順便說一句:你的'while'循環沒有意義。可見的結果將是最後一個位置。你的'Form'和'PictureBox'在循環運行時不會重畫,所以你不會看到任何「移動」。 –