动态按钮图像更改

动态按钮图像更改

本文介绍了动态按钮图像更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有一个按钮式的50件.
Imagen以子形式对它们进行的更改.我必须使用程序的某些部分.
但是,我不想一一更改.我想在下一个循环中进行for循环.
1.第50个按钮的按钮将变为.但是不知何故我无法从内部进行工作.如果您有帮助,我会很高兴.您真诚的


我写了不断变化的代码,但是文本还是前景色

但是如果我说没问题的话,直接选择button30.text ="test"


Hi,

I have a button formumda 50 pieces.
Imagen changes made to them in a sub form. I have to use certain parts of the program.
However, I do not want to change them one by one. I want to do a for loop in the next cycle.
1. Buttons from the 50th Images of the button will change to. But somehow I could not work from within. I''ll be glad if you help. Yours sincerely


I wrote the code that is changing, but what the text nor the forecolor

But directly button30.text = "test" if I say no problem


Dim mybutton As New Button


             For tt 1 to 50

                 mybutton.Name = "Button"&tt

                 With mybutton
                     .Text = "test"
                     .Name = "Button" & tt
                     .ForeColor = Color.Blue
                 End With
 next
             End If

推荐答案

For Each c As Control In Controls
    Dim b As Button = TryCast(c, Button)
    If b IsNot Nothing Then
       ....
    End If
Next




"抱歉,我听不懂


对于控件中的每个c As控件
Dim b As Button = TryCast(c,Button)
如果b不算什么

对于tt 1至50

mybutton.Name ="Button"& tt

使用mybutton
.Text =测试"
.ForeColor =颜色.蓝色
结尾为
下一个



如果结束
下一个


这样他会吗?




AddHandler Button1.Click,地址为secilenbuton
AddHandler Button2.Click,地址为secilenbuton
AddHandler Button3.Click,Secilenbuton的地址
AddHandler Button4.Click,地址为secilenbuton
.
.
.
.
.
AddHandler Button50.Click,地址为secilenbuton

演示文稿,我问,
如何将以下定义写为简短的




不,当您执行For Each循环时,每当您获得不为Nothing的"b"值时,它就已经是一个按钮.
您不再需要"For tt"循环.




"sorry i am not understand


For Each c As Control In Controls
Dim b As Button = TryCast(c, Button)
If b IsNot Nothing Then

For tt 1 to 50

mybutton.Name = "Button"&tt

With mybutton
.Text = "test"
.ForeColor = Color.Blue
End With
next



End If
Next


in this way will beDid he??

or


AddHandler Button1.Click, AddressOf secilenbuton
AddHandler Button2.Click, AddressOf secilenbuton
AddHandler Button3.Click, AddressOf secilenbuton
AddHandler Button4.Click, AddressOf secilenbuton
.
.
.
.
.
AddHandler Button50.Click, AddressOf secilenbuton

presentation, I ask,
How can I write the following definition as a short"




No, when you do the For Each loop, every time you get a value of "b" that is not Nothing, it it already a button.
You do not need the "For tt" loop any more.

For Each c As Control In Controls
    Dim b As Button = TryCast(c, Button)
    If b IsNot Nothing Then
        With b
            .Text = "test"
            .ForeColor = Color.Blue
        End With
    End If
Next


For tt 1 to 50
    Dim mybutton As Button = Me.Controls.Find("Button" & tt,True)(0)
    With mybutton
        .Text = "test"
        .Name = "Button" & tt
        .ForeColor = Color.Blue
    End With
next


这篇关于动态按钮图像更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-23 00:26