Skip to main content

How to Make Button Dynamic With VB.NET

នៅក្នុងកម្មវិធីមួយចំនួនតំរូវឱ្យអ្នកធ្វើការបង្កើត Button តាមតម្រូវការរបស់អ្នកប្រើប្រាស់ ឧទាហរណ៍នៅក្នុង​ ប្រពន្ធ័គ្រប់គ្រងការកម្មង់អាហារនៅក្នុង​ភោជនិយ ដ្ឋាន​(Food Order Management System) អ្នកប្រើប្រាស់អាច ធ្វើការបន្ថែមតុ (តំណាងដោយ Button) តាមតម្រូវការ។
ខាងក្រោមនេះនាងខ្ញុំនឹងបង្ហាញអ្នកអំពីរបៀបបង្កើត Button Dynamic ដែលទាញចេញពី​Database ជាមួយ VB.NET។

 


ជាដំបូងសូមធ្វើការ Design Form ដូចខាងក្រោម 

1.       TextBox: txtBtnName
2.       Button: btnAdd
3.       FlowLayoutPanel: FlowLayoutPanelButton
ចំណាំ៖ ចំពោះ Panel ដែលប្រើសម្រាប់ផ្ទុក Button អ្នកគួរជ្រើសយក FlowLayoutPanel ព្រោះវាជួយរៀបចំឱ្យ Button មានលក្ខណៈជាជួរ ដោយមិនចាំបាច់ឱ្យយើងធ្វើការ​ Set Location ទៅលើButtonដោយខ្លួនឯងទេ។
បន្ទាប់មកអ្នកត្រូវមាន​Database សម្រាប់ផ្ទុកនូវ អក្សរសម្រាប់បង្ហាញនៅក្នុង​ Button និមួយៗ ជាមុនសិន​។ ហើយនៅពេលដែលអ្នកបើ  Form លើកក្រោយចំនួន Button ។
 

ការសរសេរកូដ

- កូដសម្រាប់ Save ឈ្មោះ Button 
1Sub InsertButton(ByVal btnName As String)
2        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BTN.accdb")
3        Dim comm As New OleDbCommand("Insert into Buttons Values ('" + btnName + "')", con)
4        con.Open()
5        comm.ExecuteNonQuery()
6        con.Close()
7End Sub
- កូដសម្រាប់​បង្កើត​Button ដែលត្រូវបានទាញចេញពី Database
1Sub CallButton()
2        Dim con As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=BTN.accdb")
3        Dim comm As New OleDbCommand("SELECT * FROM Buttons", con)
4        con.Open()
5        Dim dr As OleDbDataReader = comm.ExecuteReader
6        While dr.Read
7            Dim btn As New Button
8            btn.Text = dr(0).ToString
9            FlowLayoutPanelButton.Controls.Add(btn)
10
11        End While
12        con.Close()
13End Sub
**ដើម្បីឱ្យបើក Form មកចេញ​Button ដែលមានឈ្មោះនៅក្នុង​Database សូមហៅ Function CallButton ខាងលើនៅក្នុង​Event Form_Load ដូចខាងក្រោម​​៖
1Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
2        Call CallButton()
3    End Sub
** សូមហៅ​Function InserButton() នៅក្នុង​Event click របស់ btnBtnName ដូចខាក្រោម៖
1Private Sub btnBtnName_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
2        FlowLayoutPanelButton.Controls.Clear()
3        Call InsertButton(txtBtnName.Text)
4        Call CallButton()
5End Sub

Comments

Popular posts from this blog

Windows 7 Boot Updater

