| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 5538 人关注过本帖
标题:C#怎么写代码从一个窗口跳到另一个窗口
只看楼主 加入收藏
mmnh80
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-7-1
收藏
 问题点数:0 回复次数:16 
C#怎么写代码从一个窗口跳到另一个窗口
设置按钮的click代码应该怎么写
比如说当前窗口是Form1,上面设置一个按钮button1
怎么写click事件跳转到以建立的form2
(新手,刚起步,请大家指点)

我这样写的 为什么不起作用


Form2 frm2=new Form2();
frm2.Show();
搜索更多相关主题的帖子: 窗口 代码 click 按钮 
2006-04-05 16:36
mmnh80
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-7-1
收藏
得分:0 
怎么包含调用的文件?

2006-04-05 16:46
Flying12
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2006-4-2
收藏
得分:0 

试试这个

Form Frm = new Form();
Frm.showDialog(this);

2006-04-05 17:09
mmnh80
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-7-1
收藏
得分:0 

/*

*/
using System;
using System.Drawing;
using System.Windows.Forms;
using System.IO;

namespace feng
{
/// <summary>
/// Description of MainForm.
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuCut;
private System.Windows.Forms.MenuItem menuHelp;
private System.Windows.Forms.MenuItem menuFile;
private System.Windows.Forms.MenuItem menuExit;
private System.Windows.Forms.MenuItem menuLoad;
private System.Windows.Forms.MenuItem menuSave;
private System.Windows.Forms.MenuItem menuPast;
private System.Windows.Forms.MenuItem menuCopy;
private System.Windows.Forms.MenuItem menuAbout;
private System.Windows.Forms.MenuItem menuEditor;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}

[STAThread]
public static void Main(string[] args)
{
Application.Run(new MainForm());
}

#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.menuEditor = new System.Windows.Forms.MenuItem();
this.menuAbout = new System.Windows.Forms.MenuItem();
this.menuCopy = new System.Windows.Forms.MenuItem();
this.menuPast = new System.Windows.Forms.MenuItem();
this.menuSave = new System.Windows.Forms.MenuItem();
this.menuLoad = new System.Windows.Forms.MenuItem();
this.menuExit = new System.Windows.Forms.MenuItem();
this.menuFile = new System.Windows.Forms.MenuItem();
this.menuHelp = new System.Windows.Forms.MenuItem();
this.menuCut = new System.Windows.Forms.MenuItem();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
//
// menuEditor
//
this.menuEditor.Index = 2;
this.menuEditor.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuCut,
this.menuCopy,
this.menuPast});
this.menuEditor.Text = "Editor(E)";
//
// menuAbout
//
this.menuAbout.Index = 0;
this.menuAbout.Text = "About(A)";
this.menuAbout.Click += new System.EventHandler(this.MenuAboutClick);
//
// menuCopy
//
this.menuCopy.Index = 1;
this.menuCopy.Text = "Copy(O)";
//
// menuPast
//
this.menuPast.Index = 2;
this.menuPast.Text = "Past(P)";
//
// menuSave
//
this.menuSave.Index = 2;
this.menuSave.Text = "Save(S)";
//
// menuLoad
//
this.menuLoad.Index = 0;
this.menuLoad.Text = "Load(L)";
this.menuLoad.Click += new System.EventHandler(this.MenuLoadClick);
//
// menuExit
//
this.menuExit.Index = 1;
this.menuExit.Text = "Exit(E)";
this.menuExit.Click += new System.EventHandler(this.MenuExitClick);
//
// menuFile
//
this.menuFile.Index = 0;
this.menuFile.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuLoad,
this.menuExit,
this.menuSave});
this.menuFile.Text = "File(F)";
//
// menuHelp
//
this.menuHelp.Index = 1;
this.menuHelp.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuAbout});
this.menuHelp.Text = "Help(H)";
//
// menuCut
//
this.menuCut.Index = 0;
this.menuCut.Text = "Cut(C)";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuFile,
this.menuHelp,
this.menuEditor});
//
// MainForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(456, 365);
this.Menu = this.mainMenu1;
this.Name = "MainForm";
this.Text = "MainForm";
}
#endregion
void MenuExitClick(object sender, System.EventArgs e)
{
Application.Exit();
}

void MenuLoadClick(object sender, System.EventArgs e)
{
OpenFileDialog dlgOpenFile=new OpenFileDialog();
dlgOpenFile.Title="open";
dlgOpenFile.Filter="open(*.txt)|*.txt|All Files(*.*)|*.*";
if(dlgOpenFile.ShowDialog()==DialogResult.OK)
{
string fileName=dlgOpenFile.FileName;
FileStream aFile=new FileStream(fileName,FileMode.Open);
StreamReader sr=new StreamReader(aFile);
this.Text=fileName;
sr.Close();
this.menuSave.Enabled=false;
}
}

void MenuAboutClick(object sender, System.EventArgs e)
{
Form1 frm2=new Form1();
frm2.Show();

}

}
}


2006-04-05 17:24
mmnh80
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-7-1
收藏
得分:0 

/*

*/

using System;
using System.Drawing;
using System.Windows.Forms;

namespace DefaultNamespace
{
/// <summary>
/// Description of Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
public Form1()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();

//
// TODO: Add constructor code after the InitializeComponent() call.
//
}

#region Windows Forms Designer generated code
/// <summary>
/// This method is required for Windows Forms designer support.
/// Do not change the method contents inside the source code editor. The Forms designer might
/// not be able to load this method if it was changed manually.
/// </summary>
private void InitializeComponent() {
this.textBox1 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 96);
this.textBox1.Name = "textBox1";
this.textBox1.TabIndex = 1;
this.textBox1.Text = "hello!! xuefeng";
//
// button1
//
this.button1.Location = new System.Drawing.Point(192, 224);
this.button1.Name = "button1";
this.button1.TabIndex = 0;
this.button1.Text = "确定";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "About";
this.Load += new System.EventHandler(this.Form1Load);
this.ResumeLayout(false);
}
#endregion
void Form1Load(object sender, System.EventArgs e)
{

}

}
}


2006-04-05 17:25
mmnh80
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-7-1
收藏
得分:0 
提示说 找不到文件   不 知道为什么

2006-04-05 17:26
smofbao
Rank: 1
等 级:新手上路
帖 子:135
专家分:0
注 册:2006-4-5
收藏
得分:0 

怎么在Form1中用个方法让Form1关闭同时让Form2打开??
(新手才学)
先先谢谢了


2006-04-05 17:57
唐伯猫
Rank: 8Rank: 8
等 级:贵宾
威 望:45
帖 子:5323
专家分:58
注 册:2005-8-9
收藏
得分:0 
说不定你某个细节错了,仔细找找。

<iframe name="alimamaifrm" frameborder="0" marginheight="0" marginwidth="0" border="0" scrolling="no" width="300" height="170" src="/go/app/tbk_app/chongzhi_300_170.php?pid=mm_28854300_2441872_11377541&page=chongzhi_300_170.php&size_w=300&size_h=170&stru_phone=1&stru_game=1&stru_travel=1" ></iframe>
2006-04-05 18:08
smalc
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2006-4-4
收藏
得分:0 
所试验一下
2006-04-05 19:57
wang51168
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2006-2-23
收藏
得分:0 

你必须保证这个窗体及代码同时在这个项目文件夹下,
Form2 fm=new Form();
fm.Owner=this;
fm.Showdialog();

2006-04-06 13:52
快速回复:C#怎么写代码从一个窗口跳到另一个窗口
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.026642 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved