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

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

问题描述

我最近升级到了VS2012.我已经在VS 2010中进行了一组编码的UI测试,并且正在尝试在VS 2012中进行测试.我有一个Windows窗体,我将在其中显示使用AssemblyInitialize属性运行测试的开始.我使用这种形式允许用户从一组值中进行选择,这些值用于为测试提供数据.这是显示表单的我的代码的副本:

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();
    }
}

所以,这让我很头疼:在运行"模式下,窗体显示得很好.但是,如果我尝试以调试"模式启动它,它将永远不会显示.我已经逐步完成了代码.它正在正确加载表格的所有控件.我将其添加到代码的"initForm.ShowDialog()"行中.它运行那行代码,但是什么也没发生.我没有收到任何错误,IDE左下角的状态为就绪".几乎就像IDE认为表单已显示一样,但事实并非如此.我已经仔细检查了任务管理器,但它不在那儿.我已经验证了构建配置已设置为调试".我曾尝试清洁解决方案并重新构建.这段代码在VS 2010中可以继续使用.请告诉我那里有人遇到了类似的问题,因为我没有想法.我是stackoverflow的新手,所以让我知道我还有什么可以提供的,以更好地解释该问题.预先感谢您的关注.

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.

推荐答案

不确定该解决方案为何有效,但是我能够通过在我试图显示的表单上将visible属性设置为true来解决VS2013中的此问题,然后在调用ShowDialog之前为false.

Not sure why this solution works, but I was able to solve this issue in VS2013 by setting the visible property on the form I was trying to display to true and then false before calling ShowDialog.

VB.Net示例代码

VB.Net example code

Dim form as Form = new Form
form.Visible = True
form.Visible = False
form.ShowDialog

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

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