精華區beta Visual_Basic 關於我們 聯絡資訊
※ 引用《amortization (阿呆)》之銘言: 明天要考VB 先來練習一下吧 首先把pictur1屬性anchor改成全部right,left,top,bottom 再令 dim j=10 '以下再大致修改 ---------------------- Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If i = 1 Then Picture1.Left = Picture1.Left - j If i = 2 Then Picture1.Left = Picture1.Left + j If i = 3 Then Picture1.Top = Picture1.Top - j If i = 4 Then Picture1.Top = Picture1.Top + j If Picture1.Left <= 0 Then j = -j If Picture1.Right >= Me.ClientSize.Width Then j = -j If Picture1.Top <= 0 Then j = -j If Picture1.Bottom >= Me.ClientSize.Height Then j = -j End Sub ---------------------- 其它一樣 有點不符題意 我還要複習其它的 就先不改啦\( ̄▽ ̄~*) 我的想法是 只有左上,左下,右上,右下四個變數 一樣是4個i 不同的地方 暗示左上的 If i = 1 Then Picture1.Left = Picture1.Left - j Picture1.Top = Picture1.Top - j endif 其它以此類推 自己完成會學的比較多哦^^ : 我是個VB新手~想請問一下有關picture的移動問題 : 嗯~下面是圖片垂直與水平移動的程式碼 : Dim i As Integer : Private Sub Command1_Click() : i = 1 '向左走 : Timer1.Enabled = True : End Sub : Private Sub Command2_Click() : i = 2 '向右走 : Timer1.Enabled = True : End Sub : Private Sub Command3_Click() : i = 3 '向上走 : Timer1.Enabled = True : End Sub : Private Sub Command4_Click() : i = 4 '向下走 : Timer1.Enabled = True : End Sub : Private Sub Command5_Click() : Timer1.Enabled = False '煞車 : End Sub : Private Sub Form_Load() : i = 0 : Timer1.Interval = 50 : End Sub : Private Sub Timer1_Timer() : If i = 1 Then : Picture1.Left = Picture1.Left - 100 : If Picture1.Left < 0 Then : Picture1.Left = Form1.Width : End If : End If : If i = 2 Then : Picture1.Left = Picture1.Left + 100 : If Picture1.Left > Form1.Width Then : Picture1.Left = 0 : End If : End If : If i = 3 Then Picture1.Top = Picture1.Top - 100 : If Picture1.Top < 0 Then : Picture1.Top = Form1.Height : End If : If i = 4 Then Picture1.Top = Picture1.Top + 100 : If Picture1.Top > Form1.Height Then : Picture1.Top = 0 : End If : End Sub : 現在想要讓picture是由form中心出發向左上射出碰到表單邊邊再反射回來(往右下) : 或者是向右上射出碰到表單邊邊再反射回來(往左下) : 那我必須修改哪些步驟呢?還是說必須重新寫程式碼? : 那該怎麼寫呢?麻煩各位替小妹解答唷^^先謝謝了~~ -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.115.229.222
amortization:非常謝謝喔^^ 推 61.223.135.114 04/21