首页 > Windows开发 > 详细

C# 下使用委托跨窗体调用函数和控件的实现

时间:2014-03-28 18:04:16      阅读:487      评论:0      收藏:0      [点我收藏+]

form1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 跨窗体调用函数
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 f = new Form2();
            f.ChangeColor += new Form2.ChangeFormColor(f_ChangeColor);
            f.Show();  
        }
        void f_ChangeColor(bool topmost)
        {
            this.BackColor = Color.LightBlue;
            this.Text = "改变成功";
        }  
    }
}



form2

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 跨窗体调用函数
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        public delegate void ChangeFormColor(bool topmost);  
        private void Form2_Load(object sender, EventArgs e)
        {

        }
        public event ChangeFormColor ChangeColor;
        private void button1_Click(object sender, EventArgs e)
        {
            ChangeColor(true);//执行委托实例  
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            ChangeColor(true);
        }  
    }
}


C# 下使用委托跨窗体调用函数和控件的实现,布布扣,bubuko.com

C# 下使用委托跨窗体调用函数和控件的实现

原文:http://blog.csdn.net/energeticsunxiaocong/article/details/22376625

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!