c#面向对象程序设计—— 弹出窗体以及新建窗体类的返回值,图片导入,退出问题

新建窗体类:
在form1的加载事件中加入以下语句:

        private void Form1_Load(object sender, EventArgs e)
        {
            Message mes = new Message();
            if (mes.ShowDialog() != DialogResult.OK) Application.Exit();
        }

在新建窗体类中加入以下程序

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 Message : Form
    {
        public Message()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (Nam.Text == "admin" && Password.Text == "123")
            {
                MessageBox.Show("Welcome","success", MessageBoxButtons.OK);
                this.DialogResult = DialogResult.OK;

            }
            else
            {
                MessageBox.Show("Gun","fale",MessageBoxButtons.OK);
                this.DialogResult = DialogResult.No;
            }
        }
    }
}

效果如下:
在这里插入图片描述

图片导入:

        private void Picture_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.ShowDialog();
            string path = op.FileName;
            pictureBox1.ImageLocation = path;
            FileInfo file = new FileInfo(path);
            file.CopyTo("your menu", true);
        }

退出键:

        private void edit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

comboBox的选择:

if(comboBox1.SelectedIndex>=0)
                emp.Marry = comboBox1.SelectedItem.ToString();

form事件的代码:

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;
using System.IO; 

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Employee emp = new Employee();

        private void Save_Click(object sender, EventArgs e)
        {
            emp.Nam=txtName.Text;
            if (rbMale.Checked)
                emp.Sex = "Male";
            else
                emp.Sex = "Female";
            emp.Birth = BirthDay.Text;
            emp.Addin = Addin.Text;
            if(comboBox1.SelectedIndex>=0)
                emp.Marry = comboBox1.SelectedItem.ToString();
            if (comboBox2.SelectedIndex >=0)
            emp.Politic = comboBox2.SelectedItem.ToString();
            emp.Jiguan = JiGuan.Text;
            emp.Native = MinZu.Text;
            if(XueLi.SelectedIndex>=0)
            emp.Educate = XueLi.SelectedItem.ToString();
            emp.Adress = Adress.Text;
            emp.Eadress = Eadress.Text;
            emp.Telnumber = TelNumber.Text;
            emp.Worknumber = WorkNumber.Text;
            if (comboBox3.SelectedIndex >=0)
            emp.Department = comboBox3.SelectedItem.ToString();
            richTextBox1.Text = emp.information();

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            Message mes = new Message();
            if (mes.ShowDialog() != DialogResult.OK) Application.Exit();


        }

        private void edit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void Picture_Click(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();
            op.ShowDialog();
            string path = op.FileName;
            pictureBox1.ImageLocation = path;
            FileInfo file = new FileInfo(path);
            file.CopyTo("your menu", true);
        }

    }
}

窗体界面如下:

在这里插入图片描述

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值