简体   繁体   English

WindowsForms TopMost 与 ComboBox

[英]WindowsForms TopMost versus ComboBox

I have a WindowsForms application in which I open a Form as a Dialog (Form2.ShowDialog) and in this Form I have a Timer that sets the TopMost property of the Form to true.我有一个 WindowsForms 应用程序,我在其中打开一个窗体作为对话框 (Form2.ShowDialog),在这个窗体中我有一个计时器,它将窗体的 TopMost 属性设置为 true。 But I also have a ComboBox in this Form and when I click on the ComboBox to select an Item, the list opens and closes immediately as the Timer sets the TopMost property back to true.但是我在这个表单中也有一个 ComboBox,当我单击 ComboBox 到 select 一个项目时,列表会立即打开和关闭,因为计时器将 TopMost 属性设置回 true。

If you ask me This is wrong way and should be replace your "load data function" from timer to form_load event.如果你问我这是错误的方式,应该将你的“加载数据功能”从计时器替换为 form_load 事件。 so if you want current way you should disable timer in ComboBox Enter Event and enable timer in ComboBox Leave Event.所以如果你想要当前的方式,你应该在 ComboBox Enter Event 中禁用计时器并在 ComboBox Leave Event 中启用计时器。

    private void comboBox1_Enter(object sender, EventArgs e)
    {
        timer1.Enabled = false;
    }

    private void comboBox1_Leave(object sender, EventArgs e)
    {
        timer1.Enabled = true;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM