SlideShare a Scribd company logo
1 of 5
Download to read offline
VB .NET 2005 By Warawut Khangkhan



                        ตวอยาง การใช ListBox และ ComboBox Control
ตวอยาง การใช ListBox และ ComboBox Control
                                                      1
                                             3                4               5              6           7         8
                            2

                                                                                               Label Control
                                                                                             Name: lblAmountList
       9                                  Label Control
                                    Name: lblAmountComboBox                                 11
                                                                                            12
                Label Control
                                               10
           Name: lblIndexComboBox                                         Label Control
                                                                       Name: lblIndexListBox


                                                                                  13
                                                                                       14              15



ตาราง การก,าหนด Properties ท45สาค8ญแต:ละ Control
                               ,
 No.        Control                      Properties                                         Values
  1 Form                   Name                                   Form1
                           StartPosition                          CenterScreen
                           Text                                   Example Using ListBox and ComboBox Control
  2 TextBox                Name                                   TextBox1
  3 Button                 Name                                   Button1
                           Text                                   Add Text
  4 Button                 Name                                   Button2
                           Text                                   Clear Text
  5 Button                 Name                                   Button5
                           Text                                   Run Number




                                                          -1-
VB .NET 2005 By Warawut Khangkhan


ตาราง การก,าหนด Properties ท45สาค8ญแต:ละ Control (ต:อ)
                               ,
 No.        Control                    Properties                               Values
  6 NumericUpDown          Name                                NumericUpDown1
                           Maximum                             10
                           Minimum                             1
  7 NumericUpDown          Name                                NumericUpDown2
                           Maximum                             10
                           Minimum                             1
  8 NumericUpDown          Name                                NumericUpDown3
                           Maximum                             10
                           Minimum                             1
  9 ComboBox               Name                                ComboBox1
                           DropDownStyle                       DropDownList
 10 ListBox                Name                                ListBox1
 11 Button                 Name                                Button4
                           Text                                RemoveAt
 12 Button                 Name                                Button6
                           Text                                Remove
 13 TextBox                Name                                TextBox2
 14 TextBox                Name                                TextBox3
 15 Button                 Name                                Button3
                           Text                                Insert Text




                                                         -2-
VB .NET 2005 By Warawut Khangkhan


Coding:
Public Class Form1

  Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
     ComboBox1.Items.Add(TextBox1.Text.Trim)
     ListBox1.Items.Add(TextBox1.Text.Trim)
     lblAmountList.Text = ListBox1.Items.Count
     lblAmountComboBox.Text = ComboBox1.Items.Count
     TextBox1.Focus()
  End Sub

  Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter
     TextBox1.SelectionStart = 0
     TextBox1.SelectionLength = TextBox1.Text.Length
  End Sub

  Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
     ComboBox1.Items.Clear()
     ListBox1.Items.Clear()
     lblAmountList.Text = "0"
     lblAmountComboBox.Text = "0"
     lblIndexComboBox.Text = "0"
     lblIndexListBox.Text = "0"
     TextBox1.Focus()
  End Sub

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     lblAmountList.Text = "0"
     lblAmountComboBox.Text = "0"
     lblIndexListBox.Text = "0"
     lblIndexComboBox.Text = "0"
  End Sub

   Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ListBox1.SelectedIndexChanged
      lblIndexListBox.Text = ListBox1.SelectedIndex + 1
   End Sub

  Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
ComboBox1.SelectedIndexChanged
     lblIndexComboBox.Text = ComboBox1.SelectedIndex + 1
  End Sub

  Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
     If Convert.ToInt32(TextBox3.Text) >= 0 And Convert.ToInt32(TextBox3.Text) <= ListBox1.Items.Count Then
        If Convert.ToInt32(TextBox3.Text) = 0 Then
           ListBox1.Items.Insert(TextBox3.Text, TextBox2.Text)
        Else
           ListBox1.Items.Insert(TextBox3.Text - 1, TextBox2.Text)
        End If
     Else




                                                            -3-
