日期:2014-05-17  浏览次数:20854 次

可不可以给“ChildWindow”传入参数?
可不可以给“ChildWindow”传入参数???

private void SiPingRuiAn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  {
  GisChartWindow gischartwindow = new GisChartWindow();
  gischartwindow.Show();
  }

问题:“ChildWindow”在执行“Show”时,我们可否对其传入参数???

------解决方案--------------------
GisChartWindow 中public一些属性,然后就 gischartwindow.xxx访问
------解决方案--------------------
GisChartWindow子窗口中设置属性,例如:
C# code

namespace Test
{
    public partial class ShowValue : Form
    {
        public int nID = 0;
        public ShowValue()
        {
            InitializeComponent();
            MessageBox.Show(nID.ToString());
        }
    }
}

------解决方案--------------------
GisChartWindow子窗口中设置属性,例如:
C# code

namespace Test
{
    public partial class GisChartWindow : Form
    {
        public int nID = 0;
        public ShowValue()
        {
            InitializeComponent();
            MessageBox.Show(nID.ToString());
        }
    }
}

------解决方案--------------------
2次都搞错了,把ShowValue改成GisChartWindow就行
------解决方案--------------------
private void SiPingRuiAn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
GisChartWindow gischartwindow = new GisChartWindow("A楼", "B001");
gischartwindow.Show();
}

public GisChartWindow(string title, string tag)
{
InitializeComponent();
string str1 = title;
string str2 = tag;
}
------解决方案--------------------
构造函数里加。
------解决方案--------------------
在子窗口Load方法里进行赋值不就好了
1、赋值
C# code

private void SiPingRuiAn_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
    GisChartWindow gischartwindow = new GisChartWindow();
    gischartwindow.strParam1 = "A楼";
    gischartwindow.strParam2 = "B001";
    gischartwindow.Show();
}