vb.net列表框移除 vb中怎么移除list所有项

VB.NET中要删除列表框中的多个选项,请问代码如何编写。我下面的代码错在哪里请指导,谢谢

For i = List1.ListCount - 1 To 0 Step -1

专注于为中小企业提供成都网站设计、网站建设服务,电脑端+手机端+微信端的三站合一,更高效的管理,为中小企业揭东免费做网站提供优质的服务。我们立足成都,凝聚了一批互联网行业人才,有力地推动了上千余家企业的稳健成长,帮助中小企业通过网站建设实现规模扩充和转变。

If List1.Selected(i) Then

List1.RemoveItem (i)

End If

Next i

VB.NET列表框问题

有这个条件是为了避免 当列表没有选项的时候 或者 有选项但没有选中的时候 点击删除按钮会引发错误 selectindex =-1 是没有选中的时候默认值 而列表序号从0开始 删除一个不存在的序号引发错误

vb.net编写一个为列表框添加删除选项的应用程序,如果该字符串在列表框中,

Private Sub TextBox1_KeyPress(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress

If e.KeyChar.ToString() = Chr(13) Then

Dim str As String = TextBox1.Text

If Not ListBox1.Items.Contains(str) Then

ListBox1.Items.Add(str)

End If

End If

End Sub

Private Sub btn_Remove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

If ListBox1.SelectedIndex 0 Then

ListBox1.Items.RemoveAt(ListBox1.SelectedIndex)

End If

End Sub

Private Sub btn_Clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

ListBox1.Items.Clear()

End Sub

VB.NET 如何去掉 GroupBox 控件的边框?

工程里面添加一个类,命名为myGroupBox,代码如下:

Imports System.ComponentModel

Imports System.Drawing.Drawing2D

Public Class myGroupBox

Inherits GroupBox

Public Sub New()

MyBase.BackColor = Color.Transparent

End Sub

Browsable(False) _

Public Overrides Property BackColor() As Color

Get

Return MyBase.BackColor

End Get

Set(value As Color)

MyBase.BackColor = value

End Set

End Property

Private m_backColor As Color = Color.Transparent

Public Property ActualBackColor() As Color

Get

Return Me.m_backColor

End Get

Set(value As Color)

Me.m_backColor = value

End Set

End Property

Protected Overrides Sub OnPaint(e As PaintEventArgs)

Dim tSize As Size = TextRenderer.MeasureText(Me.Text, Me.Font)

Dim borderRect As Rectangle = e.ClipRectangle

borderRect.Y += tSize.Height / 2

borderRect.Height -= tSize.Height / 2

Dim gPath As GraphicsPath = CreatePath(0, borderRect.Y, CSng(Me.Width - 1), borderRect.Height - 1, 5, True, _

True, True, True)

e.Graphics.FillPath(New SolidBrush(ActualBackColor), gPath)

e.Graphics.DrawPath(New Pen(Me.BackColor), gPath)

borderRect.X += 6

borderRect.Y -= 7

e.Graphics.DrawString(Me.Text, Me.Font, New SolidBrush(Me.ForeColor), borderRect)

End Sub

Public Function CreatePath(x As Single, y As Single, width As Single, height As Single, radius As Single, _

RoundTopLeft As Boolean, RoundTopRight As Boolean, RoundBottomRight As Boolean, RoundBottomLeft As Boolean) As GraphicsPath

Dim xw As Single = x + width

Dim yh As Single = y + height

Dim xwr As Single = xw - radius

Dim yhr As Single = yh - radius

Dim xr As Single = x + radius

Dim yr As Single = y + radius

Dim r2 As Single = radius * 2

Dim xwr2 As Single = xw - r2

Dim yhr2 As Single = yh - r2

Dim p As New GraphicsPath()

p.StartFigure()

'Top Left Corner

If RoundTopLeft Then

p.AddArc(x, y, r2, r2, 180, 90)

Else

p.AddLine(x, yr, x, y)

p.AddLine(x, y, xr, y)

End If

'Top Edge

p.AddLine(xr, y, xwr, y)

'Top Right Corner

If RoundTopRight Then

p.AddArc(xwr2, y, r2, r2, 270, 90)

Else

p.AddLine(xwr, y, xw, y)

p.AddLine(xw, y, xw, yr)

End If

'Right Edge

p.AddLine(xw, yr, xw, yhr)

'Bottom Right Corner

If RoundBottomRight Then

p.AddArc(xwr2, yhr2, r2, r2, 0, 90)

Else

p.AddLine(xw, yhr, xw, yh)

p.AddLine(xw, yh, xwr, yh)

End If

'Bottom Edge

p.AddLine(xwr, yh, xr, yh)

'Bottom Left Corner

If RoundBottomLeft Then

p.AddArc(x, yhr2, r2, r2, 90, 90)

Else

p.AddLine(xr, yh, x, yh)

p.AddLine(x, yh, x, yhr)

End If

'Left Edge

p.AddLine(x, yhr, x, yr)

p.CloseFigure()

Return p

End Function

End Class

工具栏会出现一个myGroupBox控件,放入窗体,你会发现边框没了。


网站名称:vb.net列表框移除 vb中怎么移除list所有项
标题来源:http://scyanting.com/article/dojjosc.html