如何在C#中切换表格 [英] How to switch forms in C#

查看:86
本文介绍了如何在C#中切换表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在编写一个程序,其中用户单击是"或否".然后弹出一个消息框,然后在用户单击确定"后,我希望它显示我创建的新表单.事情是我不知道如何编程该程序以切换到另一种形式.是的,我尝试过form2.Show,但它不起作用.我也尝试了form2.Show().请帮忙!

这是代码(是的,我知道它是一个愚蠢的程序,但是我是新手,我正在玩它:
使用系统;
使用System.Collections.Generic;
使用System.ComponentModel;
使用System.Data;
使用System.Drawing;
使用System.Linq;
使用System.Text;
使用System.Windows.Forms;
命名空间WindowsFormsApplication1
{
公共局部类Form1:Form
{
公共Form1()
{
InitializeComponent();
}
private void button1_Click(对象发送者,EventArgs e)
{
MessageBox.Show("Good choice");
Form2.Show;
}
private void button2_Click(对象发送者,EventArgs e)
{
MessageBox.Show("Eh");
}
}
}

Hi, I am making a program in which a user clicks "yes" or "no". Then a message box pops up and then after the user clicks ok, i want it to show a new form that i have created. the thing is i don''t know how to program the program to switch to another form. And yes, I have tried form2.Show and it doesn''t work. I also tried form2.Show(). Please help!

Here is the code(and yes i know its a stupid program, but I''m new and i''m playing around with it:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Good choice");
Form2.Show;
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Eh");
}
}
}

推荐答案

它应该像 ^ ],因此除非您在此处发布一些代码,否则任何人都很难检测到可能出了什么问题.
It should be as simple as this.[^], so unless you post some code here it will be hard for anyone to detect what could be going wrong.


尝试这个:

try this:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Good choice");

Form2 frm = new Form2();
frm.ShowDialog();
}
private void button2_Click(object sender, EventArgs e)
{
MessageBox.Show("Eh");
}
}
}



希望这会有所帮助:)



hope this helps :)


这篇关于如何在C#中切换表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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