开发者

Event on each Control Array in C#

i asked this question previously in vb.net but i want to do it in c#..

Private Sub cbtns_ClickButtonArea(ByVal Sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles cbtn_a.ClickButtonArea, cbtn_b.ClickButtonArea, cbtn_c.ClickButtonArea, cbtn_d.ClickButtonArea
Dim cbtn As CButtonLib.CButton() = {cbtn_a, cbtn_b, cbtn_c, cbtn_d}        
Dim clickedBtn As CButtonLib.CButton = DirectCast(sender, CButtonLib.CButton)

For Each cb As CButtonLib.CButton In cbtn
    If cb Is clickedBtn Then
        cb.Enabled = False
    Else
        cb.Enabled = True
    End If
Next        
End S开发者_运维百科ub

how to convert this to c#?


Something like this

private void cbtns_ClickButtonArea(System.Object Sender, System.Windows.Forms.MouseEventArgs e)
{
    CButtonLib.CButton[] cbtn = {
        cbtn_a,
        cbtn_b,
        cbtn_c,
        cbtn_d
    };
    CButtonLib.CButton clickedBtn = (CButtonLib.CButton)sender;

    foreach (CButtonLib.CButton cb in cbtn) {
        if (cb == clickedBtn)) {
            cb.Enabled = false;
        } else {
            cb.Enabled = true;
        }
    }
}

and

cbtn_a.ClickButtonArea += cbtns_ClickButtonArea;
cbtn_b.ClickButtonArea += cbtns_ClickButtonArea;
cbtn_c.ClickButtonArea += cbtns_ClickButtonArea;
cbtn_d.ClickButtonArea += cbtns_ClickButtonArea;

Since c# does not have and equivalent to Handles, the event handlers have to be added like it's shown above.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