使用VB.NET开发复合控件

使用VB.NET开发sql教程复合控件

java基础教程面:

控件python基础教程类型   名称               文本 

ListBox     lstSource

ListBox     lstTargeg

Button     btnAdd           Add >

Button     btnAddAll       Add All >>

Button     btnRemove    < Remove

Button     btnClear        << Clear

代码c#教程如下:

复制代码

  1 Public Class SelectCombo
  2   Inherits System.Windows.Forms.UserControl
  3 
  4   ' Make the width of the area for the buttons 100 twips
  5   Dim mnButtonAreaWidth As Integer = 100
  6 
  7   ' Set minimum height and width for the control
  8   Dim mnMinControlWidth As Integer = 200
  9   Dim mnMinControlHeight As Integer = 200
 10 
 11 
 12 #Region " Windows Form Designer generated code "
 13 
 14   Public Sub New()
 15     MyBase.New()
 16 
 17     'This call is required by the Windows Form Designer.
 18     InitializeComponent()
 19 
 20     'Add any initialization after the InitializeComponent() call
 21 
 22   End Sub
 23 
 24   'UserControl1 overrides dispose to clean up the component list.
 25   Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
 26     If disposing Then
 27       If Not (components Is Nothing) Then
 28         components.Dispose()
 29       End If
 30     End If
 31     MyBase.Dispose(disposing)
 32   End Sub
 33 
 34   'Required by the Windows Form Designer
 35   Private components As System.ComponentModel.IContainer
 36 
 37   'NOTE: The following procedure is required by the Windows Form Designer
 38   'It can be modified using the Windows Form Designer.  
 39   'Do not modify it using the code editor.
 40   Friend WithEvents lstSource As System.Windows.Forms.ListBox
 41   Friend WithEvents btnAdd As System.Windows.Forms.Button
 42   Friend WithEvents btnAddAll As System.Windows.Forms.Button
 43   Friend WithEvents lstTarget As System.Windows.Forms.ListBox
 44   Friend WithEvents btnRemove As System.Windows.Forms.Button
 45   Friend WithEvents btnClear As System.Windows.Forms.Button
 46   <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
 47         Me.lstSource = New System.Windows.Forms.ListBox()
 48         Me.btnAdd = New System.Windows.Forms.Button()
 49         Me.btnAddAll = New System.Windows.Forms.Button()
 50         Me.btnRemove = New System.Windows.Forms.Button()
 51         Me.btnClear = New System.Windows.Forms.Button()
 52         Me.lstTarget = New System.Windows.Forms.ListBox()
 53         Me.SuspendLayout()
 54         '
 55         'lstSource
 56         '
 57         Me.lstSource.Dock = System.Windows.Forms.DockStyle.Left
 58         Me.lstSource.ItemHeight = 12
 59         Me.lstSource.Location = New System.Drawing.Point(0, 0)
 60         Me.lstSource.Name = "lstSource"
 61         Me.lstSource.Size = New System.Drawing.Size(120, 136)
 62         Me.lstSource.TabIndex = 0
 63         '
 64         'btnAdd
 65         '
 66         Me.btnAdd.Location = New System.Drawing.Point(136, 8)
 67         Me.btnAdd.Name = "btnAdd"
 68         Me.btnAdd.Size = New System.Drawing.Size(80, 24)
 69         Me.btnAdd.TabIndex = 1
 70         Me.btnAdd.Text = "Add >"
 71         '
 72         'btnAddAll
 73         '
 74         Me.btnAddAll.Location = New System.Drawing.Point(136, 40)
 75         Me.btnAddAll.Name = "btnAddAll"
 76         Me.btnAddAll.Size = New System.Drawing.Size(80, 24)
 77         Me.btnAddAll.TabIndex = 2
 78         Me.btnAddAll.Text = "Add All >>"
 79         '
 80         'btnRemove
 81         '
 82         Me.btnRemove.Location = New System.Drawing.Point(136, 72)
 83         Me.btnRemove.Name = "btnRemove"
 84         Me.btnRemove.Size = New System.Drawing.Size(80, 24)
 85         Me.btnRemove.TabIndex = 3
 86         Me.btnRemove.Text = "< Remove"
 87         '
 88         'btnClear
 89         '
 90         Me.btnClear.Location = New System.Drawing.Point(136, 104)
 91         Me.btnClear.Name = "btnClear"
 92         Me.btnClear.Size = New System.Drawing.Size(80, 24)
 93         Me.btnClear.TabIndex = 4
 94         Me.btnClear.Text = "<< Clear"
 95         '
 96         'lstTarget
 97         '
 98         Me.lstTarget.Dock = System.Windows.Forms.DockStyle.Right
 99         Me.lstTarget.ItemHeight = 12
