winform 介面跳轉
c# 一個窗體 跳轉到另一個窗體
窗體1程式碼
using System.Windows.Forms;
namespace CHUANGTI
{
public partial class Form1 : Form
{
public event EventHandler changeinfo;
/// <summary>
/// 介面跳轉
/// </summary>
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
/* 這裡是窗體抖動 其實是改變窗體的位置*/
Random ran = new Random((int)DateTime.Now.Ticks);
Point point = this.Location;
for (int i = 0; i < 20; i++)
{
this.Location = new Point(point.X + ran.Next(8) - 4, point.Y + ran.Next(8) - 4);
System.Threading.Thread.Sleep(15);
this.Location = point;
System.Threading.Thread.Sleep(15);
}
//跳轉到登入介面
this.DialogResult = System.Windows.Forms.DialogResult.OK;//實現介面跳轉
//Form2 FRM = new Form2();
}
}
}
窗體2程式碼
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace CHUANGTI
{
public partial class Form3 : Form
{
public event EventHandler initn;
public Form3()
{
InitializeComponent();
}
}
}
最重要的
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace CHUANGTI
{
static class Program
{
/// <summary>
/// 應用程式的主入口點。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new Form1());
Form1 SS = new Form1();
if(SS.ShowDialog() == DialogResult.OK)
{
Form3 SSS = new Form3();
if(SSS.ShowDialog() == DialogResult.OK)
{
Application.Run(new Form3());
}
}
}
}
}