上显示的各种形式的顶部一个MessageBox,设置位置和/或颜色 [英] Displaying a MessageBox on top of all forms, setting location and/or color

查看:650
本文介绍了上显示的各种形式的顶部一个MessageBox,设置位置和/或颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个形式和我设置的形式最顶层属性设置为true之一。某处,在程序运行时,我将展示一个MessageBox,但由于最顶层设置为true,当消息框弹出它显示了最顶层的形式下,让我无法看到它。




  1. 有什么办法,我让我的一种形式总是在最前面,但是当一个消息框弹出,使该特定形式的顶部的消息框,说明了什么?


  2. 是否有可能给一个位置到MessageBox使其显示没有在中间,但例如低下来,屏幕上?


  3. 让我们说,我有一个橙色的形式,我可以有一个粉红色的消息框只为特定的应用程序。我的意思是我不是指弹窗颜色属性。 (我不想要的所有的消息框是粉红色的。)



解决方案

1)MessageBox.Show方法有一个的超载的是采用窗式的第一个参数。如果您使用过载,而不是仅仅显示(串),即:

 类MyForm的:表格{
无效方法(){
MessageBox.Show(这一点,blablablablabla);
}
}



然后在MessageBox将在模式现身模式,这将是恰好在该表格上顶。现在只需确保您传递最顶层的形式,就大功告成了。副作用是,在模式模式会导致直到该消息被驳回的消息框挡住原来的窗口。



2)不,那直接是不可能的。但是,您可以与.net努力打球并获得了处理的消息框,然后通过P将窗口移动/调用一些WINAPI的功能,但我建议你不要。



3)否,这只是不可能的提示消息



要实现在什么(2)和(3)是不可能的,因为MSGBOX意指是简单的。要获得的东西,你将不得不编写您自己的小表格将作为一个消息框,并提交形式,而不是消息框。这种形式可以有任何样式,任何位置,任何你喜欢的行为。


I have two forms and I set one of the forms' TopMost property to true. Somewhere, while the program runs, I show a MessageBox, but since TopMost is set to true, when the MessageBox pops up it shows under the topmost form so I cannot see it.

  1. Is there any way that I make one of my forms always be on top, but when a MessageBox pops up, make the message box show on top of that specific form?

  2. Is it possible to give a location to the MessageBox so that it shows not in the middle but for example low down on the screen?

  3. Let's say that I have an orange colored form can I have a pink colored message box only for that specific application. I mean I am NOT referring to playing the windows color properties. (I don't want all message boxes to be pink.)

解决方案

1) The MessageBox.Show method has an overload that takes a first parameter of Window type. If you use that overload instead of just Show(string), ie.:

class MyForm : Form {
    void method(){
       MessageBox.Show(this, "blablablablabla");
    }
}

then the MessageBox will show up in a 'modal' mode and it will be exactly on top on that form. Now just ensure that you pass that topmost form and you're done. Side effect is that the 'modal' mode will cause the Messagebox to BLOCK the original window until the message is dismissed.

2) No, that is not possible directly. However, you can play hard with .Net and get a "handle" to the messagebox and then move the window via P/Invoke to some WinApi functions, but I recommend you not.

3) No, that's just not possible with MessageBoxes

What you want to achieve in (2) and (3) is not possible, because the MsgBox is meant to be simple. To get that things you will have to write your own tiny form that will act as a message box, and present that form instead of the message box. That form will be able to have any styling, any position and any behaviour you like.

这篇关于上显示的各种形式的顶部一个MessageBox,设置位置和/或颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