当我调用另一个窗体时,它显示为空白 [英] When I call another windows form, it shows up blank

查看:91
本文介绍了当我调用另一个窗体时,它显示为空白的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我正在为朋友编写一个简单的应用程序,只是为了演示加密并解释加密如何在日常计算机上运行。



然而,我遇到了一个问题;当我尝试调用解密数据的表单时,它显示为空白。



我尝试了什么:



所以,我尝试使用我在所有其他表单上使用的.show()方法,但现在表单空白了。



以下是我尝试使用的代码:



First Form - 我会点击一个按钮来调用解密表格/窗口:



So, I'm currently writing a simple application for a friend, just to demonstrate cryptography and explain how encryption works on everyday computers.

However, I've ran into an problem; When I try and call the form that decrypts the data, it shows up blank.

What I have tried:

So, I've tried using the .show() method that I used on all of my other forms, but now the form comes up blank.

Below is the code that I have tried to use:

First Form - I would click a button to call the decryption form/window:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Media;

namespace CryptExample
{

    //Form 1

    public partial class cryptMsg : Form
    {
        public cryptMsg()
        {
            InitializeComponent();
        }

        private void pictureBox3_Click(object sender, EventArgs e)
        {
            cryptUnlock showDecrypt = new cryptUnlock();
            showDecrypt.Show();
        }

        private void label2_Click(object sender, EventArgs e)
        {
            cryptUnlock showDecrypt = new cryptUnlock();
            showDecrypt.Show();
        }
    }
}





第二表格 - 解密窗口





Second Form - The decryption window

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Security;
using System.Security.Cryptography;
using System.IO;
using System.Net;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace CryptExample
{
	//Form 2
	
    public partial class cryptUnlock : Form
    {
    	public cryptUnlock()
        {
            InitializeComponent();
            //Add in decryption stuff later
        }
    }
}

推荐答案

首先在设计器中查看您的表单:它是否有任何控件?它是否编译干净,没有错误,没有警告?

如果确实如此,那么在这两种方法的第一行放置一个断点,然后在调试器中运行你的应用程序。当它到达断点时,进入构造函数并确保设计器生成的代码正在创建控件并将它们添加到表单中。

如果一切正常并且没有异常或其他错误,然后你需要通过显示空白来准确解释你的意思 - 如果正确添加控件,表单将不会真正空白。
Start by looking at your form in the designer: does it have any controls on it? Does it compile clean, with no errors and no warnings?
If it does, then put a breakpoint on the first line of both of those methods, and run your app in the debugger. When it hits the breakpoint, step into the constructor and make sure that the designer generated code is creating the controls and adding them to your form.
If everything looks right and you get no exceptions, or other errors, then you need to explain exactly what you mean by "shows up blank" - if the controls are added correctly, the form will not be truly blank.


尝试 ShowDialog()代替。



使用 Show()使其成为无模式窗体,它可能在你的主表单后面。
Try ShowDialog() instead.

Using Show() makes it a modeless form, and it's probably behind your main form.


我忘了将以下代码添加到我的解密表单(CryptUnlock);



I forgot to add the following code to my decryption form (CryptUnlock);

public cryptUnlock()
        {
            InitializeComponent();
        }


这篇关于当我调用另一个窗体时,它显示为空白的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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