dcAlge
2010-07-03, 00:26:05
Hey Leute,
folgende Situation:
-ich habe zwei Forms
-ein Instanz der Klasse WiimoteCollection (in der Main instanziert), die ich als Argument dem Konstruktor der Forms übergebe (das klappt auch ganz gut)
-jetzt möchte ich in eines der Forms eine UserControl einbauen, der diese Instanz dann weitergereicht wird (auch wieder als Argument im Konstruktor)
-dabei aber kommt es zu den Warnungen:
1: Warnung 1 Die Variable wc wurde nicht deklariert oder nicht zugeordnet.
2: Warnung 2 Die Variable wCollectionInfo1 wurde nicht deklariert oder nicht zugeordnet. C:\Users\Marco\Documents\Visual Studio 2010\Projects\enrich002\enrich002\FMoteInformationen.Designer.cs 58 0
bei der Ausführung gibt es eine NullReferenceException an der Stelle "wc.FindAllWiimotes();" beim Klicken des Button1 in der UCwCollectionInfo
Hier ein paar Codeschnipsel:
namespace enrich002
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
WiimoteCollection wc = new WiimoteCollection();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FMoteInformationen(wc));
Application.Run(new FKonfiguration(wc));
}
}
}
namespace enrich002
{
public partial class FMoteInformationen : Form
{
private WiimoteCollection wc;
public FMoteInformationen()
{
InitializeComponent();
}
public FMoteInformationen(WiimoteCollection arg)
{
InitializeComponent();
wc = arg;
}
}
}
partial class FMoteInformationen
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.wCollectionInfo1 = new enrich002.UCwCollectionInfo(wc);
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// wCollectionInfo1
//
this.wCollectionInfo1.Location = new System.Drawing.Point(13, 43);
this.wCollectionInfo1.Name = "wCollectionInfo1";
this.wCollectionInfo1.Size = new System.Drawing.Size(596, 515);
this.wCollectionInfo1.TabIndex = 1;
//
// MoteInformationen
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(645, 622);
this.Controls.Add(this.wCollectionInfo1);
this.Controls.Add(this.button1);
this.Name = "MoteInformationen";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private UCwCollectionInfo wCollectionInfo1;
}
namespace enrich002
{
public partial class UCwCollectionInfo : UserControl
{
private WiimoteCollection wc;
public UCwCollectionInfo()
{
InitializeComponent();
}
public UCwCollectionInfo(WiimoteCollection arg)
{
InitializeComponent();
wc = arg;
}
private void button1_Click(object sender, EventArgs e)
{
wc.FindAllWiimotes();
}
}
}
partial class UCwCollectionInfo
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Komponenten-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(4, 4);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(458, 108);
this.listBox1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(469, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(469, 34);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(4, 119);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(458, 380);
this.tabControl1.TabIndex = 3;
//
// tabPage1
//
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(450, 354);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(450, 354);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// wCollectionInfo
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox1);
this.Name = "wCollectionInfo";
this.Size = new System.Drawing.Size(596, 515);
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
}
}
Meine Idee war halt die Klasse WiimoteCollection einmal in Main() zu instanzieren und dann an die Forms weiterzureichen und damit zu arbeiten...
Mach ich grundsätzlich was falsch? Ist mein Aufbau eine Sackgasse?! Bin noch Frischling was Programmieren und speziell in C#.NET angeht...
Würde mich über jeden Tipp freuen! :)
Vielen Dank,
dcAlge
P.S.: Benutze übrigens VS 2010 Express, falls das irgendwie wichtig ist.
folgende Situation:
-ich habe zwei Forms
-ein Instanz der Klasse WiimoteCollection (in der Main instanziert), die ich als Argument dem Konstruktor der Forms übergebe (das klappt auch ganz gut)
-jetzt möchte ich in eines der Forms eine UserControl einbauen, der diese Instanz dann weitergereicht wird (auch wieder als Argument im Konstruktor)
-dabei aber kommt es zu den Warnungen:
1: Warnung 1 Die Variable wc wurde nicht deklariert oder nicht zugeordnet.
2: Warnung 2 Die Variable wCollectionInfo1 wurde nicht deklariert oder nicht zugeordnet. C:\Users\Marco\Documents\Visual Studio 2010\Projects\enrich002\enrich002\FMoteInformationen.Designer.cs 58 0
bei der Ausführung gibt es eine NullReferenceException an der Stelle "wc.FindAllWiimotes();" beim Klicken des Button1 in der UCwCollectionInfo
Hier ein paar Codeschnipsel:
namespace enrich002
{
static class Program
{
/// <summary>
/// Der Haupteinstiegspunkt für die Anwendung.
/// </summary>
[STAThread]
static void Main()
{
WiimoteCollection wc = new WiimoteCollection();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new FMoteInformationen(wc));
Application.Run(new FKonfiguration(wc));
}
}
}
namespace enrich002
{
public partial class FMoteInformationen : Form
{
private WiimoteCollection wc;
public FMoteInformationen()
{
InitializeComponent();
}
public FMoteInformationen(WiimoteCollection arg)
{
InitializeComponent();
wc = arg;
}
}
}
partial class FMoteInformationen
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Windows Form-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.wCollectionInfo1 = new enrich002.UCwCollectionInfo(wc);
this.SuspendLayout();
//
// button1
//
this.button1.Location = new System.Drawing.Point(13, 13);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 0;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
//
// wCollectionInfo1
//
this.wCollectionInfo1.Location = new System.Drawing.Point(13, 43);
this.wCollectionInfo1.Name = "wCollectionInfo1";
this.wCollectionInfo1.Size = new System.Drawing.Size(596, 515);
this.wCollectionInfo1.TabIndex = 1;
//
// MoteInformationen
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(645, 622);
this.Controls.Add(this.wCollectionInfo1);
this.Controls.Add(this.button1);
this.Name = "MoteInformationen";
this.Text = "Form1";
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button button1;
private UCwCollectionInfo wCollectionInfo1;
}
namespace enrich002
{
public partial class UCwCollectionInfo : UserControl
{
private WiimoteCollection wc;
public UCwCollectionInfo()
{
InitializeComponent();
}
public UCwCollectionInfo(WiimoteCollection arg)
{
InitializeComponent();
wc = arg;
}
private void button1_Click(object sender, EventArgs e)
{
wc.FindAllWiimotes();
}
}
}
partial class UCwCollectionInfo
{
/// <summary>
/// Erforderliche Designervariable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Verwendete Ressourcen bereinigen.
/// </summary>
/// <param name="disposing">True, wenn verwaltete Ressourcen gelöscht werden sollen; andernfalls False.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Vom Komponenten-Designer generierter Code
/// <summary>
/// Erforderliche Methode für die Designerunterstützung.
/// Der Inhalt der Methode darf nicht mit dem Code-Editor geändert werden.
/// </summary>
private void InitializeComponent()
{
this.listBox1 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.tabControl1 = new System.Windows.Forms.TabControl();
this.tabPage1 = new System.Windows.Forms.TabPage();
this.tabPage2 = new System.Windows.Forms.TabPage();
this.tabControl1.SuspendLayout();
this.SuspendLayout();
//
// listBox1
//
this.listBox1.FormattingEnabled = true;
this.listBox1.Location = new System.Drawing.Point(4, 4);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(458, 108);
this.listBox1.TabIndex = 0;
//
// button1
//
this.button1.Location = new System.Drawing.Point(469, 4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "button1";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(469, 34);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2;
this.button2.Text = "button2";
this.button2.UseVisualStyleBackColor = true;
//
// tabControl1
//
this.tabControl1.Controls.Add(this.tabPage1);
this.tabControl1.Controls.Add(this.tabPage2);
this.tabControl1.Location = new System.Drawing.Point(4, 119);
this.tabControl1.Name = "tabControl1";
this.tabControl1.SelectedIndex = 0;
this.tabControl1.Size = new System.Drawing.Size(458, 380);
this.tabControl1.TabIndex = 3;
//
// tabPage1
//
this.tabPage1.Location = new System.Drawing.Point(4, 22);
this.tabPage1.Name = "tabPage1";
this.tabPage1.Padding = new System.Windows.Forms.Padding(3);
this.tabPage1.Size = new System.Drawing.Size(450, 354);
this.tabPage1.TabIndex = 0;
this.tabPage1.Text = "tabPage1";
this.tabPage1.UseVisualStyleBackColor = true;
//
// tabPage2
//
this.tabPage2.Location = new System.Drawing.Point(4, 22);
this.tabPage2.Name = "tabPage2";
this.tabPage2.Padding = new System.Windows.Forms.Padding(3);
this.tabPage2.Size = new System.Drawing.Size(450, 354);
this.tabPage2.TabIndex = 1;
this.tabPage2.Text = "tabPage2";
this.tabPage2.UseVisualStyleBackColor = true;
//
// wCollectionInfo
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.tabControl1);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox1);
this.Name = "wCollectionInfo";
this.Size = new System.Drawing.Size(596, 515);
this.tabControl1.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.TabControl tabControl1;
private System.Windows.Forms.TabPage tabPage1;
private System.Windows.Forms.TabPage tabPage2;
}
}
Meine Idee war halt die Klasse WiimoteCollection einmal in Main() zu instanzieren und dann an die Forms weiterzureichen und damit zu arbeiten...
Mach ich grundsätzlich was falsch? Ist mein Aufbau eine Sackgasse?! Bin noch Frischling was Programmieren und speziell in C#.NET angeht...
Würde mich über jeden Tipp freuen! :)
Vielen Dank,
dcAlge
P.S.: Benutze übrigens VS 2010 Express, falls das irgendwie wichtig ist.