2017年12月6日 星期三

VB2010 ch9視窗程式設計

VB2010 視窗程式設計


下載

https://sites.google.com/site/changsmallyi/dang-an-xia-zai/VB2010%20Express.zip?attredirects=0&d=1



Mail 至  alex9ufo@gmail.com
課後作業1   project 壓縮檔案
課後作業2   project 壓縮檔案
•將blog Address mail至  alex9ufo@gmail.com




下載PPT + PDF
https://www.mediafire.com/file/d9haqp3vo9u6n7y/CH9.rar      PPT + PDF






09
井字圈叉連線遊戲設計





五子棋黑白橫輪替

Public Class Form1
    Dim P(,) As Boolean
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load
        ReDim P(Me.ClientSize.Width \ 50, Me.ClientSize.Height \ 50)
        Dim bg As New Bitmap(Me.ClientSize.Width, Me.ClientSize.Height)
        Dim g As Graphics = Graphics.FromImage(bg)
        For i As Integer = 50 To Me.ClientSize.Width Step 50
            g.DrawLine(Pens.Black, i, 0, i, Me.ClientSize.Height)
        Next
        For j As Integer = 50 To Me.ClientSize.Height Step 50
            g.DrawLine(Pens.Black, 0, j, Me.ClientSize.Width, j)
        Next
        Me.BackgroundImage = bg
    End Sub

    Dim T As Boolean
    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
    Handles Me.MouseDown
        Dim cx As Integer = Math.Round(e.X / 50)
        Dim cy As Integer = Math.Round(e.Y / 50)
        If cx > 0 And cy > 0 And P(cx, cy) = False Then
            Dim bg As New Bitmap(Me.BackgroundImage)
            Dim g As Graphics = Graphics.FromImage(bg)
            Dim px As Integer = cx * 50 - 20
            Dim py As Integer = cy * 50 - 20
            If T Then
                g.FillEllipse(Brushes.White, px, py, 40, 40)
            Else
                g.FillEllipse(Brushes.Black, px, py, 40, 40)
            End If
            g.DrawEllipse(Pens.Black, px, py, 40, 40)
            P(cx, cy) = True
            T = Not (T)
            Me.BackgroundImage = bg
        End If
    End Sub
End Class



井字遊戲

Public Class Form1

    Dim T As Boolean

    Private Sub C1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles C1.Click, C2.Click, C3.Click, C4.Click, C5.Click, C6.Click, C7.Click, _
    C8.Click, C9.Click
        If Label1.Text = "" Then
            If sender.Text = "" Then
                If T = True Then
                    sender.Text = "X"
                Else
                    sender.Text = "O"
                End If
                T = Not (T)
                If chkWin() <> "" Then
                    Label1.Text = chkWin() + " win!"
                End If
            End If
        End If
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
    Handles MyBase.Load, Button1.Click
        For Each c In Me.Controls
            If TypeOf (c) Is Label Then
                c.text = ""
            End If
        Next
    End Sub

    Function chkWin() As String
        If C1.Text + C2.Text + C3.Text = "OOO" Then Return "O"
        If C4.Text + C5.Text + C6.Text = "OOO" Then Return "O"
        If C7.Text + C8.Text + C9.Text = "OOO" Then Return "O"
        If C1.Text + C4.Text + C7.Text = "OOO" Then Return "O"
        If C2.Text + C5.Text + C8.Text = "OOO" Then Return "O"
        If C3.Text + C6.Text + C9.Text = "OOO" Then Return "O"
        If C1.Text + C5.Text + C9.Text = "OOO" Then Return "O"
        If C3.Text + C5.Text + C7.Text = "OOO" Then Return "O"
        If C1.Text + C2.Text + C3.Text = "XXX" Then Return "X"
        If C4.Text + C5.Text + C6.Text = "XXX" Then Return "X"
        If C7.Text + C8.Text + C9.Text = "XXX" Then Return "X"
        If C1.Text + C4.Text + C7.Text = "XXX" Then Return "X"
        If C2.Text + C5.Text + C8.Text = "XXX" Then Return "X"
        If C3.Text + C6.Text + C9.Text = "XXX" Then Return "X"
        If C1.Text + C5.Text + C9.Text = "XXX" Then Return "X"
        If C3.Text + C5.Text + C7.Text = "XXX" Then Return "X"
        Return ""
    End Function