100         Me.lstTarget.Location = New System.Drawing.Point(232, 0)
101         Me.lstTarget.Name = "lstTarget"
102         Me.lstTarget.Size = New System.Drawing.Size(120, 136)
103         Me.lstTarget.TabIndex = 5
104         '
105         'SelectCombo
106         '
107         Me.Controls.Add(Me.lstTarget)
108         Me.Controls.Add(Me.btnClear)
109         Me.Controls.Add(Me.btnRemove)
110         Me.Controls.Add(Me.btnAddAll)
111         Me.Controls.Add(Me.btnAdd)
112         Me.Controls.Add(Me.lstSource)
113         Me.Name = "SelectCombo"
114         Me.Size = New System.Drawing.Size(352, 136)
115         Me.ResumeLayout(False)
116 
117     End Sub
118 
119 #End Region
120 
121   Private Sub SelectCombo_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize
122     ' Check for minimum width and height.
123     ' Throw exception if new width or height too small 
124     Dim sError As String
125     sError = "Attempted to make SelectCombo user control too small."
126 
127     If MyBase.Size.Width < mnMinControlWidth Then
128       Dim eComboException As New ApplicationException(sError)
129       eComboException.Source = Me.ToString
130     End If
131     If MyBase.Size.Height < mnMinControlHeight Then
132       Dim eComboException As New ApplicationException(sError)
133       eComboException.Source = Me.ToString
134     End If
135 
136     'Set source and target list boxes to appropriate width. Note that
137     'docking the list boxes makes their height the right size automatically.
138     Dim nListboxWidth As Integer
139     nListboxWidth = CInt(0.5 * (Me.Size.Width - mnButtonAreaWidth))
140     lstSource.Size = New Size(nListboxWidth, lstSource.Size.Height)
141     lstTarget.Size = New Size(nListboxWidth, lstSource.Size.Height)
142 
143     'Now position the buttons between the list boxes. 
144     Dim nLeftButtonPosition As Integer
145     nLeftButtonPosition = nListboxWidth + _
146            ((mnButtonAreaWidth - btnAdd.Size.Width) \ 2)
147     btnAdd.Location = New Point(nLeftButtonPosition, btnAdd.Location.Y)
148     btnAddAll.Location = New Point(nLeftButtonPosition, btnAddAll.Location.Y)
149     btnRemove.Location = New Point(nLeftButtonPosition, btnRemove.Location.Y)
150     btnClear.Location = New Point(nLeftButtonPosition, btnClear.Location.Y)
151   End Sub
152 
153   Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
154     Dim objItem As Object
155     For Each objItem In lstSource.SelectedItems
156       lstTarget.Items.Add(objItem)
157     Next objItem
158 
159   End Sub
160 
161   Private Sub btnAddAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAddAll.Click
162     Dim objItem As Object
163     For Each objItem In lstSource.Items
164       lstTarget.Items.Add(objItem)
165     Next objItem

166 
167   End Sub
168 
169   Private Sub btnRemove_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRemove.Click
170     lstTarget.Items.Clear()
171   End Sub
172 
173   Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
174     ' Have to go through the collection in reverse
175     ' because we are removing items.
176     Dim nIndex As Integer
177     For nIndex = lstTarget.SelectedItems.Count - 1 To 0 Step -1
178       lstTarget.Items.Remove(lstTarget.SelectedItems(nIndex))
179     Next nIndex
180 
181   End Sub
182 
183   Public ReadOnly Property SelectedItem(ByVal iIndex As Integer) As Object
184     Get
185       Return lstTarget.Items(iIndex)
186     End Get
187   End Property
188 
189   Public ReadOnly Property SelectedCount() As Integer
190     Get
191       Return lstTarget.Items.Count
192     End Get
193   End Property
194 
195   Public ReadOnly Property AvailableCount() As Integer
196     Get
197       Return lstSource.Items.Count
198     End Get
199   End Property
200 
201   Public Sub Add(ByVal objItem As Object)
202     lstSource.Items.Add(objItem)
203   End Sub
204 
205   Public ReadOnly Property AvailableItem(ByVal iIndex As Integer) As Object
206     Get
207       Return lstSource.Items(iIndex)
208     End Get
209   End Property
210 
211   Public Sub Clear()
212     lstSource.Items.Clear()
213     lstTarget.Items.Clear()
214 
215   End Sub
216 
217 End Class

