本文介绍了如何将数据从事件传递到其他形式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我创建了一个"UserControl"库,该库具有一些接口按钮,每个按钮都包含一些作为属性的数据,并且所有按钮都使用一个事件,有人认为它显示消息框内容是存储的数据在界面按钮中.

现在,我想将此数据从"Usercontrol"传递到在其上运行"UserControl"的主应用程序.

我该怎么做?

接口按钮代码:

Hi guys

I create a "UserControl" library that''s have some interfaced buttons each button content some data as propertys and all buttons use one event that''s do one think it''s show message box content the data that''s stored in interfaced buttons.

Now i want to passing this data from "Usercontrol" to Main application that''s "UserControl" run on it.

How could i do this ??

Interfaced button code:

public class IButtons : System.Windows.Forms.Button
{

    #region Private data memory

    private Guid _Id;
    private Product_data _iproduct;

    #endregion

    private Size defualt_Bsize = new Size(156, 68); //Defualt button size

    public Guid Button_id { get { return _Id; } set { _Id = value; } }

    public Product_data IProduct { get { return _iproduct; } set { _iproduct = value; } }

    public IButtons(Guid Id, Color Button_color, Size Button_size, Product_data Product)
    {
        //Set button Text property as the product name
        this.Text = Product.Name;

        //Button color
        Color color = Button_color;
        if (color == null || color.IsEmpty)
            this.BackColor = Color.FromName("Control");
        else
            this.BackColor = color;

        //Button size
        Size b_size = Button_size;
        if (b_size == null || b_size.IsEmpty)
            this.Size = defualt_Bsize;
        else
            this.Size = b_size;

        //Button Id
        if (Id == null || Id == Guid.Empty)
            _Id = Guid.NewGuid();
        else
            _Id = Id;

        _iproduct = Product; //Load product to private memory

        this.FlatStyle = System.Windows.Forms.FlatStyle.Flat; //Convert button style from standard to flat

        this.Click += new EventHandler(ClickOnButton_event); //Load click event to button
    }

    private void ClickOnButton_event(object sender, EventArgs e)
    {
        System.Windows.Forms.MessageBox.Show(string.Format("Produt Id {0} / Name {1} / Retail Price {2}", _iproduct.Id, _iproduct.Name, _iproduct.Price));
    }

    private void InitializeComponent()
    {
        this.SuspendLayout();
        this.ResumeLayout(false);
    }

}



我想用传递数据的代码替换下面的代码



I want to replace the code below with passing data code

System.Windows.Forms.MessageBox.Show(string.Format("Produt Id {0} / Name {1} / Retail Price {2}", _iproduct.Id, _iproduct.Name, _iproduct.Price));

推荐答案




这篇关于如何将数据从事件传递到其他形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 12:39