我一直在使用一个pos系统 VB.NET
需要一些帮助来解决我面临的问题。
基本上,我使用一个函数 SQL
表中查找与表格中某个类别对应的项目相关的信息 Button
.
基本上,所有类别都自动创建到 Form
使用 SQL
table。
我想找到一种方法,使用它我将能够以 Buttons
分配给数据库中已在代码中完成的每个类别。
唯一的问题是,按钮形式的旧项目不会被删除,并将留在屏幕上,造成一个问题,我无法看到由类别调用的新项目 Button
.
下面是代码示例:
Public Sub Form13_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim point As Integer
Dim point1 As Integer
point = 20
point1 = 100
Label2.Text = Form12.selected_value
Dim connection As New MySqlConnection
connection.ConnectionString = ("host=localhost;user=root;password=;database=pos;")
connection.Open()
Dim command As New MySqlCommand("select * from categories", connection)
Dim reader As MySqlDataReader
reader = command.ExecuteReader
Dim perm As String
While reader.Read()
Dim button As New Button
Dim value As String = reader.GetString("category_name")
perm = reader.GetString("category_name")
button.Name = value
button.Text = value
button.Height = 50
button.Width = 190
button.Font = New Font("arial", 11)
button.Location = New Point(point, point1)
Me.Controls.Add(button)
point1 = point1 + 50
'showing items based on the button that the user clicks
AddHandler button.Click,
Sub()
reader.Close()
Dim command1 As New MySqlCommand("select * from items where category=@name", connection)
command1.Parameters.AddWithValue("@name", value)
reader = command1.ExecuteReader
'new look for the items to be converted into physical buttons
Dim point2 As Integer
Dim point3 As Integer
point2 = 235
point3 = 100
Dim counter As Integer
counter = 1
While reader.Read()
Dim item As String
Dim category_type As String
category_type = reader.GetString("category")
item = reader.GetString("name")
Dim button1 As New Button
button1.Name = item
button1.Text = item
button1.Height = 50
button1.Width = 160
button1.Font = New Font("Arial", 11)
button1.Location = New Point(point2, point3)
Me.Controls.Add(button1)
counter = counter + 1
Me.Refresh()
'figure out how to remove buttons when they are not neeeded aka find a way to check when a button is being clicked
If point2 > 700 Then
point2 = 235
point3 = point3 + 55
Else
point2 = point2 + 168
End If
End While
End Sub
End While
End Sub
请帮帮我,因为我已经被这个问题困扰了很长时间了。
我假设可以通过找出用户何时单击不同的类别来解决这个问题,这样就可以使用 button1.Dispose
.
包含这些项目的表格的图像已附在下面:
暂无答案!
目前还没有任何答案,快来回答吧!