我需要弄清楚如何将 class 库中的枚举绑定到应用程序中的单选按钮

I need to figure out how to bind my enum in my class library to the radio buttons in my application

我不知道如何将我的 class 库中的枚举绑定到我的单选按钮以显示其中一个已被选中并从枚举中提取答案 我的单选按钮的名称是 radCopper、radNickel、radGold、radSilver、radPalladium、radPlatinum 和 radZinc。 这是我需要在 class 库

中使用的枚举
Namespace CoinCollection
`Public Class Coin
Public Enum Metal
            Gold
            Silver
            Platinum
            Copper
            Zinc
            Nickel
            Palladium
        End Enum`
This is the button I need to display the radio button checked when clicked

Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
Dim Met = [Enum].GetValues(GetType(Coinn.Metal))
        If radCopper.Checked Then
            MessageBox.Show("Copper")
        End If

此按钮还将我的 class 库中的其他枚举绑定到我当前正在工作的下拉列表

Private Sub btnInsert_Click(sender As Object, e As EventArgs) Handles btnInsert.Click
        Dim Curr = [Enum].GetValues(GetType(Coinn.Currency))
        MessageBox.Show(cboCurrency.SelectedItem, GetType(Coinn.Currency).Name)

RadioButtons 没有绑定。您只需要使用一些代码来获取适当的值。您可以在事后通过索引这样做,例如

Dim radioButtons = {radGold, radSilver, ...}
Dim checkedIndex = Array.IndexOf(radioButtons, radioButtons.Single(Function(rb) rb.Checked))
Dim metalValue = DirectCast([Enum].GetValues(GetType(Metal)), Metal())(checkedIndex)

或者,您可以在事前使用控件的 Tag 属性,例如

Dim radioButtons = {radGold, radSilver, ...}
Dim metalValues = DirectCast([Enum].GetValues(GetType(Metal)), Metal())

For i = 0 To radioButtons.GetUpperBound(0)
    radioButtons(i).Tag = metalValues(i)
Next

您可以在事后从选中的 RadioButton 中获取适当的值,例如

Dim metalValue = DirectCast(radioButtons.Single(Function(rb) rb.Checked).Tag, Metal)