我还没有做过很多 C# 编程。不过,我非常擅长 C/C++。我无法弄清楚从项目中的其他类访问类成员的正确方法。例如,我有一个 addChannel() 类,它是一个弹出框,允许用户输入 Channel 类的信息。我有一个可以保存这些频道的 treeView。treeView 位于 ListView 类中,该类是其中包含树的主要形式。我在 addChannel 弹出窗口上有一个按钮,单击该按钮应添加一个新 Channel() 并将此通道作为新节点添加到树中。但是我根本无法访问树,也不知道如何访问。这是一些相关的代码。
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();
}
}
}
这是设计器的 ListView 部分类
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;
}
}