How to make Combobox in winforms readonly

后端 未结 18 2070
攒了一身酷
攒了一身酷 2020-12-08 09:40

I do not want the user to be able to change the value displayed in the combobox. I have been using Enabled = false but it grays out the text, so it is not very

18条回答
  •  情歌与酒
    2020-12-08 10:00

    Simplest way in code:

    instead of adding methods for KeyPress or KeyDown, add this code on 'Form1_Load' method:

    comboBox1.KeyPress += (sndr, eva) => eva.Handled = true;

    or

    comboBox1.KeyDown += (sndr, eva) => eva.SuppressKeyPress = true;

    (sndr, eva) is for (object sender, EventArgs e)

提交回复
热议问题