我想在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
答案 0 :(得分:1)
我会这样做:
private void AllControlDesign2(Control tb) {
var textBox = tb as TextBox;
if (textBox != null) {
textBox.ReadOnly = true;
textBox.BackColor = stFromBackColour;
textBox.ForeColor = Color.Gray;
}
}
答案 1 :(得分: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;
}
}
答案 2 :(得分: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;
}
}
使用this转换。