聊天联系人列表VB.NET和MSSQL

时间:2016-03-01 11:59:41

标签: sql-server vb.net

我正在为我的工作制作聊天系统,而我却无法找到显示用户及其状态的方法。

所以我有一个名为Chat Client的表单

我有Panel1(Left)Panel2(Right)

Panel1我必须让我的数据库中列出每个用户

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))

如何在显示其状态的名称之前创建一个下标,该下标为表格中列出的所有用户提供图像?

2 个答案:

答案 0 :(得分:0)

我自己找到了答案:)

我使用了带有2列的e TableLayoutPanel,并用它填充了它:

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

答案 1 :(得分:-1)

我见过你的决心,我理解错了。无论如何,你很好地解决了这个任务。