End Class





課後作業1

海拔高度每上升一百公尺,氣溫下降攝氏○.六度,雖然這是簡單的常識,卻少有人正確運用在登山活動。比方說氣象預報台灣某都市,夏天氣溫攝氏三十三度。海拔僅八百公尺的郊山, 依據此原理推算,氣溫可能比平地低了攝氏四八度,三十三度減掉約度似乎相當溫暖,不需要多帶衣服。
*************************************************************
[作業2] 請你設計一個程式,幫助登山者算看看山上的溫度為幾度?
輸入:使用者輸入平地溫度、山的高度(即海拔?公尺),再按下"夏季"或"冬季"按鈕
輸出:?度
公式:夏季海拔高度每上升100公尺氣溫約降低0.6度,而冬季每上升100公尺約降低0.36度。
參考畫面如下:


作業要求:
1.表單標題為   學號_估計山上溫度
2.Textbox、Button、Label物件之字體大小為12點;山上溫度之Enable屬性設成不能點選更改
3.請將 Textbox值(即平地溫度、山的高度)儲存為變數
4.程式碼每一行請加上註解 (')
5.作業檔名: 學號_作業 2.zip

6.請mail至    alex9ufo@gmail.com
請~勿~抄~襲!!!!!


課後作業2
解二次方程式AX^2+BX+C=0 

表單設計與程式執行:

表單設計



執行畫面





控制項屬性資料:
Form1   : 調整表單視窗的大小,使Width和Height合乎適當大小。
Label1  : Caption = "A="
Label2  : Caption = "B="
Label3  : Caption = "C="
Label4  : Caption = "解一元二次方程式AX^2+BX+C=0"
Label5  : Caption = "判別式B^2-4AC="
Label6  : Caption = "根的性質"
Label7  : Caption = "X1 ="
Label8  : Caption = "X2 ="
Label9  : Caption = "機1-3 王小明製作"
Label10 : Caption = "學號:2902001"
Text1   : Text = "1"
Text2   : Text = "2"
Text3   : Text = "3"
Text4   : Text = ""
Text5   : Text = ""
Text6   : Text = ""
Text7   : Text = ""
程式碼列表:
Public A, B, C, D As Single

Private Sub Command1_Click()
  A = Val(Text1.Text)
  B = Val(Text2.Text)
  C = Val(Text3.Text)
'-------------------------------
  If B >= 0 Then
     G1$ = "+"
     Else
     G1$ = "-"
  End If
  If C >= 0 Then
     G2$ = "+"
     Else
     G2$ = "-"
  End If
'-------------------------------------------------------------------------
U$ = Str(A) + "X^2" + G1$ + Str(Abs(B)) + "X" + G2$ + Str(Abs(C)) + "= 0"
Label4.Caption = "一元二次方程式" + U$

D = B * B - 4 * A * C
Text4.Text = Str(D)

Select Case D
   Case Is >= 0
      X1 = -B / (2 * A) + Sqr(D) / (2 * A)
      X2 = -B / (2 * A) - Sqr(D) / (2 * A)
      If D > 0 Then Text5.Text = "有二不等實數根(實根)"
      If D = 0 Then Text5.Text = "有二相等實數根(重根)"
      Text6.Text = Str(X1)
      Text7.Text = Str(X2)
   Case Is < 0
     U = -B / (2 * A)
     V = Sqr(Abs(D)) / (2 * A)
     Text5.Text = "其解為共軛複根(虛根)"
     Text6.Text = Str(U) + "+" + Str(V) + "i"
     Text7.Text = Str(U) + "-" + Str(V) + "i"
   End Select

End Sub

Private Sub Command2_Click()
End
End Sub


沒有留言:

張貼留言

WOKWI LED + MQTT Node-Red SQLite

WOKWI LED + MQTT Node-Red SQLite const char *mqtt_broker = "broker.mqtt-dashboard.com" ; const char *topic1 = "alex9ufo/e...