使C#表单在VISTA中居于首位 [英] Make C# form topmost in VISTA

查看:108
本文介绍了使C#表单在VISTA中居于首位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我们在Installer中使用具有自定义操作的Installer类.我们在安装程序类中将自定义表单显示为对话框表单.代码如下.我们正在使用C#.net lang.在VS.net中默认设置和部署项目.

受保护的 覆盖 无效 OnBeforeInstall(System.Collections. IDictionary savedState)

{

使用( frmShow fmShow = frmShow())

{

frmShow .ShowDialog()

}

.OnBeforeInstall(savedState);

}

它在XP中也能完美运行,并且在安装过程中会显示对话框形式. 但在VISTA中,"frmShow"表格返回到设置-安装"表格的后面.如果用户不自觉,则总是等待完成该过程,但是表单正在等待用户交互.

我已经测试过对前景做出不同的选择,但是它没有出现在前面. 我检查了User32的以下功能. api在frmShow中-绘制事件,但它没有出现在前面.我还使用了

this.bringtofront().但是 >

BringWindowToTop(this.Handle);

SwitchToThisWindow(this.Handle,true);

SetForegroundWindow( this .Handle);

我认为实现在VISTA中运行应用程序确实是真正的挑战. 633337194230757564>.请提出解决方案.

谢谢.

解决方案

我不确定您在这里的要求.我已经尝试在系统上使用一小段代码,但是效果很好.我遵循的步骤–

1. 创建具有两个Windows窗体的项目

2. 一个是主要形式,另一个是子形式

3. 从主表单中称为子表单.

4. 子表格被调用并始终显示在顶部主要形式.

但是,如果您的要求相反,这意味着您始终将主窗体保持在顶部,那么我也尝试过在我的系统上发生.这是我正在使用的代码–

私有 void button1_Click(对象发​​件人, EventArgs e)

{

//MessageBox.Show("Hello World");

frmChild child = frmChild ();

表格 frmShow = 表格 .ActiveForm;

.BringToFront();

}

this.BringToFront()始终将主窗体保持在顶部.以下是一些可能对您有帮助的链接–

http://msdn.microsoft.com/en -us/library/system.windows.forms.form.activeform.aspx

希望以上帮助.

谢谢.


Hello,

 

We are using Installer class with custom action in Setup . We are showing our custom form as a dialog form in installer class. Code is given follows. We are using C#.net lang. in VS.net default setup and deployement project.

 

protected override void OnBeforeInstall(System.Collections.IDictionary savedState)

{

using (frmShow fmShow = new frmShow())

{

frmShow.ShowDialog()

}

base.OnBeforeInstall(savedState);

}

 

 

It works perfectly in XP as well it shows dialog form during Setup process. But in VISTA "frmShow" form goes to back of Setup - Installation form. If user is not concious, one is always wait to complete the process but form is waiting for user interaction.

 

I have tested different options to make to foreground, but it does not appear at front. I checked following function of User32. api in frmShow - paint event but it does not appear front. I also used

this.bringtofront() also. but 

 

BringWindowToTop(this.Handle);

SwitchToThisWindow(this.Handle, true);

SetForegroundWindow(this.Handle);

 

I think its really headace to achieve application working in VISTA .  Please suggest the solution.

 

Thanks in advance.

解决方案

Hi,

I am not sure about your requirement here. I have tried with a small piece of code on my system but it worked fine. Steps which I followed –

1.       Created a project with two Windows forms

2.       One is main form and another is child form

3.       Called child form from main form.

4.       Child form gets called and always appears on the top of main form.

However, if your requirement was opposite which means you always keep the main form on the top then I tried with that too and it is happening on my system. Here is the code which I am using –

private void button1_Click(object sender, EventArgs e)

{

      //MessageBox.Show("Hello World");

 

      frmChild child = new frmChild();

 

      child.Show();

 

      Form frmShow = Form.ActiveForm;

      this.BringToFront();

 

}

this.BringToFront() always keeps the main form on the top. Here are few links which might be helpful for you –

http://social.msdn.microsoft.com/forums/cs-CZ/csharplanguage/thread/6b2c891f-62c0-49ab-8d13-0d20eeb59e39/

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.activeform.aspx

http://social.msdn.microsoft.com/forums/en-US/csharpgeneral/thread/24715e6a-ae98-486d-90dc-c8d7a2a4ce6a/

 

Hope above helps.

Thanks.

 


这篇关于使C#表单在VISTA中居于首位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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