? asked in 電腦與網際網路程式設計 · 1 decade ago

VB程式設計問題!

1.圖中紅色圖形,按上鍵後會朝上移動50,同樣的,按下、左、右移動50!

2.案結束鍵後會結束此程式!

圖片在此~

http://img516.imageshack.us/img516/7466/17029460pw...

拜託 非常急,

麻煩各位高手幫忙~

Update:

Shape在哪裡?

我的版本是用Visual Basic 2005 Express 版

找不到Shape這個東西~

Update 2:

請問一下Shape的選項在哪裡?

判斷該如何寫呢?

抱歉抱歉,

原諒一下剛學VB不久的新手~

Update 3:

請問GDI+是什麼?

還有我開如何畫圓呢?

3 Answers

Rating
  • Thomas
    Lv 6
    1 decade ago
    Favorite Answer

    Imports System.Drawing

    Public Class Form1

    Dim x, y As Integer

    Dim g As Graphics

    Dim bc As Color

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    x = Me.Width \ 2 '一開始秀在Form的中心

    y = Me.Height \ 2

    g = Me.CreateGraphics

    bc = Me.BackColor

    End Sub

    Private Sub Form1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Me.Paint

    '因為Graphics所畫的都是暫時的

    '所以,如果Form重畫,要圓還顯示

    g.FillEllipse(Brushes.Red, New Rectangle(x - 10, y - 10, 20, 20))

    End Sub

    Private Sub Button_up_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_up.Click

    If y - 50 >= 10 Then y = y - 50

    g.Clear(bc)

    g.FillEllipse(Brushes.Red, New Rectangle(x - 10, y - 10, 20, 20)) '直徑20的圓

    End Sub

    Private Sub Button_down_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_down.Click

    If y + 50 <= Me.Height - 10 Then y = y + 50

    g.Clear(bc)

    g.FillEllipse(Brushes.Red, New Rectangle(x - 10, y - 10, 20, 20))

    End Sub

    Private Sub Button_left_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_left.Click

    If x - 50 >= 10 Then x = x - 50

    g.Clear(bc)

    g.FillEllipse(Brushes.Red, New Rectangle(x - 10, y - 10, 20, 20))

    End Sub

    Private Sub Button_right_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_right.Click

    If x + 50 <= Me.Width - 10 Then x = x + 50

    g.Clear(bc)

    g.FillEllipse(Brushes.Red, New Rectangle(x - 10, y - 10, 20, 20))

    End Sub

    Private Sub Button_Stop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Stop.Click

    End

    End Sub

    End Class

    2008-08-14 11:25:20 補充:

    方法很多,我做一個簡單的.

    1. 使用 GDI+

    2. Form 大小固定

    3. 圓不能移到 Form 的邊界外

    4. 四個方向 buttons 分別名為 Button_up, Button_down, Button_left, Button_down

    5. 結束按鈕 Button_stop

    6. Form1_Paint()是為了Form被其它視窗遮住, 或縮小後恢復, 或..., 圓還會顯示

  • Jerod
    Lv 4
    1 decade ago

    嘿!你要先有一個圖型或是圖片,讓你可以去移動它!

  • 1 decade ago

    放一個shape設成圓形及紅色…

    上下左右分別將left及top位置加減50就好了…

    如:Shape.left=Shape.left+50

    結束程式寫End就行了…

    2008-08-13 19:07:20 補充:

    記得加判斷…避免left及top出現負值會error…

Still have questions? Get your answers by asking now.