ERLEDIGT
JA
JA
ANTWORTEN
8
8
ZUGRIFFE
307
307
EMPFEHLEN
-
Hi,
ich habe folgendes Inputboxprogramm(Kritik erwünscht) geschrieben, aber wenn ich aus einem anderen Projekt auf den Namespace Input verweise wird mir angezeigt, das dieser nicht existiert. Was hab ich falsch gemacht?
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Input { public enum States { OK, Abort, Error, } class InputBox : Form { public static States Status; public static string Output; public InputBox(string Name, string Text) { InitializeComponent(); this.Text = Name; lblText.Text = Text; } public static void Shows(string Name, string Text) { InputBox Box = new InputBox(Name,Text); Box.ShowDialog(); } private void btnOK_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(txtInput.Text)) { Status = States.OK; Output = txtInput.Text; } else Status = States.Abort; this.Close(); } private void btnAbort_Click(object sender, EventArgs e) { Status = States.Abort; this.Close(); } /// <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.lblText = new System.Windows.Forms.Label(); this.btnOK = new System.Windows.Forms.Button(); this.btnAbort = new System.Windows.Forms.Button(); this.txtInput = new System.Windows.Forms.TextBox(); this.SuspendLayout(); // // lblText // this.lblText.AutoSize = true; this.lblText.Location = new System.Drawing.Point(9, 15); this.lblText.Name = "lblText"; this.lblText.Size = new System.Drawing.Size(46, 13); this.lblText.TabIndex = 0; this.lblText.Text = "Ein Text"; // // btnOK // this.btnOK.Location = new System.Drawing.Point(248, 15); this.btnOK.Name = "btnOK"; this.btnOK.Size = new System.Drawing.Size(75, 23); this.btnOK.TabIndex = 1; this.btnOK.Text = "OK"; this.btnOK.UseVisualStyleBackColor = true; this.btnOK.Click += new System.EventHandler(this.btnOK_Click); // // btnAbort // this.btnAbort.Location = new System.Drawing.Point(248, 44); this.btnAbort.Name = "btnAbort"; this.btnAbort.Size = new System.Drawing.Size(75, 23); this.btnAbort.TabIndex = 2; this.btnAbort.Text = "Abbrechen"; this.btnAbort.UseVisualStyleBackColor = true; this.btnAbort.Click += new System.EventHandler(this.btnAbort_Click); // // txtInput // this.txtInput.Location = new System.Drawing.Point(12, 90); this.txtInput.Name = "txtInput"; this.txtInput.Size = new System.Drawing.Size(314, 20); this.txtInput.TabIndex = 3; // // FrmBox // this.AcceptButton = this.btnOK; this.ClientSize = new System.Drawing.Size(338, 122); this.Controls.Add(this.txtInput); this.Controls.Add(this.btnAbort); this.Controls.Add(this.btnOK); this.Controls.Add(this.lblText); this.Name = "FrmBox"; this.ResumeLayout(false); this.PerformLayout(); } #endregion private System.Windows.Forms.Label lblText; private System.Windows.Forms.Button btnOK; private System.Windows.Forms.Button btnAbort; private System.Windows.Forms.TextBox txtInput; } }
Gruß Didi
-
03.02.10 10:58 #2
Mal doof gefragt, hast du den auch die Referenzen im anderen Projekt gesetzt?
Internetseite:
http://www.texturenland.de
Blog:
http://blog.texturenland.de
Codesnippets:
.NET-Snippets
- Sollte ich bei einer Frage weitergeholfen haben, würde ich mich über eine positive Bewertung freuen -
-
Wie meinst du das?
Wenn ich in einem anderen Projekt Input.Inputbox angebe sagt der mir, dass der Namespace nicht existiert.
Gibt es da irgendwas, was ich nicht weis?
-
03.02.10 15:10 #4
Also wenn du von Projekten redest, denke ich an eigenständige Projekte in Visual Studio bzw. #Develop. Zum Beispiel:
Dein erstes Projekt ist eine Windows Forms Anwendung, dein zweites Projekt eine Klassenbibliothek, in dem zweiten Projekt ist jetzt deine InputBox eingebaut, damit das erste Projekt etwas von dem zweiten Projekt weiß, musst du es dem ersten Projekt referenzieren.
Es gibt einen Punkt der heißt Referenzen in deinem Projekt, dort fügst du eine neue Referenz hinzu in diesem Fall dein zweites Projekt und schon weiß dein erstes Projekt über dein zweites Projekt bescheid.Internetseite:
http://www.texturenland.de
Blog:
http://blog.texturenland.de
Codesnippets:
.NET-Snippets
- Sollte ich bei einer Frage weitergeholfen haben, würde ich mich über eine positive Bewertung freuen -
-
du meinst die using zeilen oben?
-
Nein die meint er nicht. Er meint die Referenzen.
Das Using-Keyword erspart dir nur Tipparbeit, du kannst das Using auch komplett weglassen, musst dann jedesmal aber den vollständigen Namen hinschreiben. Siehe hier: C#: Using Keyword
Aus
würde dannCode csharp:1
class InputBox : Form
werden, wenn du using weglässt.Code csharp:1
class InputBox : System.Windows.Forms.Form
hihi = -h²
-
nein, die habe ich natürlich nicht vergessen, aber als ich versucht habe die InputBox zu benutzen musste ich sie in das selbe Projekt verschieben, in dem ich sie auch benutzen wollte.
-
Vielleicht stimmt die Build-Reihenfolge noch nicht. Du musst bei deinem Hauptprojekt einstellen, dass es von dem InputBox-Projekt abhängt (d.h. es muss erst die InputBox kompiliert werden bevor das Hauptprojekt erstellt werden kann.).
hihi = -h²
-
Hat sich erledigt.
Ich hatte vergessen InputBox public zu machen.
Trozdem Danke
Gruß Didi





Zitieren
Login





