Piksou | Ce post va sans doute poser une question ridicule mais je suis un débutant en objet et en .net donc je supplie l'assistance de bien vouloir être indulgente Je tente de faire une appli tout con avec une Fenêtre (Form1) et une classe abstract (Feed) donc héritent 3 classes: MusicFeed, TalkFeed et VideoFeed. Depuis une méthode de MusicFeed (et des autres par la suite) je voudrais modifier le contenu Text de certains controles, en l'espèce, des System.Windows.Forms.TextBox et des System.Windows.Forms.ComboBox. Problème: par défaut ces contrôles étaient des membres private de Form1 j'ai donc modifié la propriété Modifiers en public (internal devrait suffire mais bon). Dans le Form1.Designer.cs, on trouve désormais: Code :
- namespace Podcast1
- {
- partial class Form1
- {
- /// <summary>
- /// Variable nécessaire au concepteur.
- /// </summary>
- private System.ComponentModel.IContainer components = null;
- /// <summary>
- /// Nettoyage des ressources utilisées.
- /// </summary>
- /// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
- #region Code généré par le Concepteur Windows Form
- /// <summary>
- /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
- /// le contenu de cette méthode avec l'éditeur de code.
- /// </summary>
- private void InitializeComponent()
- {
- this.listeFlux = new System.Windows.Forms.ListBox();
- this.inputUrl = new System.Windows.Forms.TextBox();
- this.btnAdd = new System.Windows.Forms.Button();
- this.btnDel = new System.Windows.Forms.Button();
- this.btnSave = new System.Windows.Forms.Button();
- this.grpList = new System.Windows.Forms.GroupBox();
- this.grpPodcast = new System.Windows.Forms.GroupBox();
- this.inputGenre = new System.Windows.Forms.ComboBox();
- this.label4 = new System.Windows.Forms.Label();
- this.inputType = new System.Windows.Forms.ComboBox();
- this.label3 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label1 = new System.Windows.Forms.Label();
- this.inputName = new System.Windows.Forms.TextBox();
- this.grpList.SuspendLayout();
- this.grpPodcast.SuspendLayout();
- this.SuspendLayout();
- //
- // listeFlux
- //
- this.listeFlux.FormattingEnabled = true;
- this.listeFlux.Location = new System.Drawing.Point(7, 20);
- this.listeFlux.Name = "listeFlux";
- this.listeFlux.Size = new System.Drawing.Size(598, 264);
- this.listeFlux.Sorted = true;
- this.listeFlux.TabIndex = 0;
- this.listeFlux.SelectedValueChanged += new System.EventHandler(this.listeFlux_SelectedValueChanged);
- //
- // inputUrl
- //
- this.inputUrl.Location = new System.Drawing.Point(42, 20);
- this.inputUrl.Name = "inputUrl";
- this.inputUrl.Size = new System.Drawing.Size(567, 21);
- this.inputUrl.TabIndex = 1;
- //
- // btnAdd
- //
- this.btnAdd.Location = new System.Drawing.Point(615, 19);
- this.btnAdd.Name = "btnAdd";
- this.btnAdd.Size = new System.Drawing.Size(59, 21);
- this.btnAdd.TabIndex = 2;
- this.btnAdd.Text = "&Add";
- this.btnAdd.UseVisualStyleBackColor = true;
- this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
- //
- // btnDel
- //
- this.btnDel.Location = new System.Drawing.Point(615, 46);
- this.btnDel.Name = "btnDel";
- this.btnDel.Size = new System.Drawing.Size(59, 21);
- this.btnDel.TabIndex = 3;
- this.btnDel.Text = "&Delete";
- this.btnDel.UseVisualStyleBackColor = true;
- this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
- //
- // btnSave
- //
- this.btnSave.Location = new System.Drawing.Point(611, 20);
- this.btnSave.Name = "btnSave";
- this.btnSave.Size = new System.Drawing.Size(59, 21);
- this.btnSave.TabIndex = 4;
- this.btnSave.Text = "&Save";
- this.btnSave.UseVisualStyleBackColor = true;
- this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
- //
- // grpList
- //
- this.grpList.Controls.Add(this.btnSave);
- this.grpList.Controls.Add(this.listeFlux);
- this.grpList.Location = new System.Drawing.Point(5, 5);
- this.grpList.Name = "grpList";
- this.grpList.Size = new System.Drawing.Size(677, 288);
- this.grpList.TabIndex = 5;
- this.grpList.TabStop = false;
- this.grpList.Text = "List";
- //
- // grpPodcast
- //
- this.grpPodcast.Controls.Add(this.inputGenre);
- this.grpPodcast.Controls.Add(this.label4);
- this.grpPodcast.Controls.Add(this.inputType);
- this.grpPodcast.Controls.Add(this.label3);
- this.grpPodcast.Controls.Add(this.label2);
- this.grpPodcast.Controls.Add(this.label1);
- this.grpPodcast.Controls.Add(this.inputName);
- this.grpPodcast.Controls.Add(this.inputUrl);
- this.grpPodcast.Controls.Add(this.btnDel);
- this.grpPodcast.Controls.Add(this.btnAdd);
- this.grpPodcast.Location = new System.Drawing.Point(5, 299);
- this.grpPodcast.Name = "grpPodcast";
- this.grpPodcast.Size = new System.Drawing.Size(676, 113);
- this.grpPodcast.TabIndex = 6;
- this.grpPodcast.TabStop = false;
- this.grpPodcast.Text = "Podcast";
- //
- // inputGenre
- //
- this.inputGenre.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.inputGenre.FormattingEnabled = true;
- this.inputGenre.Items.AddRange(new object[] {
- "(N/A)",
- "Bues",
- "Country",
- "Disco",
- "Dance",
- "Funk",
- "Hip Hop",
- "Jazz",
- "Pop",
- "R&B",
- "Reggae",
- "Rock",
- "Techno"});
- this.inputGenre.Location = new System.Drawing.Point(53, 74);
- this.inputGenre.MaxDropDownItems = 13;
- this.inputGenre.Name = "inputGenre";
- this.inputGenre.Size = new System.Drawing.Size(96, 21);
- this.inputGenre.TabIndex = 9;
- //
- // label4
- //
- this.label4.AutoSize = true;
- this.label4.Location = new System.Drawing.Point(7, 77);
- this.label4.Name = "label4";
- this.label4.Size = new System.Drawing.Size(40, 13);
- this.label4.TabIndex = 8;
- this.label4.Text = "Genre:";
- //
- // inputType
- //
- this.inputType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.inputType.FormattingEnabled = true;
- this.inputType.Items.AddRange(new object[] {
- "Music",
- "Talk",
- "Video"});
- this.inputType.Location = new System.Drawing.Point(510, 47);
- this.inputType.MaxDropDownItems = 3;
- this.inputType.Name = "inputType";
- this.inputType.Size = new System.Drawing.Size(99, 21);
- this.inputType.TabIndex = 7;
- this.inputType.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.inputType_TextChanged);
- this.inputType.TextChanged += new System.EventHandler(this.inputType_TextChanged);
- //
- // label3
- //
- this.label3.AutoSize = true;
- this.label3.Location = new System.Drawing.Point(469, 50);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(35, 13);
- this.label3.TabIndex = 6;
- this.label3.Text = "Type:";
- //
- // label2
- //
- this.label2.AutoSize = true;
- this.label2.Location = new System.Drawing.Point(7, 50);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(38, 13);
- this.label2.TabIndex = 5;
- this.label2.Text = "Name:";
- //
- // label1
- //
- this.label1.AutoSize = true;
- this.label1.Location = new System.Drawing.Point(6, 24);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(30, 13);
- this.label1.TabIndex = 4;
- this.label1.Text = "URL:";
- //
- // inputName
- //
- this.inputName.Location = new System.Drawing.Point(50, 47);
- this.inputName.Name = "inputName";
- this.inputName.Size = new System.Drawing.Size(413, 21);
- this.inputName.TabIndex = 1;
- //
- // Form1
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.AutoSize = true;
- this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
- this.ClientSize = new System.Drawing.Size(685, 418);
- this.Controls.Add(this.grpPodcast);
- this.Controls.Add(this.grpList);
- this.MaximizeBox = false;
- this.Name = "Form1";
- this.Text = "Podcast Project";
- this.Load += new System.EventHandler(this.Form1_Load);
- this.grpList.ResumeLayout(false);
- this.grpPodcast.ResumeLayout(false);
- this.grpPodcast.PerformLayout();
- this.ResumeLayout(false);
- }
- #endregion
- private System.Windows.Forms.ListBox listeFlux;
- private System.Windows.Forms.Button btnAdd;
- private System.Windows.Forms.Button btnDel;
- private System.Windows.Forms.Button btnSave;
- private System.Windows.Forms.GroupBox grpList;
- private System.Windows.Forms.GroupBox grpPodcast;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label3;
- private System.Windows.Forms.Label label4;
- public System.Windows.Forms.TextBox inputUrl;
- public System.Windows.Forms.ComboBox inputType;
- public System.Windows.Forms.TextBox inputName;
- public System.Windows.Forms.ComboBox inputGenre;
- }
- }
|
Les quatre dernières lignes sont a priori OK. Dans Form1.cs, j'ai tapé:
Code :
- /// <summary>
- /// Basic class for any kind of feed
- /// </summary>
- public abstract class Feed
- {
- protected string url;
- protected string name;
- public string Name
- {
- get
- {
- return name;
- }
- set
- {
- name = value;
- }
- }
- public string Url
- {
- get
- {
- return url;
- }
- set
- {
- url = value;
- }
- }
- public abstract void Load();
- }
- public class MusicFeed : Feed
- {
- string genre;
- public string Genre
- {
- get
- {
- return genre;
- }
- set
- {
- genre = value;
- }
- }
- public MusicFeed(string inName, string inUrl, string inGenre)
- {
- name = inName;
- url = inUrl;
- genre = inGenre;
- }
- public override void Load()
- {
- Form1.inputName.Text = name;
- }
- }
|
Sauf que non, il semble que VS ne voit pas de memebre inputName à Form1: Intellisense ne le propose pas et le compilateur génère une erreur "Erreur 2 Une référence d'objet est requise pour la propriété, la méthode ou le champ non statique 'Podcast1.Form1.inputName' " (Podcast1 est le namespace qui contient tout). Quelqu'un ici aurait une piste ? Message édité par Piksou le 26-11-2006 à 18:11:55 ---------------
« Le verbe "aimer" est le plus compliqué de la langue. Son passé n'est jamais simple, son présent n'est qu'imparfait et son futur toujours conditionnel. » Jean Cocteau
|