简体   繁体   English

总是在最上面,但是需要消息框和组合框

[英]always on top form but requires message boxes and combobox

I have a form that is set to always ontop. 我有一个设置为始终在最前面的表单。 I force this every 500 ms via a timer shown below in code. 我通过以下代码中的计时器每500毫秒强制执行一次。 The timer is being started from a child thread. 正在从子线程启动计时器。

The form has to raise an error sometimes but this is not modal and the users ends having to click it twice - once to make it modal and once to acknowledge it (if they do it fast enough) 表单有时会引发错误,但这不是模态的,用户最终不得不单击两次,一次是使其变为模态,一次是对其进行确认(如果他们做得足够快)

The user can also bring up a combobox that is in a panel in the main form but when selecting this, the dropdown becomes clear again, as a result of the timer making the form modal(the same effect as if the user just clicked away from the combobox). 用户还可以调出主窗体面板中的组合框,但是当选择此选项时,由于计时器使窗体成为模态,结果下拉列表再次变得清晰(就像用户只是单击鼠标左键一样。组合框)。

How can i fix the Messagebox that it is modal? 如何修复消息框是模态的? How can i fix the combobox that it continues to list the items within it without clearing thanks damo 我该如何修复组合框,使其继续列出其中的项目,而无需清除感谢damo

timer to make form always on top 计时器使表格始终排在最前面

// Restore the form.
this.Visible = true;
this.TopMost = true;
this.WindowState = FormWindowState.Maximized;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
this.Show();

messagebox 留言框

MessageBox.Show(this,"hello world", "myApplication");

Just disable the timer before and reenable after showing the messagebox: 只需在显示消息框之前禁用计时器,然后再重新启用它即可:

timer1.Enabled = false;
MessageBox.Show(this,"hello world", "myApplication");
timer1.Enabled = true;

This of course can be in a method so you won't have to duplicate code: 当然,这可以在方法中,因此您不必重复代码:

public void ShowMessage(string title, string message)
{
   timer1.Enabled = false;
   MessageBox.Show(this,message, title);
   timer1.Enabled = true;
}

Since MessageBox.Show is a blocking command, timer will only be reEnabled after the MessageBox is closed 由于MessageBox.Show是阻止命令,因此仅在关闭MessageBox后才重新启用计时器

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

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