如何將文字顯示在視窗新建表單(newForm)上?(VB)

我的程式碼如下:

Private Sub btnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click

Dim subj As String = ""

Dim show As String = ""

Dim score As Integer

Dim b As Integer

Dim c As Integer

Dim newForm As New Form

newForm.Text = "上課老師"

newForm.FormBorderStyle _

= Windows.Forms.FormBorderStyle.FixedSingle

newForm.StartPosition = FormStartPosition.CenterScreen

newForm.Size = New Size(200, 200)

newForm.BackColor = Color.Yellow

newForm.Opacity = 0.8

newForm.Show()

show &= "選課資料如下:" & vbCrLf

show &= "-------------------------------" & vbCrLf

show &= "科目" & vbTab & vbTab & "學分" & vbCrLf

show &= "-------------------------------" & vbCrLf

For Each subj In lsbShow.Items

Select Case subj

Case "國文"

score = 4

b = b + 4

c = c + 1

Case "英文"

score = 3

b = b + 3

c = c + 1

Case "數學"

score = 5

b = b + 5

c = c + 1

End Select

show &= subj & vbTab & vbTab & score & vbCrLf

Next

show &= "-------------------------------" & vbCrLf

show &= "總計:" & c & "科目," & b & "學分" & vbCrLf

TextBox1.Text = show

End Sub

End Class

不知道要怎麼打~

請各位高手們~幫幫忙~謝謝^^

Update 3:

我的程式碼要打什麼才會跟上圖完成品一樣呢???

Update 4:

打好測試之後~選"國文"在newForm上卻顯示出"國文:李國"

正確的應該會顯示出"國文:李國文老師"啊~怎麼會這樣...

還有再選"英文"newForm上應該會顯示出"國文:李國文老師"和"英文:吳英文老師"啊!!!

可是怎麼還是只有顯示"國文:李國"呢???

怎麼辦??????

其他以此類推....

1 Answer

Rating
  • C H-Y
    Lv 5
    7 years ago
    Favorite Answer

    不知道你想要怎放控制項

    你可以插入下段程式碼,再依你的需求變更

    '在newform建立Label

    Dim a As New Label

    a.Text = "12333"

    a.Location = New Point(10, 10)

    a.Font = New Font("Arial", 12)

    newForm.Controls.Add(a)

    '在newform建立TextBox

    Dim t As New TextBox

    t.Text = "Textbox"

    t.Location = New Point(10, 30)

    t.Font = New Font("Arial", 12)

    newForm.Controls.Add(t)

    2012-11-09 16:29:41 補充:

    程式碼有點長 我分段貼

    btnList_Click 的程式碼

    Dim subj As String = ""

    Dim show As String = ""

    Dim Teacher As String = "" '準備放到newform Label的字串

    Dim score As Integer

    Dim b As Integer

    Dim c As Integer

    2012-11-09 16:29:53 補充:

    'Create Newform

    Dim newForm As New Form

    newForm.Text = "上課老師"

    newForm.FormBorderStyle _

    = Windows.Forms.FormBorderStyle.FixedSingle

    newForm.StartPosition = FormStartPosition.CenterScreen

    newForm.Size = New Size(200, 200)

    newForm.BackColor = Co

    2012-11-09 16:30:04 補充:

    '這裡差程式碼(在newform中建立lable控制項)

    Dim a As New Label

    a.Text = "12333"

    a.Location = New Point(10, 10)

    a.Font = New Font("Arial", 12)

    newForm.Controls.Add(a)

    '----------------------------------

    newForm.Show()

    2012-11-09 16:30:55 補充:

    show &= "選課資料如下:" & vbCrLf

    show &= "-------------------------------" & vbCrLf

    show &= "科目" & vbTab & vbTab & "學分" & vbCrLf

    show &= "-------------------------------" & vbCrLf

    For Each subj In lsbShow.Items

    Select Case subj

    Case "國文"

    2012-11-09 16:32:15 補充:

    2012-11-09 16:38:45 補充:

    貼不上來了= =

    http://ichying.weebly.com/buffer.html

    2012-11-09 16:39:00 補充:

    我把程式碼放在這網址

    2012-11-09 20:38:19 補充:

    補充那邊我貼不上去了

    因為label長寬太小

    加入下面程式碼

    方法一:

    a.Width = 300

    a.Height = 100

    或者

    方法二:

    a.Dock = DockStyle.Fill

    2012-11-09 20:54:15 補充:

    建議你可以把

    Dim newForm As New Form

    Dim a As New Label

    放在btnList_Click外面

    作為全域變數

    這樣當btnList_Click時,不會再出現新的newform

    也可直接更新newform的label

    我把新的程式碼放到這裡了

    http://ichying.weebly.com/buffer.html

    • Login to reply the answers
Still have questions? Get your answers by asking now.