System.Windows.Forms.Keys.HasFlag behaving weirdly

后端 未结 3 543
悲哀的现实
悲哀的现实 2020-12-22 00:52

I have the following code, meant to prevent user from writing new-lines in a memo text editor:

private void m_commentMemoEdit_KeyDown(object sender, KeyEvent         


        
3条回答
  •  离开以前
    2020-12-22 01:28

    HasFlag is for Flags - which means if a bit is set or not

    the keyvalue is an ordinal value, so completely different from flags use the comparison operator and everything should be fine.

    some enum fields are defined like flags, e.g.

    enum SomeFlag
    {
       BitOne = 1, 
       BitTwo = 2, 
       Bitthree = 4
    };
    

    here it makes sense to use "HasFlag"

提交回复
热议问题