Windows窗体不会在调试模式下显示 [英] Windows Form Won't Display in Debug Mode

查看:101
本文介绍了Windows窗体不会在调试模式下显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级到了VS 2012.我有一套编码的UI测试,我在VS 2010中编码,我试图在VS 2012中进行编码。我有一个窗体,我显示在通过使用AssemblyInitialize属性运行测试的开始。我使用此表单允许用户从值集合中进行选择,这些值用于数据提供测试。以下是我的代码的一个副本:

  [AssemblyInitialize] 
public static void AssemblyInitialize(TestContext context)
{
ProcessUtility.TerminateAll();
if(!File.Exists(Directory.GetCurrentDirectory()+ @\RunInfo.ser))
{
InitializeForm initForm = new InitializeForm();
initForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
initForm.ShowDialog();
}
}

所以,这是我的头痛:窗体显示刚好在运行模式。但是,如果我尝试在调试模式下旋转它,它不会显示。我已经完成了代码。它正在加载表单的所有控件,没有错误。我将其转到'initForm.ShowDialog()'代码行。它运行这行代码,但没有任何反应。我没有收到任何错误,IDE左下角的状态为就绪。这几乎就好像IDE认为表单是显示的,但不是。我已经检查过任务管理器,只是不在那里。我已经验证了构建配置设置为Debug。我已经尝试清理解决方案并重新构建。这段代码在VS 2010中继续工作。请告诉我有人在遇到类似的问题,因为我没有想法。我是新来的stackoverflow,所以让我知道,如果还有什么我可以提供更好地解释这个问题。谢谢你提前看看它。

解决方案

我可以使用以下代码取得表单,的ShowDialog。我仍然不知道为什么ShowDialog不工作,但这是诀窍:

  InitializeForm initForm = new InitializeForm(); 
initForm.Visible = true;
initForm.Focus();
Application.Run(initForm);


I recently upgraded to VS 2012. I have a set of coded UI tests that I've coded in VS 2010 and I'm trying to spin them up in VS 2012. I have a windows form that I'm displaying at the beginning of the test run by using the AssemblyInitialize attribute. I use this form to allow users to select from sets of values and those values are used to data feed the tests. Here's a copy of my code that displays the form:

[AssemblyInitialize]
public static void AssemblyInitialize(TestContext context)
{
    ProcessUtility.TerminateAll();
    if (!File.Exists(Directory.GetCurrentDirectory() + @"\RunInfo.ser"))
    {
        InitializeForm initForm = new InitializeForm();
        initForm.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
        initForm.ShowDialog();
    }
}

So, here's my headache: the form displays just fine in Run mode. However, if I try to spin it up in Debug mode, it never displays. I've stepped through the code. It's loading all of the controls for the form with no errors. I make it to the 'initForm.ShowDialog()' line of code. It runs that line of code but then nothing happens. I don't receive any errors and the status in the lower left of the IDE is 'Ready'. It's almost as if the IDE thinks the form is displayed but it's not. I've double-checked the Task Manager and it's just not there. I've verified the build configuration is set to Debug. I've tried cleaning the solution and re-building. This code continues to work in VS 2010. Please tell me someone out there has ran into a similar problem because I'm out of ideas. I'm new to stackoverflow so let me know if there is anything else I can provide to better explain the issue. Thank you in advance for taking a look at it.

解决方案

I was able to get the form to display using the following code instead of ShowDialog. I still have no idea why ShowDialog wasn't working but this does the trick:

InitializeForm initForm = new InitializeForm();
initForm.Visible = true;
initForm.Focus();
Application.Run(initForm);

这篇关于Windows窗体不会在调试模式下显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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