• C#学习笔记(32)——委托改变窗体颜色


    说明(2017-11-23 22:17:34):

    1. 蒋坤的作业,点击窗体1里面的按钮,出现窗体2;点击窗体2里的按钮,窗体1改变背景色。

    2. 做完窗体传值后,这个作业就很简单了。

    代码:

    Form1:

    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 _06_窗体传值
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                Form2 f2 = new Form2(ChangeColor);
                f2.Show();
            }
            private void ChangeColor()
            {
                this.BackColor = System.Drawing.Color.Black;
            }
        }
    }

    Form2:

    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 _06_窗体传值
    {
        public partial class Form2 : Form
        {
            public Form2()
            {
                InitializeComponent();
            }
            private Action _a;
            public Form2(Action a)
                : this()
            {
                this._a = a;
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                if (_a != null)
                {
                    _a();
                }
            }
        }
    }
  • 相关阅读:
    彻底理解cookie,session,token
    IP 别名和辅助 IP 地址
    1 构建Mysql+heartbeat+DRBD+LVS集群应用系统系列之DRBD的搭建
    centos配置DNS和ip
    centos的安装和下载
    activemq的学习
    mongodb的分片
    MongoDB的安装
    分布式事务中的三种解决方案详解(转载)
    redis中redis.conf配置文件解析
  • 原文地址:https://www.cnblogs.com/Jacklovely/p/7887298.html
Copyright © 2020-2023  润新知