以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  全局代码简化  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=66927)

--  作者:联友
--  发布时间:2015/4/16 8:30:00
--  全局代码简化

这些代码怎么简化。请指点,谢谢!

Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Functions.Execute("btnAdd1",sender.Name)
End Sub

Public Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Functions.Execute("btnAdd2",sender.Name)
End Sub

Public Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Functions.Execute("btnAdd3",sender.Name)
End Sub

Public Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Functions.Execute("btnAdd4",sender.Name)
End Sub

Public Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Functions.Execute("btnAdd5",sender.Name)
End Sub


--  作者:Bin
--  发布时间:2015/4/16 8:36:00
--  
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
    Functions.Execute("btnAdd1",sender.Name)
End Sub

全局代码应该就写这么一段

然后你内部函数,根据Sender.Name 执行对应的操作

例如 select case args(0)
   case "button1"
 end select

--  作者:联友
--  发布时间:2015/4/16 10:03:00
--  

这样吗?

Select Case args(0)
   Case "btnAdd1"
      Forms("窗口1").Open()
   Case "btnAdd2"
      Forms("窗口").Open()
   Case "btnAdd3"
      Forms("窗口4").Open()
 End Select


--  作者:Bin
--  发布时间:2015/4/16 10:03:00
--  
是的
--  作者:联友
--  发布时间:2015/4/16 10:07:00
--  
谢谢!
--  作者:联友
--  发布时间:2015/4/16 10:15:00
--  

还想请教,这能简化吗?

Dim btnAdd1 As New C1Input.C1Button
With btnAdd1
    .Name = "btnAdd1"
    .Text = "窗口1"
    .TabIndex = 0
    .Font = New Font("微软雅黑",10)
    .Location = New System.Drawing.Point(20, 28)
    .Size = New System.Drawing.Size(68, 70)
    .VisualStyle = C1Input.VisualStyle.Office2010Blue
    .VisualStyleBaseStyle = C1Input.VisualStyle.Office2010Blue
    .TextAlign  = ContentAlignment.BottomCenter
    .Image = GetImage("Accept.png")
    .TextAlign  = ContentAlignment.BottomCenter
    .ImageAlign = ContentAlignment.TopCenter
End With
AddHandler btnAdd1.Click, AddressOf Button_Click
Forms("导航").Panel.Controls.Add(btnAdd1)

Dim btnAdd2 As New C1Input.C1Button
With btnAdd2
    .Name = "btnAdd2"
    .Text = "窗口2"
    .TabIndex = 0
    .Font = New Font("微软雅黑",10)
    .Location = New System.Drawing.Point(100, 28)
    .Size = New System.Drawing.Size(68, 70)
    .VisualStyle = C1Input.VisualStyle.Office2010Blue
    .VisualStyleBaseStyle = C1Input.VisualStyle.Office2010Blue
    .TextAlign  = ContentAlignment.BottomCenter
    .Image = GetImage("Accept.png")
    .TextAlign  = ContentAlignment.BottomCenter
    .ImageAlign = ContentAlignment.TopCenter
End With
AddHandler btnAdd2.Click, AddressOf Button_Click
Forms("导航").Panel.Controls.Add(btnAdd2)


--  作者:jspta
--  发布时间:2015/4/16 10:25:00
--  
封装成函数,返回btnAdd1

Dim btnAdd1 As New C1Input.C1Button
With btnAdd1
    .Name = Args(0)
    .Text = Args(1)
    .TabIndex = 0
    .Font = New Font("微软雅黑",10)
    .Location = New System.Drawing.Point(20, 28)
    .Size = New System.Drawing.Size(68, 70)
    .VisualStyle = C1Input.VisualStyle.Office2010Blue
    .VisualStyleBaseStyle = C1Input.VisualStyle.Office2010Blue
    .TextAlign  = ContentAlignment.BottomCenter
    .Image = GetImage("Accept.png")
    .TextAlign  = ContentAlignment.BottomCenter
    .ImageAlign = ContentAlignment.TopCenter 
End With
AddHandler btnAdd1.Click, AddressOf Button_Click
return btnAdd1


--  作者:联友
--  发布时间:2015/4/16 14:17:00
--  
谢谢
--  作者:Bin
--  发布时间:2015/4/16 16:35:00
--  
帮助没有的,底层控件的名称.