我正在为我的工作制作一个聊天系统,但我很难找到一种方式来显示用户及其状态.
I'm making a chat system for my work and I'm having trouble to find a way to display users and their status.
所以我有一个叫做 Chat Client 的表单
So I have a Form called Chat Client
我有 Panel1(Left)
和 Panel2(Right)
在 Panel1
中,我必须让每个用户都列在我的数据库中
In Panel1
I have to get every user listed in my database
Select [first_name] + ' ' + [Name] As 'Contact', [Status] From dbo.TableUsers
这给出了以下内容:
[green image] [contact name] (if someone is logged in (status online))
[Orange image] [contact name] (If someone is logged in (status away))
[Red image] [contact name] (If someone is not logged in (Status offline))
如何创建一个下标,为我提供表中列出的所有用户,并在显示其状态的名称前附上一张图片?
How can I create a subscript that gives me all the users listed in the table with an image before the name showing their status?
我自己找到了答案 :)
I found the answer myself :)
我使用了带有 2 列的 e TableLayoutPanel,并用它填充了它:
i used e TableLayoutPanel with 2 columns and i filled it up with this:
While UserData.Read
If UserData("Status").ToString = "Online" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.greenchat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString & "Pic"
ChatContactList.Controls.Add(newPictureBox)
Dim newLabel As New Label
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString & "Lab"
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Height = 30
newLabel.AutoSize = True
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
ElseIf UserData("Status").ToString = "Afwezig" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.orangechat
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString & "Pic"
ChatContactList.Controls.Add(newPictureBox)
Dim newLabel As New Label
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString & "Lab"
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Height = 30
newLabel.AutoSize = True
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
ElseIf UserData("Status").ToString = "Offline" Then
Dim newPictureBox As New PictureBox
newPictureBox.Image = My.Resources.ResourceManager.GetObject("redchat")
newPictureBox.Visible = True
newPictureBox.Width = 30
newPictureBox.Height = 30
newPictureBox.SizeMode = PictureBoxSizeMode.Zoom
newPictureBox.Name = UserData("Username").ToString & "Pic"
ChatContactList.Controls.Add(newPictureBox)
Dim newLabel As New Label
newLabel.Text = UserData("Voornaam").ToString & " " & UserData("Achternaam").ToString
newLabel.Name = UserData("Username").ToString & "Lab"
newLabel.Font = New Font("Microsoft sans serif", 12)
newLabel.Height = 30
newLabel.AutoSize = True
newLabel.TextAlign = ContentAlignment.MiddleLeft
newLabel.Visible = True
ChatContactList.Controls.Add(newLabel)
End If
End While
这篇关于聊天联系人列表 VB.NET 和 MSSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!