VB .NET 2005 By Warawut Khangkhan


       MessageBox.Show("ระบรายการททาไมถกตอง", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
       TextBox3.Focus()
    End If
    lblAmountList.Text = ListBox1.Items.Count
  End Sub

  Private Sub TextBox3_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.Enter
     TextBox3.SelectionStart = 0
     TextBox3.SelectionLength = TextBox3.Text.Length
  End Sub

  Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter
     TextBox2.SelectionStart = 0
     TextBox2.SelectionLength = TextBox2.Text.Length
  End Sub

  Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles
TextBox3.KeyPress
     If e.KeyChar < "0" Or e.KeyChar > "9" Then
       e.Handled = True
     End If
  End Sub

  Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
     If ListBox1.SelectedIndex < 0 Then Exit Sub
     ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)
     lblAmountList.Text = ListBox1.Items.Count
  End Sub

  Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
     Dim i As Integer

    If NumericUpDown1.Value > NumericUpDown2.Value Then
       MessageBox.Show("Start ตองนอยกวา Stop", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information)
       NumericUpDown1.Focus()
       Exit Sub
    End If
    ListBox1.Items.Clear()
    lblAmountList.Text = "0"
    lblAmountComboBox.Text = "0"
    lblIndexListBox.Text = "0"
    lblIndexComboBox.Text = "0"

    For i = NumericUpDown1.Value To NumericUpDown2.Value Step NumericUpDown3.Value
      ListBox1.Items.Add("Number " & i)
    Next

    lblAmountList.Text = ListBox1.Items.Count
  End Sub




                                                            -4-
VB .NET 2005 By Warawut Khangkhan


  Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
     If ListBox1.SelectedIndex < 0 Then Exit Sub
     ListBox1.Items.Remove(ListBox1.SelectedItem)
     lblAmountList.Text = ListBox1.Items.Count
  End Sub
End Class




                                                            -5-

More Related Content

What's hot

What's hot (16)

Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)Refactoring to Java 8 (Devoxx BE)
Refactoring to Java 8 (Devoxx BE)
 
C++ Windows Forms L07 - Collections
C++ Windows Forms L07 - CollectionsC++ Windows Forms L07 - Collections
C++ Windows Forms L07 - Collections
 
Python functions
Python functionsPython functions
Python functions
 
Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)Pragmatic Real-World Scala (short version)
Pragmatic Real-World Scala (short version)
 
Java File
Java FileJava File
Java File
 
Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.Chat application in java using swing and socket programming.
Chat application in java using swing and socket programming.
 
The Ring programming language version 1.7 book - Part 29 of 196
The Ring programming language version 1.7 book - Part 29 of 196The Ring programming language version 1.7 book - Part 29 of 196
The Ring programming language version 1.7 book - Part 29 of 196
 
Creating Lazy stream in CSharp
Creating Lazy stream in CSharpCreating Lazy stream in CSharp
Creating Lazy stream in CSharp
 
Functions in python
Functions in pythonFunctions in python
Functions in python
 
The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180The Ring programming language version 1.5.1 book - Part 24 of 180
The Ring programming language version 1.5.1 book - Part 24 of 180
 
Advance Java Programs skeleton
Advance Java Programs skeletonAdvance Java Programs skeleton
Advance Java Programs skeleton
 
Introduction to Python - Part Two
Introduction to Python - Part TwoIntroduction to Python - Part Two
Introduction to Python - Part Two
 
Java programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswarJava programming lab_manual_by_rohit_jaiswar
Java programming lab_manual_by_rohit_jaiswar
 
Java misc1
Java misc1Java misc1
Java misc1
 
Ejb3 Dan Hinojosa
Ejb3 Dan HinojosaEjb3 Dan Hinojosa
Ejb3 Dan Hinojosa
 
Java Lab Manual
Java Lab ManualJava Lab Manual
Java Lab Manual
 

Similar to การใช้ ListBox และ ComboBox Control

Vb6 ch.7-3 cci
Vb6 ch.7-3 cciVb6 ch.7-3 cci
Vb6 ch.7-3 cci
Fahim Khan
 
Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012
yantoit2011
 
Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012
yantoit2011
 
Inventory management
Inventory managementInventory management
Inventory management
Rajeev Sharan
 
Lampiran source code
Lampiran source codeLampiran source code
Lampiran source code
ancunk
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
dhi her
 
Introtodotnet
IntrotodotnetIntrotodotnet
Introtodotnet
rashmix
 
IntroToDotNetTech
IntroToDotNetTechIntroToDotNetTech
IntroToDotNetTech
rashmix
 

Similar to การใช้ ListBox และ ComboBox Control (20)

Vb6 ch.7-3 cci
Vb6 ch.7-3 cciVb6 ch.7-3 cci
Vb6 ch.7-3 cci
 
Richtextbox
RichtextboxRichtextbox
Richtextbox
 
Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012Ebook Pembuatan Aplikasi tiket kapal 2012
Ebook Pembuatan Aplikasi tiket kapal 2012
 
The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88The Ring programming language version 1.3 book - Part 13 of 88
The Ring programming language version 1.3 book - Part 13 of 88
 
Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012Ebook Pembuatan Aplikasi Rental film 2012
Ebook Pembuatan Aplikasi Rental film 2012
 
