我还没有做很多C#编程。不过,我非常擅长C/C++。我找不到从项目中的其他类访问类成员的正确方法。例如,我有一个类addChannel(),它是一个弹出框,允许用户输入Channel类的信息。我有一个树形视图,可以容纳这些频道。 TreeView是一个ListView类,它是树中的主要形式。我在addChannel弹出窗口中有一个按钮,单击它时应添加一个新的Channel()并将此通道作为新节点添加到树中。但是我根本无法访问树,也不知道如何。这里有一些相关的代码。访问C#Windows中的其他类窗体
namespace RSSReader
{
public partial class addChannel : Form
{
public addChannel()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
// Save the info to an XML doc
// I want to access the channelTree treeView here
this.Close();
}
}
}
这里是设计师
namespace RSSReader
{
partial class ListView
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
// ALL THE INITIALIZATION IS HERE... I excluded it
public System.Windows.Forms.TreeView channelTree;
private System.Windows.Forms.WebBrowser webBrowser;
private System.Windows.Forms.Button addBtn;
private System.Windows.Forms.Button setBtn;
private System.Windows.Forms.Button remBtn;
private System.Windows.Forms.RadioButton titleFilter;
private System.Windows.Forms.RadioButton dateFilter;
}
}
但我的treeView并没有分开addChannel类.. addChannel只是一个简单的弹出窗体来获得标题和描述。我不想在addChannel中创建一个新的TreeView,因为我已经在我的ListView中有一个了。 – 2013-03-18 01:39:03
我像你说的那样将treeView和Add按钮拖放到我的ListView上。但是addChannel是一个新的Class,当点击Add按钮时它弹出 – 2013-03-18 01:41:34