按钮被用户重新命名 [英] Buttons to be renamed by the user
问题描述
我有编码的一些我的按钮的问题。这是我到目前为止有:
I am having problems coding some of my buttons. This is what I've got so far:
Public Class Form1
Dim Button(12) As Button
Dim X As Integer
Private Sub EventName()
Dim message, title, defaultValue As String
Dim myValue As Object
If Label4.Text = "Admin" Then
' Set prompt.
Message = "Enter Product Name"
' Set title.
title = "Product Name"
defaultValue = "" ' Set default value.
'Display message, title, and default value.
myValue = InputBox(Message, title, defaultValue)
Button(X).Text = myValue
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click, Button9.Click, Button8.Click, Button7.Click, Button6.Click, Button5.Click, Button4.Click, Button3.Click, Button2.Click, Button12.Click, Button11.Click, Button10.Click
'Dim message, title, defaultValue As String
'Dim myValue As Object
For Me.X = 1 To 10
>>>>> <<<<<<<
Next
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button(1) = Button1
Button(2) = Button2
Button(3) = Button3
Button(4) = Button4
Button(5) = Button5
Button(6) = Button6
Button(7) = Button7
Button(8) = Button8
Button(9) = Button9
Button(10) = Button10
Button(11) = Button11
Button(12) = Button12
End Sub
我想要做的,就是如果我点击按钮7,一个输入框来为用户输入按钮的名称。不管是什么我都试过之间的&GT;&GT;&GT;&GT;&GT; &LT;&LT;&LT;&LT;&LT;
,我似乎无法得到它的权利。
What I'm trying to do, is if I click button 7, an input box comes up for the user to input the button's name. No matter what I have tried between the >>>>> <<<<<
, I can't seem to get it right.
推荐答案
这听起来像你只是想一个人去点击一个按钮并更改按钮上的文字?
It sounds like you just want a person to click on a button and change the text of that button?
如果这是正确的,这样的事情会在你点击的方法工作:
If that is correct, something like this would work in your click method:
With DirectCast(sender, Button)
.Text = InputBox("Button Name", "Button Name", .Text)
End With
如果每个按钮需要相同的输入,然后再尝试这样的事:
If every button needs that same input, then try something like this:
Dim value As String = InputBox("Button Name", "Button Name")
For Each btn As Button In Buttons
If btn IsNot Nothing Then
btn.Text = value
End If
Next
您应该认真考虑使用数组按钮逐渐远离。如果您需要在列表中持有这些按钮的参考,使用列表(巴顿)
代替。
You should strongly consider moving away from using that Buttons array. If you need to hold a reference of those buttons in a list, use a List(of Button)
instead.
这篇关于按钮被用户重新命名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!