0

如何将按钮的文本用作资源名称?

我的尝试:

Public Sub LlamadaButton(ByVal sender As Object, ByVal e As System.EventArgs)
   Dim ButtonN As Button = CType(sender, Button)
   Dim ResourceName = ButtonN.Text
   ReadDelimitedText(My.Resources._(ResourceName), ";")     ' The problem: My.Resources._(ResourceName)
   End Sub

错误:需要标识符

4

3 回答 3

3

使用My.Resources.ResourceManager.GetString方法。

Dim ResourceName = ButtonN.Text
ReadDelimitedText(My.Resources.ResourceManager.GetString("_" & ResourceName), ";")     
于 2013-01-06T00:22:05.097 回答
1
<script runat="server">
Public Sub LlamadaButton(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  Dim ButtonN As Button = CType(sender, Button)
  Dim ButtonText = ButtonN.Text
  MsgBox(ButtonText)
End Sub
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title></title>
</head>
<body>
  <form id="form1" runat="server">
    <div>
        <asp:Button ID="Button1" runat="server" Text="Button Bob" />
    </div>
  </form>
</body>
</html>

这是你的意思吗?,单击按钮将在消息框中显示文本,尝试更改按钮文本并再次单击它

于 2013-01-06T00:04:35.920 回答
1

假设您的资源文件名是Resource1.resx,并且其中的字符串是String1,您应该能够像这样访问它:

My.Resources.Resource1.String1
于 2013-01-06T01:27:59.133 回答