ជាទូទៅអ្នកតែងតែឃើញនូវរូប Logo របស់ Windows 7 រៀងរាល់ពេលដែល អ្នកបើកដំនើរការ កុំព្យូទ័រ ដែលគេហៅថា BootScreen។ ដូច្នេះនៅក្នុងអត្ថបទនេះ អាយធីកូនខ្មែរ នឹងបង្ហាញពីរ របៀបផ្លាស់ប្តូរ BootScreen របស់ Windows 7។ ជំហានទី ១៖ អ្នកត្រូវធ្វើការទាញយកកម្មវិធី Windows 7 Boot Updater  ចុចត្រង់នេះ ជំហានទី ២៖ បើកដំនើរការកម្មវិធីបន្ទាប់មកនៅក្នុងប្រអប់ Animation ជ្រើសរើសយកជំរើស Animation

Orkida English-Khmer Dictionary

ថ្ងៃ​នេះ​សុំ លើក​យក​វត្ថុ​បូរាណ​ ប៉ុន្តែ​ពេញ​និយម ដែល​ត្រូវ​បាន​ដំឡើង​ស្ទើគ្រប់​កុំព្យូទ័រ​បង​ប្អូន​ខ្មែរ​យើងគឺ វចនានុក្រម Orkida English<->Khmer ។ សង្ឃឹម​ថា​ម្ចាស់​បង្កើតវចនា​នុក្រម​នេះ មិន​យល់​ទាស់​អី​ទេ ដែល​ខ្ញុំ​ដាក់​អោយ​គេ​ទាញ​យក​ជាសាធារណះ​ដូច្នេះ ព្រោះ​ថា​វា​កម្មវិធី​ដែល​បង្កើត​ឡើង​តាំង​ពីឆ្នាំ ១៩៩៨មក​ម្ល៉េះ ម្យ៉ាង​វិញ​ទៀតបង​ប្អូន​យើង​បាន​ចម្លង​ពីមួយ​ទៅ​មួយស្ទើរ​គ្រប់​កុំព្យូទ័រ​ ទៅ​ហើយ។ ដោយ​ឡែក​ពេល​ខ្ញុំ​សាកល្បង​ស្វែង​រក​ក្នុង Google អំពី​វចនា​នុក្រម​នេះ ហាក់​ដូច​ជា​ស្ងាត់​ឈឹង​ មិនសូវ​មាន​កន្លែង​ Download សោះ ! ដូច្នេះ​ដើម្បី​អោយ​ការ​ស្វែង​រកក្នុង​អ៊ិនធឺណិត​ទាក់​ទង​នឹង​ស្រុក​ខ្មែរ​ យើងកាន់​តែមាន​​ប្រសិទ្ធភាព ខ្ញុំ​សម្រេច​ចិត្ត​ Upload វា​ចូល​ក្នុង Hosting របស់​ខ្ញុំ​ ហើយ​ចែក​អោយ​បងប្អូន​ដែល​ត្រូវ​ការ​វា​ យក​ទៅ​ប្រើ​ប្រាស់​ចុះ។ ថ្វីត្បិត​តែ​វា​រាង​ចំណាស់​បន្តិច​មែន តែ​រហូត​មក​ដល់​ Windows 7 ហើយ​ វា​នៅ​តែ​អាច​ដំឡើង​និង​ប្រើ​បាន​ជា​ធម្មតា។ ទាញ​យកវចនានុក្រម​ Orkida By : Sam Vichea

Mongkol Borey, i was born in here ..:'(

Mongkol Borei District (Khmer: ស្រុកមង្គលបុរី) is a district (srok) in the south of Banteay Meanchey Province, in north-western Cambodia. The district capital is Mongkol Borei town located around 8 kilometres south of the provincial capital of Sisophon by road. Mongkol Borei District is the southern-most district of Banteay Meanchey. The district shares a border with Battambang Province to the south. The main railway line from Phnom Penh to Poipet on the border with Thailand runs through the district from north to south.[2] The district is easily accessed by road from Sisophon (8 km) Battambang (city) (60 km) and Siem Reap (city) (110 km). Mongkol Borei District is one of the smallest districts in Banteay Meanchey province by land area and only Serei Saophoan District is smaller. However, it has the largest district population in the province due to its central location and transport infrastructure. National Highway 5 which begins in Phnom Penh and ends at Poipet and the National rai...