0

我想将下面的 VB.net 代码写入 C#。C# 中最好的等效代码是什么:

Private Sub AllControlDesign2(ByRef TB As Control)
    If TB.GetType Is GetType(StatusStrip) Then
        CType(TB, TextBox).ReadOnly = True
        TB.BackColor = stFromBackColour
        TB.ForeColor = Color.Gray
    End If
End Sub
4

3 回答 3

1

我会做:

private void AllControlDesign2(Control tb) {
    var textBox = tb as TextBox;
    if (textBox != null) {
        textBox.ReadOnly = true;
        textBox.BackColor = stFromBackColour;
        textBox.ForeColor = Color.Gray;
    }
}
于 2012-11-10T06:44:45.980 回答
0

这是从DeveloperFusion.com复制的等价物

private void AllControlDesign2(ref Control TB)
{
    if (object.ReferenceEquals(TB.GetType, typeof(StatusStrip))) {
        ((TextBox)TB).ReadOnly = true;
        TB.BackColor = stFromBackColour;
        TB.ForeColor = Color.Gray;
    }
}
于 2012-11-10T06:41:26.910 回答
0
private void AllControlDesign2(ref Control TB)
{
    if (object.ReferenceEquals(TB.GetType, typeof(StatusStrip))) {
        ((TextBox)TB).ReadOnly = true;
        TB.BackColor = stFromBackColour;
        TB.ForeColor = Color.Gray;
    }
}

使用转换。

于 2012-11-10T06:41:40.573 回答