显示和隐藏窗体 不能显示第二个窗体
出错不能显示二窗体,说
从未对字段“小项目.Form1.Form2Example”赋值,字段将一直保持其默认值 null
=============================================
一窗体代码如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 小项目
{
public partial class Form1 : Form
{
private Form2 Form2Example;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
Rectangle pos = new Rectangle(250,250,300,300);
Bounds = pos;
}
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
button2.Enabled = true;
button3.Enabled = true;
}
private void button2_Click(object sender, EventArgs e)
{
Form2Example.Visible = true;
}
private void button3_Click(object sender, EventArgs e)
{
Form2Example.Visible = false;
}
}
}
==========================
二窗体如下
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace 小项目
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
Rectangle pos = new Rectangle(550, 250, 300, 300);
Bounds = pos;
}
}
}
相关推荐
Qt实现窗体在显示屏旁边自动隐藏/显示
Qt实现窗体在显示屏旁边自动隐藏/显示,类似于QQ实现
QT-侧靠动画窗口-隐藏和显示窗体
1、QT-侧靠动画窗口-隐藏和显示窗体 2、动画显示效果
C# 启动隐藏窗体(只显示托盘)
C#程序启动时隐藏窗体,让程序最小化到托盘图标
窗体传值和显示隐藏
窗体传值和显示隐藏,包含常见方法,所见即所得.
C#窗体实现热键控制窗口隐藏显示
C#窗体实现热键控制窗口隐藏显示 主要类文件 class HotKey { //如果函数执行成功,返回值不为0。 //如果函数执行失败,返回值为0。要得到扩展错误信息,调用GetLastError。 [DllImport("user32.dll", SetLastError = true)] public static extern bool RegisterHotKey( IntPtr hWnd, //要定义热键的窗口的句柄 int id, //定义热键ID(不能与其它ID重复) KeyModifiers fsModifiers, //标识热键是否在按Alt、Ctrl、Shift、Windows等键时才会生效 Keys vk //定义热键的内容 ); [DllImport("user32.dll", SetLastError = true)] public static extern bool UnregisterHotKey( IntPtr hWnd, //要取消热键的窗口的句柄 int id //要取消热键的ID ); //定义了辅助键的名称(将数字转变为字符以便于记忆,也可去除此枚举而直接使用数值) [Flags()] public enum KeyModifiers { None = 0, Alt = 1, Ctrl = 2, Shift = 4, WindowsKey = 8 }


