Make all Controls on a Form read-only at once

前端 未结 7 494
故里飘歌
故里飘歌 2021-01-12 07:40

Does anyone have a piece of code to make all Controls (or even all TextBoxes) in a Form which is read-only at once without having to set every Control to read-only individua

7条回答
  •  不思量自难忘°
    2021-01-12 08:14

    I haven't tested this, but it should work:

    foreach (var textBox in this.Controls.OfType())
        textBox.ReadOnly = true;
    

    Edit: This is not such a good solution it seems: see Timwi's comment.

提交回复
热议问题