我還沒有做很多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