首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

怎样得到自动那个生成控件上的值?该怎么解决

2012-01-16 
怎样得到自动那个生成控件上的值???生成button的事件:Dim Ctl(350) As ButtonCtl(intCtl) New ButtonWit

怎样得到自动那个生成控件上的值???
生成button的事件:
  Dim Ctl(350) As Button
  Ctl(intCtl) = New Button
  With Ctl(intCtl)
  .Name = TabNo  
  .Text = TabNo + "|" + Mens.ToString.Trim() '''''传过来的值 .Font = New Font("Tahoma", 14, FontStyle.Bold)
  .Location = New Point(x_Lines, y_Lines)
  .Size = New Size(52, 46)
  .Scale(addSize)
  End With
  Me.Pane_TableNo.Controls.Add(Ctl(intCtl))
  AddHandler Ctl(intCtl).Click, AddressOf ButtNew_table
我要生成的button有很多,生成之后,button的text上的值是对应自动传过来的
 ----点击界面上自动生成的Botton按钮,就会触发下列事件(在生成button的时候,button上的text就会得到对应的值)
  现在我想在点击自动生成的button的时候,,就得到button上的值
Private Sub ButtNew_Table(ByVal sender As System.Object, ByVal e As System.EventArgs)
  ----这怎么写????????
End Sub




[解决办法]
利用sender,例如sender.text

[解决办法]

VB.NET code
Private Sub ButtNew_Table(ByVal sender As System.Object, ByVal e As System.EventArgs)   MessageBox.Show(DirectCast(sender, Button).Text)End Sub
[解决办法]
dim btn(350) as button
for i as integer=0 to 349
btn(i)=new button
with btn(i)
.Name = TabNo
.Text = TabNo + " ¦" + Mens.ToString.Trim() '''''传过来的值 .Font = New Font("Tahoma", 14, FontStyle.Bold) 
.Location = New Point(x_Lines, y_Lines) 
.Size = New Size(52, 46) 
End With 

Me.Pane_TableNo.Controls.Add(btn(i)) 
AddHandler btn(i).Click, AddressOf btn_Click
next

Private Sub ButtNew_Table(ByVal sender As System.Object, ByVal e As System.EventArgs) 
'----这怎么写???????? 
msgbox(ctype(sender,button).text)
End Sub
[解决办法]
如大家所说,使用sender.Text
看我的代码
VB.NET code
    '动态添加控件**************************************    Private Sub DesignPicBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DesignPicBox.Click        sender.Focus()        Console.WriteLine("设计窗体有子控件: " & DesignPicBox.Controls.Count)        If isAdditem Then            Dim lblItem As New System.Windows.Forms.Label            With lblItem                .BorderStyle = Windows.Forms.BorderStyle.FixedSingle                .BackColor = Color.Transparent                .Cursor = Cursors.Hand                .Top = eX - 20 : lblItem.Left = eY - 20                .Text = eX & ":" & eY                .BringToFront()                AddHandler .Click, AddressOf lblItem_Click ''绑定事件处理程序                AddHandler .KeyDown, AddressOf lblItem_KeyDown                AddHandler .LostFocus, AddressOf lblItem_LostFocus            End With            sender.Controls.Add(lblItem)                  ''向窗体中增加控件            isAdditem = False        End If    End Sub    Public Sub lblItem_Click(ByVal sender As Object, ByVal e As System.EventArgs)        ''在这里编写控件数组对点击事件的响应        MsgBox(sender.Text)        sender.BorderStyle = Windows.Forms.BorderStyle.FixedSingle        sender.focus()    End Sub    Public Sub lblItem_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)        Console.WriteLine(e.KeyCode)        If e.KeyCode = Keys.Delete Then            Me.DesignPicBox.Controls.Remove(sender)        End If    End Sub 

热点排行