C# 关掉当前界面,返回到上一界面,但不重新创建

说明

我们以一个例子说明(登录窗体:Form_login();用户窗体:Form_user()):
当我们制作了一个管理系统,其中含有登录功能,很多时候我们登录成功进入到用户界面,但此时我们需要退出用户,回到登录界面,我们可能会选择这样处理:

Form_user form_user = new Form_user();	// 实例化将要进入的窗体对象
form_user.Show();	// 显示窗口
this
  • 5
    点赞
  • 24
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,以下是一个简单的微信界面C#代码,只有界面,没有功能: ```csharp using System; using System.Windows.Forms; namespace WeChatInterface { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { this.Text = "微信"; this.Width = 600; this.Height = 800; this.FormBorderStyle = FormBorderStyle.FixedSingle; // 上面的标题栏 Panel panelTitle = new Panel(); panelTitle.Dock = DockStyle.Top; panelTitle.Height = 50; panelTitle.BackColor = System.Drawing.Color.FromArgb(0, 122, 204); this.Controls.Add(panelTitle); // 标题栏上的关闭按钮 Button btnClose = new Button(); btnClose.Text = "×"; btnClose.Font = new System.Drawing.Font("宋体", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); btnClose.ForeColor = System.Drawing.Color.White; btnClose.FlatStyle = FlatStyle.Flat; btnClose.BackColor = System.Drawing.Color.FromArgb(0, 122, 204); btnClose.FlatAppearance.BorderSize = 0; btnClose.Dock = DockStyle.Right; btnClose.Width = 50; btnClose.Height = 50; btnClose.Click += BtnClose_Click; panelTitle.Controls.Add(btnClose); // 标题栏上的标题 Label lblTitle = new Label(); lblTitle.Text = "微信"; lblTitle.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); lblTitle.ForeColor = System.Drawing.Color.White; lblTitle.Dock = DockStyle.Fill; lblTitle.TextAlign = System.Drawing.ContentAlignment.MiddleCenter; panelTitle.Controls.Add(lblTitle); // 左侧的联系人列表 ListBox listBoxContacts = new ListBox(); listBoxContacts.Dock = DockStyle.Left; listBoxContacts.Width = 200; listBoxContacts.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); listBoxContacts.Items.Add("联系人1"); listBoxContacts.Items.Add("联系人2"); listBoxContacts.Items.Add("联系人3"); listBoxContacts.Items.Add("联系人4"); listBoxContacts.Items.Add("联系人5"); listBoxContacts.Items.Add("联系人6"); listBoxContacts.Items.Add("联系人7"); listBoxContacts.Items.Add("联系人8"); listBoxContacts.Items.Add("联系人9"); listBoxContacts.Items.Add("联系人10"); this.Controls.Add(listBoxContacts); // 右侧的聊天窗口 Panel panelChat = new Panel(); panelChat.Dock = DockStyle.Fill; panelChat.Padding = new Padding(10); panelChat.BackColor = System.Drawing.Color.White; this.Controls.Add(panelChat); // 聊天窗口上面的标题 Label lblChatTitle = new Label(); lblChatTitle.Text = "联系人1"; lblChatTitle.Font = new System.Drawing.Font("微软雅黑", 15F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); lblChatTitle.ForeColor = System.Drawing.Color.FromArgb(0, 122, 204); lblChatTitle.Dock = DockStyle.Top; lblChatTitle.Padding = new Padding(10); panelChat.Controls.Add(lblChatTitle); // 聊天记录 TextBox txtChatRecord = new TextBox(); txtChatRecord.Multiline = true; txtChatRecord.ReadOnly = true; txtChatRecord.ScrollBars = ScrollBars.Vertical; txtChatRecord.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); txtChatRecord.Dock = DockStyle.Top; txtChatRecord.Height = 500; txtChatRecord.Text = "这里是聊天记录"; panelChat.Controls.Add(txtChatRecord); // 发送消息的文本框 TextBox txtSend = new TextBox(); txtSend.Multiline = true; txtSend.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); txtSend.Dock = DockStyle.Bottom; txtSend.Height = 100; panelChat.Controls.Add(txtSend); // 发送按钮 Button btnSend = new Button(); btnSend.Text = "发送"; btnSend.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))); btnSend.ForeColor = System.Drawing.Color.White; btnSend.FlatStyle = FlatStyle.Flat; btnSend.BackColor = System.Drawing.Color.FromArgb(0, 122, 204); btnSend.FlatAppearance.BorderSize = 0; btnSend.Dock = DockStyle.Right; btnSend.Width = 100; btnSend.Height = 50; btnSend.Click += BtnSend_Click; panelChat.Controls.Add(btnSend); } private void BtnClose_Click(object sender, EventArgs e) { this.Close(); } private void BtnSend_Click(object sender, EventArgs e) { // 发送消息的代码 } } } ``` 注意:此代码仅为界面演示,不包含任何实际功能。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值