• 大小: 59KB
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-09
  • 语言: C#
  • 标签: C#  winform  多个窗体  

资源简介

C#winform多个窗体之间相互传递数据操作。弹出一个新窗体,选中一个数据并传递到父窗体的某个控件上,可以是TextBox也可以是DataGrideView之间相互传递数据,处理并刷新等。

资源截图

代码片段和文件信息

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.Diagnostics;

namespace winfrom
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_Click(object sender EventArgs e)
        {
            frmTeachers frm = new frmTeachers();
            frm.Owner = this;
            frm.flag = “上课“;
            frm.Show();
        }

        private void textBox2_Click(object sender EventArgs e)
        {
            frmTeachers frm = new frmTeachers();
            frm.Owner = this;
            frm.flag = “签到“;
            frm.Show();
        }

        private void button1_Click(object sender EventArgs e)
        {
            this.labTeacher1.Text = ““;
            this.labTeacher2.Text = ““;
            this.txtTeacher1.Text = ““;
            this.txtTeacher2.Text = ““;
            Bind();
        }

        private void Form1_Load(object sender EventArgs e)
        {
            Bind();
        }
        //假数据,初始化:
        private void Bind()
        {
            DataTable dt1 = new DataTable();
            dt1.Columns.Add(“学号“ typeof(string));
            dt1.Columns.Add(“姓名“ typeof(string));
            dt1.Columns.Add(“上课教师“ typeof(string));
            dt1.Columns.Add(“签到教师“ typeof(string));

            dt1.Rows.Add(“1“ “小明“ ““ ““);

            dataGridView1.DataSource = dt1;
        }
        //这里应重新读取数据:
        public void Bind(string sid string shangke string qiandao)
        {
            DataTable dt1 = new DataTable();
            dt1.Columns.Add(“学号“ typeof(string));
            dt1.Columns.Add(“姓名“ typeof(string));
            dt1.Columns.Add(“上课教师“ typeof(string));
            dt1.Columns.Add(“签到教师“ typeof(string));

            if (sid == “1“)
            {
                dt1.Rows.Add(“1“ “小明“ shangke qiandao);               
            } 

            dataGridView1.DataSource = dt1;
        }

        private void dataGridView1_CellDoubleClick(object sender DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                string flag = this.dataGridView1.Columns[e.ColumnIndex].Name;//获取当前点击单元格的“表头”
                if (flag == “上课教师“)
                {
                    frmTeachers frm = new frmTeachers();
                    frm.Owner = this;
                    frm.flag = “上课教师“;
                    frm.sid = dataGridView1.Rows[e.RowIndex].Cells[“学号“].Value.ToString();
                    frm.shangke = dataGridView1.Rows[e.RowIndex].Cells[“上课教师“].Value.ToString();
                    frm.qiandao = dataGridView1.Rows[e.RowIndex].Cells[“签到教师“].Value.ToString();
                    frm.Show();
                }
                else if (flag == “

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2017-02-05 14:31  winfrom\
     目录           0  2017-02-05 14:35  winfrom\winfrom\
     文件         863  2017-02-05 14:31  winfrom\winfrom.sln
     文件       20992  2017-02-05 17:07  winfrom\winfrom.suo
     目录           0  2017-02-05 14:31  winfrom\winfrom\bin\
     目录           0  2017-02-05 14:42  winfrom\winfrom\bin\Debug\
     文件       16384  2017-02-05 17:06  winfrom\winfrom\bin\Debug\winfrom.exe
     文件       34304  2017-02-05 17:06  winfrom\winfrom\bin\Debug\winfrom.pdb
     文件       11600  2017-02-05 17:07  winfrom\winfrom\bin\Debug\winfrom.vshost.exe
     文件         490  2014-01-13 21:31  winfrom\winfrom\bin\Debug\winfrom.vshost.exe.manifest
     文件        3985  2017-02-05 17:06  winfrom\winfrom\Form1.cs
     文件       11846  2017-02-05 16:28  winfrom\winfrom\Form1.Designer.cs
     文件        7305  2017-02-05 16:28  winfrom\winfrom\Form1.resx
     文件        3117  2017-02-05 16:24  winfrom\winfrom\frmTeachers.cs
     文件        4260  2017-02-05 15:53  winfrom\winfrom\frmTeachers.Designer.cs
     文件        6183  2017-02-05 15:53  winfrom\winfrom\frmTeachers.resx
     目录           0  2017-02-05 14:31  winfrom\winfrom\obj\
     目录           0  2017-02-05 14:31  winfrom\winfrom\obj\x86\
     目录           0  2017-02-05 17:06  winfrom\winfrom\obj\x86\Debug\
     文件        2867  2017-02-05 14:31  winfrom\winfrom\obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache
     文件        6287  2017-02-05 17:06  winfrom\winfrom\obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache
     目录           0  2017-02-05 14:31  winfrom\winfrom\obj\x86\Debug\TempPE\
     文件         555  2017-02-05 17:07  winfrom\winfrom\obj\x86\Debug\winfrom.csproj.FileListAbsolute.txt
     文件        1039  2017-02-05 16:29  winfrom\winfrom\obj\x86\Debug\winfrom.csproj.GenerateResource.Cache
     文件       16384  2017-02-05 17:06  winfrom\winfrom\obj\x86\Debug\winfrom.exe
     文件         180  2017-02-05 16:29  winfrom\winfrom\obj\x86\Debug\winfrom.Form1.resources
     文件         180  2017-02-05 15:53  winfrom\winfrom\obj\x86\Debug\winfrom.frmTeachers.resources
     文件       34304  2017-02-05 17:06  winfrom\winfrom\obj\x86\Debug\winfrom.pdb
     文件         180  2017-02-05 14:42  winfrom\winfrom\obj\x86\Debug\winfrom.Properties.Resources.resources
     文件         488  2017-02-05 14:31  winfrom\winfrom\Program.cs
     目录           0  2017-02-05 14:31  winfrom\winfrom\Properties\
............此处省略6个文件信息

评论

共有 条评论