Binary Search Program in Visual Basic 2008
Binary Search Program in Visual Basic 2008Binary Search Program in Visual Basic 2008
Binary Search Program in Visual Basic 2008
 
Vizwik Coding Manual
Vizwik Coding ManualVizwik Coding Manual
Vizwik Coding Manual
 
Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3Visual Web Developer and Web Controls VB set 3
Visual Web Developer and Web Controls VB set 3
 
Inventory management
Inventory managementInventory management
Inventory management
 
Colegio municipal
Colegio municipalColegio municipal
Colegio municipal
 
Basic controls in asp
Basic controls in aspBasic controls in asp
Basic controls in asp
 
Delphi L02 Controls P1
Delphi L02 Controls P1Delphi L02 Controls P1
Delphi L02 Controls P1
 
.net progrmming part4
.net progrmming part4.net progrmming part4
.net progrmming part4
 
The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84The Ring programming language version 1.2 book - Part 11 of 84
The Ring programming language version 1.2 book - Part 11 of 84
 
Lampiran source code
Lampiran source codeLampiran source code
Lampiran source code
 
Practicalfileofvb workshop
Practicalfileofvb workshopPracticalfileofvb workshop
Practicalfileofvb workshop
 
Ficha tecnica
Ficha tecnicaFicha tecnica
Ficha tecnica
 
Visual basic
Visual basicVisual basic
Visual basic
 
Introtodotnet
IntrotodotnetIntrotodotnet
Introtodotnet
 
IntroToDotNetTech
IntroToDotNetTechIntroToDotNetTech
IntroToDotNetTech
 

More from Warawut

Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
Warawut
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
Warawut
 

More from Warawut (20)

Database design
Database designDatabase design
Database design
 
Business Computer Project 4
Business Computer Project 4Business Computer Project 4
Business Computer Project 4
 
Object-Oriented Programming 10
Object-Oriented Programming 10Object-Oriented Programming 10
Object-Oriented Programming 10
 
Object-Oriented Programming 9
Object-Oriented Programming 9Object-Oriented Programming 9
Object-Oriented Programming 9
 
Object-Oriented Programming 8
Object-Oriented Programming 8Object-Oriented Programming 8
Object-Oriented Programming 8
 
Object-Oriented Programming 7
Object-Oriented Programming 7Object-Oriented Programming 7
Object-Oriented Programming 7
 
Object-Oriented Programming 6
Object-Oriented Programming 6Object-Oriented Programming 6
Object-Oriented Programming 6
 
Management Information System 6
Management Information System 6Management Information System 6
Management Information System 6
 
Management Information System 5
Management Information System 5Management Information System 5
Management Information System 5
 
Management Information System 4
Management Information System 4Management Information System 4
Management Information System 4
 
Object-Oriented Programming 5
Object-Oriented Programming 5Object-Oriented Programming 5
Object-Oriented Programming 5
 
Business Computer Project 3
Business Computer Project 3Business Computer Project 3
Business Computer Project 3
 
Management Information System 3
Management Information System 3Management Information System 3
Management Information System 3
 
Business Computer Project 2
Business Computer Project 2Business Computer Project 2
Business Computer Project 2
 
Chapter 2 Strategy & Information System
Chapter 2 Strategy & Information SystemChapter 2 Strategy & Information System
Chapter 2 Strategy & Information System
 
Object-Oriented Programming 4
Object-Oriented Programming 4Object-Oriented Programming 4
Object-Oriented Programming 4
 
Business Computer Project 1
Business Computer Project 1Business Computer Project 1
Business Computer Project 1
 
Chapter 1 Organization & MIS
Chapter 1 Organization & MISChapter 1 Organization & MIS
Chapter 1 Organization & MIS
 
Object-Oriented Programming 3
Object-Oriented Programming 3Object-Oriented Programming 3
Object-Oriented Programming 3
 
Object-Oriented Programming 2
Object-Oriented Programming 2Object-Oriented Programming 2
Object-Oriented Programming 2
 

Recently uploaded

Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
Chris Hunter
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Recently uploaded (20)

Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Making and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdfMaking and Justifying Mathematical Decisions.pdf
Making and Justifying Mathematical Decisions.pdf
 
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural ResourcesEnergy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
Energy Resources. ( B. Pharmacy, 1st Year, Sem-II) Natural Resources
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 

