Dockpanel Suite并通过多种形式传递数据 [英] Dockpanel Suite and passing data across multiple forms

查看:192
本文介绍了Dockpanel Suite并通过多种形式传递数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我找不到任何引用我正在寻找的东西。我曾在两种形式之间传递数据的站点上看到很多示例,如

如何将值从一个表单传递到另一个表单?
使用一种形式的控制到另一个



开启/关闭如何访问继承表单上的控件?



所以基本上这里是我试图完成
的行为使用DockPanel Suite



$ hr
$ b $主表格 parentForm
有一个表格 Form1 停靠在里面,总是在那里。无法删除或重新加载是不变的(因此应始终是我假设的相同实例),它具有文本框 frm1Box
parentForm 有一个菜单栏,其中包含一个按钮 button1 ,它将打开第三个窗体 Form2 ,它也有一个文本框 frm2Box 。我希望能够点击 button1 (从 parentForm )打开 Form2 并将 frm1Box 中的所有内容传递给 frm2Box






所以从阅读来看,似乎设置属性是每个人都推荐的,所以这就是我所做的,如果我只是通过按钮单击在form1上打开form2并传递数据,但我似乎无法在添加其他表单时弄清楚。这显然不是我的完整代码我会很高兴发布我的实际代码,如果需要的只是没有节省空间。

  // Parent Form 
public partial class parentForm:Form

public static Form1 form1 = new Form1();

public void showForm1()
{
form1 = new Form1();
form1.Show(dockPanel1,DockState.DockLeft);

private void parentForm_Load(object sender,EventArgs e)
{
showForm1();

private void button1_Click(object sender,EventArgs e)
{
Form2 form2 = new Form2();
form2.CustNameCb = form1.CustName;
form2.Show();
}



// Form1
public partial class Form1:DockContent
{
private string _custName;

public Form2()
{
InitializeComponent();


public string CustName
{
get
{
return _custName;
}
set
{
_custName = value;
frm1Box.Text = _custName;
}

}


// Form2
public partial class Form2:Form
{
private string _custNameCb;

public Form2()
{
InitializeComponent();


公共字符串CustNameCb
{
获得
{
return _custNameCb;
}
set
{
_custNameCb = value;
frm2Box.Text = _custNameCb;
}

}

我想我错过了这个概念但我在搜索中找不到这个好例子,或者我至少可以找到一个例子。我对编程和C#都很陌生,所以请原谅我的缺乏经验。如果任何人有更好的方式做到这一点,请让我知道。我曾考虑过使用SQL来存储数据。如果可能的话,我不希望使用基于文件的存储。另外值得注意的是,一旦我找到正确的方法,它将需要可扩展性,因为当我实际上实现它时,它将在parentForm上打开5个不同窗体的5个不同按钮,但仍然从同一个Form1中提取数据form1将有大约10个数据文本框。



感谢您提供任何回复。

解决方案

你很亲密。在您的属性中,setter显示文本框中传递的值,但getter如何从TextBox中检索值?它只返回存储在私有变量中的值。对于Form1,你是否设置了私有变量_custName(现在显示)通过代码(如通过TextChanged()事件也许)?

如果不是,更改Property to:

  public string CustName 
{
get
{
return frm1Box.Text;
}
set
{
frm1Box.Text = value;






$ b

这将返回实际在文本框中的值并希望将其纳入第二种形式......


Hi I couldn't find anything that referenced exactly what I was looking for. I have seen many examples on sites of passing data between two forms such as

How can I pass values from one form to another? Using The Controls Of One Form Into Another How to access controls on an inherited form?

On top of several blogs and hours of reading and not getting it.

So basically here is the act I am trying to accomplish Using DockPanel Suite


Main Form parentForm Has a form Form1 docked inside that is always there. Cannot be removed or reloaded is constant(so should always be same instance I would assume) that has a textboxfrm1Box. parentForm has a menu bar with a button button1 which will open a third form Form2 that also has a textbox frm2Box. I would like to be able to click button1(From the parentForm) have it open Form2 and pass whatever is in frm1Box to frm2Box.


So from reading it seemed like setting up properties was what everyone recommended so that is what I did and it works great if I just do it from a button click on form1 to open form2 and pass the data but I cant seem to figure it out when adding another form. This is obviously not my full code I will be happy to post my actual code if it is needed just didnt to save space.

//Parent Form
public partial class parentForm : Form

public static Form1 form1 = new Form1();

public void showForm1()
    {
        form1 = new Form1();
        form1.Show(dockPanel1, DockState.DockLeft);
    }
private void parentForm_Load(object sender, EventArgs e)
    {
        showForm1();
    }
private void button1_Click(object sender, EventArgs e)
    {
        Form2 form2 = new Form2();
        form2.CustNameCb = form1.CustName;
        form2.Show();
    }



//Form1
public partial class Form1 : DockContent
   {
private string _custName;

public Form2()
    {
        InitializeComponent();

    }
public string CustName
    {
        get
        {
            return _custName;
        }
        set
        {
            _custName = value;
            frm1Box.Text = _custName;
        }

    }


//Form2
public partial class Form2 : Form
   {
private string _custNameCb;

public Form2()
    {
        InitializeComponent();

    }
public string CustNameCb
    {
        get
        {
            return _custNameCb;
        }
        set
        {
            _custNameCb = value;
            frm2Box.Text = _custNameCb;
        }

    }

I think I am missing this concept altogether but I couldn't find a "good" example of this in my searches or at least one I could follow. I am new to programming and C# in particular so please forgive my inexperience. If anyone has a better way of doing this please let me know. I have considered using SQL to store the data. I would prefer not to use a file based storage if possible. Also it is worth noting once I find the proper method of doing this it will need to be scale-able because when I actually implement this it will be 5 different buttons on parentForm opening 5 different form's but all still pulling data from that same Form1 yet form1 will have around 10 textboxes of data to pull.

Thanks in advance for any replies.

解决方案

You're so close. In your Properties, the "setter" is displaying the passed value in the TextBox, but how is the "getter" retrieving the value from the TextBox? It is only returning the value stored in the private variable. For Form1, are you setting the private variable "_custName" somehow (now shown) thru code (like thru the TextChanged() event maybe)?

If not, change the Property to:

public string CustName
{
    get
    {
        return frm1Box.Text;
    }
    set
    {
        frm1Box.Text = value;
    }
}

This will return the value that is actually in the TextBox and hopefully get it into your second form...

这篇关于Dockpanel Suite并通过多种形式传递数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