复制代码

测试中,将控vb.net教程件拖入WINDOW窗体,在Form_Load事件中写入

SelectCombo1.Add("1")
SelectCombo1.Add("2")
SelectCombo1.Add("3")
SelectCombo1.Add("4")
SelectCombo1.Add("5")

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
vb.net操作DataGridView控件的用法的集合,包括: 1. DataGridView当前的单元格属性取得、变更 2. DataGridView编辑属性 3. DataGridView最下面一列新追加行非表示 4. DataGridView判断当前选中行是否为新追加的行 5. DataGridView删除行可否设定 6. DataGridView行列不表示和删除 DataGridView控件用法合集(二) 7. DataGridView行列宽度高度设置为不能编辑 8. DataGridView行高列幅自动调整 9. DataGridView指定行列冻结 10. DataGridView列顺序变更可否设定 11. DataGridView行复数选择 12. DataGridView选择的行、列、单元格取得 DataGridView控件用法合集(三) 13. DataGridView指定单元格是否表示 14. DataGridView表头部单元格取得 15. DataGridView表头部单元格文字列设定 16. DataGridView选择的部分拷贝至剪贴板 17.DataGridView粘贴 18. DataGridView单元格上ToolTip表示设定(鼠标移动到相应单元格上时,弹出说明信息) DataGridView控件用法合集(四) 19. DataGridView中的ContextMenuStrip属性 20. DataGridView指定滚动位置 21. DataGridView手动追加列 22. DataGridView全体分界线样式设置 23. DataGridView根据单元格属性更改显示内容 24. DataGridView新追加行的行高样式设置る 25. DataGridView新追加行单元格默认值设置 DataGridView中输入错误数据的处理(五) 26. DataGridView单元格数据错误标签表示 27. DataGridView单元格内输入值正确性判断 28. DataGridView单元格输入错误值事件的捕获 DataGridView控件用法合集(六) 29. DataGridView行排序(点击列表头自动排序的设置) 30. DataGridView自动行排序(新追加值也会自动排序) 31. DataGridView自动行排序禁止情况下的排序 32. DataGridView指定列指定排序 DataGridView控件用法合集(七) 33. DataGridView单元格样式设置 34. DataGridView文字表示位置的设定 35. DataGridView单元格内文字列换行 36. DataGridView单元格DBNull值表示的设定 37. DataGridView单元格样式格式化 38. DataGridView指定单元格颜色设定 39. DataGridView单元格文字字体设置 40. DataGridView根据单元格值设定单元格样式 DataGridView控件用法合集(八) 41. DataGridView设置单元格背景颜色 42. DataGridView行样式描画 43. DataGridView显示行号 44. DataGridView焦点所在单元格焦点不显示的设定 DataGridView控件用法合集(九) 45. DataGridView中显示选择CheckBox 46. DataGridView中显示下拉ComboBox 47. DataGridView单击打开下拉 48. DataGridView中显示按钮 49. DataGridView中显示链接 50. DataGridView中显示图像 DataGridView控件用法合集(十) 51. DataGridView编辑中单元格控件取得 52. DataGridView输入自动完成 53. DataGridView单元格编辑时键盘KEY事件取得 54. DataGridView下拉(ComboBox)单元格编辑时事件取得 55. DataGridView下拉(ComboBox)单元格允许文字输入设定 DataGridView控件用法合集(十一) 56. DataGridView根据值不同在另一列中显示相应图片 57. DataGridView中显示进度条(ProgressBar) 58. DataGridView中添加MaskedTextBox DataGridView控件用法合集(十二) 59. DataGridView中Enter键按下焦点移至旁边的单元格 60. DataGridView行集合化(Group)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值