การใช้ ListBox และ ComboBox Control

  • 1. VB .NET 2005 By Warawut Khangkhan ตวอยาง การใช ListBox และ ComboBox Control ตวอยาง การใช ListBox และ ComboBox Control 1 3 4 5 6 7 8 2 Label Control Name: lblAmountList 9 Label Control Name: lblAmountComboBox 11 12 Label Control 10 Name: lblIndexComboBox Label Control Name: lblIndexListBox 13 14 15 ตาราง การก,าหนด Properties ท45สาค8ญแต:ละ Control , No. Control Properties Values 1 Form Name Form1 StartPosition CenterScreen Text Example Using ListBox and ComboBox Control 2 TextBox Name TextBox1 3 Button Name Button1 Text Add Text 4 Button Name Button2 Text Clear Text 5 Button Name Button5 Text Run Number -1-
  • 2. VB .NET 2005 By Warawut Khangkhan ตาราง การก,าหนด Properties ท45สาค8ญแต:ละ Control (ต:อ) , No. Control Properties Values 6 NumericUpDown Name NumericUpDown1 Maximum 10 Minimum 1 7 NumericUpDown Name NumericUpDown2 Maximum 10 Minimum 1 8 NumericUpDown Name NumericUpDown3 Maximum 10 Minimum 1 9 ComboBox Name ComboBox1 DropDownStyle DropDownList 10 ListBox Name ListBox1 11 Button Name Button4 Text RemoveAt 12 Button Name Button6 Text Remove 13 TextBox Name TextBox2 14 TextBox Name TextBox3 15 Button Name Button3 Text Insert Text -2-
  • 3. VB .NET 2005 By Warawut Khangkhan Coding: Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ComboBox1.Items.Add(TextBox1.Text.Trim) ListBox1.Items.Add(TextBox1.Text.Trim) lblAmountList.Text = ListBox1.Items.Count lblAmountComboBox.Text = ComboBox1.Items.Count TextBox1.Focus() End Sub Private Sub TextBox1_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.Enter TextBox1.SelectionStart = 0 TextBox1.SelectionLength = TextBox1.Text.Length End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click ComboBox1.Items.Clear() ListBox1.Items.Clear() lblAmountList.Text = "0" lblAmountComboBox.Text = "0" lblIndexComboBox.Text = "0" lblIndexListBox.Text = "0" TextBox1.Focus() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load lblAmountList.Text = "0" lblAmountComboBox.Text = "0" lblIndexListBox.Text = "0" lblIndexComboBox.Text = "0" End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged lblIndexListBox.Text = ListBox1.SelectedIndex + 1 End Sub Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged lblIndexComboBox.Text = ComboBox1.SelectedIndex + 1 End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click If Convert.ToInt32(TextBox3.Text) >= 0 And Convert.ToInt32(TextBox3.Text) <= ListBox1.Items.Count Then If Convert.ToInt32(TextBox3.Text) = 0 Then ListBox1.Items.Insert(TextBox3.Text, TextBox2.Text) Else ListBox1.Items.Insert(TextBox3.Text - 1, TextBox2.Text) End If Else -3-
  • 4. VB .NET 2005 By Warawut Khangkhan MessageBox.Show("ระบรายการททาไมถกตอง", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) TextBox3.Focus() End If lblAmountList.Text = ListBox1.Items.Count End Sub Private Sub TextBox3_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.Enter TextBox3.SelectionStart = 0 TextBox3.SelectionLength = TextBox3.Text.Length End Sub Private Sub TextBox2_Enter(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox2.Enter TextBox2.SelectionStart = 0 TextBox2.SelectionLength = TextBox2.Text.Length End Sub Private Sub TextBox3_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox3.KeyPress If e.KeyChar < "0" Or e.KeyChar > "9" Then e.Handled = True End If End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click If ListBox1.SelectedIndex < 0 Then Exit Sub ListBox1.Items.RemoveAt(ListBox1.SelectedIndex) lblAmountList.Text = ListBox1.Items.Count End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click Dim i As Integer If NumericUpDown1.Value > NumericUpDown2.Value Then MessageBox.Show("Start ตองนอยกวา Stop", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information) NumericUpDown1.Focus() Exit Sub End If ListBox1.Items.Clear() lblAmountList.Text = "0" lblAmountComboBox.Text = "0" lblIndexListBox.Text = "0" lblIndexComboBox.Text = "0" For i = NumericUpDown1.Value To NumericUpDown2.Value Step NumericUpDown3.Value ListBox1.Items.Add("Number " & i) Next lblAmountList.Text = ListBox1.Items.Count End Sub -4-
  • 5. VB .NET 2005 By Warawut Khangkhan Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click If ListBox1.SelectedIndex < 0 Then Exit Sub ListBox1.Items.Remove(ListBox1.SelectedItem) lblAmountList.Text = ListBox1.Items.Count End Sub End Class -5-