Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
667 connectés 

  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [C# / .Net 2.0] Accès à des Winforms (sans doute trivial mais...)

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

[C# / .Net 2.0] Accès à des Winforms (sans doute trivial mais...)

n°1481958
Piksou
Posté le 26-11-2006 à 18:11:25  profilanswer
 

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  :o

 

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 :
  1. namespace Podcast1
  2. {
  3.     partial class Form1
  4.     {
  5.         /// <summary>
  6.         /// Variable nécessaire au concepteur.
  7.         /// </summary>
  8.         private System.ComponentModel.IContainer components = null;
  9.         /// <summary>
  10.         /// Nettoyage des ressources utilisées.
  11.         /// </summary>
  12.         /// <param name="disposing">true si les ressources managées doivent être supprimées ; sinon, false.</param>
  13.         protected override void Dispose(bool disposing)
  14.         {
  15.             if (disposing && (components != null))
  16.             {
  17.                 components.Dispose();
  18.             }
  19.             base.Dispose(disposing);
  20.         }
  21.         #region Code généré par le Concepteur Windows Form
  22.         /// <summary>
  23.         /// Méthode requise pour la prise en charge du concepteur - ne modifiez pas
  24.         /// le contenu de cette méthode avec l'éditeur de code.
  25.         /// </summary>
  26.         private void InitializeComponent()
  27.         {
  28.             this.listeFlux = new System.Windows.Forms.ListBox();
  29.             this.inputUrl = new System.Windows.Forms.TextBox();
  30.             this.btnAdd = new System.Windows.Forms.Button();
  31.             this.btnDel = new System.Windows.Forms.Button();
  32.             this.btnSave = new System.Windows.Forms.Button();
  33.             this.grpList = new System.Windows.Forms.GroupBox();
  34.             this.grpPodcast = new System.Windows.Forms.GroupBox();
  35.             this.inputGenre = new System.Windows.Forms.ComboBox();
  36.             this.label4 = new System.Windows.Forms.Label();
  37.             this.inputType = new System.Windows.Forms.ComboBox();
  38.             this.label3 = new System.Windows.Forms.Label();
  39.             this.label2 = new System.Windows.Forms.Label();
  40.             this.label1 = new System.Windows.Forms.Label();
  41.             this.inputName = new System.Windows.Forms.TextBox();
  42.             this.grpList.SuspendLayout();
  43.             this.grpPodcast.SuspendLayout();
  44.             this.SuspendLayout();
  45.             //
  46.             // listeFlux
  47.             //
  48.             this.listeFlux.FormattingEnabled = true;
  49.             this.listeFlux.Location = new System.Drawing.Point(7, 20);
  50.             this.listeFlux.Name = "listeFlux";
  51.             this.listeFlux.Size = new System.Drawing.Size(598, 264);
  52.             this.listeFlux.Sorted = true;
  53.             this.listeFlux.TabIndex = 0;
  54.             this.listeFlux.SelectedValueChanged += new System.EventHandler(this.listeFlux_SelectedValueChanged);
  55.             //
  56.             // inputUrl
  57.             //
  58.             this.inputUrl.Location = new System.Drawing.Point(42, 20);
  59.             this.inputUrl.Name = "inputUrl";
  60.             this.inputUrl.Size = new System.Drawing.Size(567, 21);
  61.             this.inputUrl.TabIndex = 1;
  62.             //
  63.             // btnAdd
  64.             //
  65.             this.btnAdd.Location = new System.Drawing.Point(615, 19);
  66.             this.btnAdd.Name = "btnAdd";
  67.             this.btnAdd.Size = new System.Drawing.Size(59, 21);
  68.             this.btnAdd.TabIndex = 2;
  69.             this.btnAdd.Text = "&Add";
  70.             this.btnAdd.UseVisualStyleBackColor = true;
  71.             this.btnAdd.Click += new System.EventHandler(this.btnAdd_Click);
  72.             //
  73.             // btnDel
  74.             //
  75.             this.btnDel.Location = new System.Drawing.Point(615, 46);
  76.             this.btnDel.Name = "btnDel";
  77.             this.btnDel.Size = new System.Drawing.Size(59, 21);
  78.             this.btnDel.TabIndex = 3;
  79.             this.btnDel.Text = "&Delete";
  80.             this.btnDel.UseVisualStyleBackColor = true;
  81.             this.btnDel.Click += new System.EventHandler(this.btnDel_Click);
  82.             //
  83.             // btnSave
  84.             //
  85.             this.btnSave.Location = new System.Drawing.Point(611, 20);
  86.             this.btnSave.Name = "btnSave";
  87.             this.btnSave.Size = new System.Drawing.Size(59, 21);
  88.             this.btnSave.TabIndex = 4;
  89.             this.btnSave.Text = "&Save";
  90.             this.btnSave.UseVisualStyleBackColor = true;
  91.             this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
  92.             //
  93.             // grpList
  94.             //
  95.             this.grpList.Controls.Add(this.btnSave);
  96.             this.grpList.Controls.Add(this.listeFlux);
  97.             this.grpList.Location = new System.Drawing.Point(5, 5);
  98.             this.grpList.Name = "grpList";
  99.             this.grpList.Size = new System.Drawing.Size(677, 288);
  100.             this.grpList.TabIndex = 5;
  101.             this.grpList.TabStop = false;
  102.             this.grpList.Text = "List";
  103.             //
  104.             // grpPodcast
  105.             //
  106.             this.grpPodcast.Controls.Add(this.inputGenre);
  107.             this.grpPodcast.Controls.Add(this.label4);
  108.             this.grpPodcast.Controls.Add(this.inputType);
  109.             this.grpPodcast.Controls.Add(this.label3);
  110.             this.grpPodcast.Controls.Add(this.label2);
  111.             this.grpPodcast.Controls.Add(this.label1);
  112.             this.grpPodcast.Controls.Add(this.inputName);
  113.             this.grpPodcast.Controls.Add(this.inputUrl);
  114.             this.grpPodcast.Controls.Add(this.btnDel);
  115.             this.grpPodcast.Controls.Add(this.btnAdd);
  116.             this.grpPodcast.Location = new System.Drawing.Point(5, 299);
  117.             this.grpPodcast.Name = "grpPodcast";
  118.             this.grpPodcast.Size = new System.Drawing.Size(676, 113);
  119.             this.grpPodcast.TabIndex = 6;
  120.             this.grpPodcast.TabStop = false;
  121.             this.grpPodcast.Text = "Podcast";
  122.             //
  123.             // inputGenre
  124.             //
  125.             this.inputGenre.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  126.             this.inputGenre.FormattingEnabled = true;
  127.             this.inputGenre.Items.AddRange(new object[] {
  128.             "(N/A)",
  129.             "Bues",
  130.             "Country",
  131.             "Disco",
  132.             "Dance",
  133.             "Funk",
  134.             "Hip Hop",
  135.             "Jazz",
  136.             "Pop",
  137.             "R&B",
  138.             "Reggae",
  139.             "Rock",
  140.             "Techno"});
  141.             this.inputGenre.Location = new System.Drawing.Point(53, 74);
  142.             this.inputGenre.MaxDropDownItems = 13;
  143.             this.inputGenre.Name = "inputGenre";
  144.             this.inputGenre.Size = new System.Drawing.Size(96, 21);
  145.             this.inputGenre.TabIndex = 9;
  146.             //
  147.             // label4
  148.             //
  149.             this.label4.AutoSize = true;
  150.             this.label4.Location = new System.Drawing.Point(7, 77);
  151.             this.label4.Name = "label4";
  152.             this.label4.Size = new System.Drawing.Size(40, 13);
  153.             this.label4.TabIndex = 8;
  154.             this.label4.Text = "Genre:";
  155.             //
  156.             // inputType
  157.             //
  158.             this.inputType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
  159.             this.inputType.FormattingEnabled = true;
  160.             this.inputType.Items.AddRange(new object[] {
  161.             "Music",
  162.             "Talk",
  163.             "Video"});
  164.             this.inputType.Location = new System.Drawing.Point(510, 47);
  165.             this.inputType.MaxDropDownItems = 3;
  166.             this.inputType.Name = "inputType";
  167.             this.inputType.Size = new System.Drawing.Size(99, 21);
  168.             this.inputType.TabIndex = 7;
  169.             this.inputType.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.inputType_TextChanged);
  170.             this.inputType.TextChanged += new System.EventHandler(this.inputType_TextChanged);
  171.             //
  172.             // label3
  173.             //
  174.             this.label3.AutoSize = true;
  175.             this.label3.Location = new System.Drawing.Point(469, 50);
  176.             this.label3.Name = "label3";
  177.             this.label3.Size = new System.Drawing.Size(35, 13);
  178.             this.label3.TabIndex = 6;
  179.             this.label3.Text = "Type:";
  180.             //
  181.             // label2
  182.             //
  183.             this.label2.AutoSize = true;
  184.             this.label2.Location = new System.Drawing.Point(7, 50);
  185.             this.label2.Name = "label2";
  186.             this.label2.Size = new System.Drawing.Size(38, 13);
  187.             this.label2.TabIndex = 5;
  188.             this.label2.Text = "Name:";
  189.             //
  190.             // label1
  191.             //
  192.             this.label1.AutoSize = true;
  193.             this.label1.Location = new System.Drawing.Point(6, 24);
  194.             this.label1.Name = "label1";
  195.             this.label1.Size = new System.Drawing.Size(30, 13);
  196.             this.label1.TabIndex = 4;
  197.             this.label1.Text = "URL:";
  198.             //
  199.             // inputName
  200.             //
  201.             this.inputName.Location = new System.Drawing.Point(50, 47);
  202.             this.inputName.Name = "inputName";
  203.             this.inputName.Size = new System.Drawing.Size(413, 21);
  204.             this.inputName.TabIndex = 1;
  205.             //
  206.             // Form1
  207.             //
  208.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  209.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  210.             this.AutoSize = true;
  211.             this.AutoSizeMode = System.Windows.Forms.AutoSizeMode.GrowAndShrink;
  212.             this.ClientSize = new System.Drawing.Size(685, 418);
  213.             this.Controls.Add(this.grpPodcast);
  214.             this.Controls.Add(this.grpList);
  215.             this.MaximizeBox = false;
  216.             this.Name = "Form1";
  217.             this.Text = "Podcast Project";
  218.             this.Load += new System.EventHandler(this.Form1_Load);
  219.             this.grpList.ResumeLayout(false);
  220.             this.grpPodcast.ResumeLayout(false);
  221.             this.grpPodcast.PerformLayout();
  222.             this.ResumeLayout(false);
  223.         }
  224.         #endregion
  225.         private System.Windows.Forms.ListBox listeFlux;
  226.         private System.Windows.Forms.Button btnAdd;
  227.         private System.Windows.Forms.Button btnDel;
  228.         private System.Windows.Forms.Button btnSave;
  229.         private System.Windows.Forms.GroupBox grpList;
  230.         private System.Windows.Forms.GroupBox grpPodcast;
  231.         private System.Windows.Forms.Label label2;
  232.         private System.Windows.Forms.Label label1;
  233.         private System.Windows.Forms.Label label3;
  234.         private System.Windows.Forms.Label label4;
  235.         public System.Windows.Forms.TextBox inputUrl;
  236.         public System.Windows.Forms.ComboBox inputType;
  237.         public System.Windows.Forms.TextBox inputName;
  238.         public System.Windows.Forms.ComboBox inputGenre;
  239.     }
  240. }

Les quatre dernières lignes sont a priori OK.

 

Dans Form1.cs, j'ai tapé:

 


Code :
  1. /// <summary>
  2.     ///  Basic class for any kind of feed
  3.     /// </summary>
  4.     public abstract class Feed
  5.     {
  6.         protected string url;
  7.         protected string name;
  8.         public string Name
  9.         {
  10.             get
  11.             {
  12.                 return name;
  13.             }
  14.             set
  15.             {
  16.                 name = value;
  17.             }
  18.         }
  19.         public string Url
  20.         {
  21.             get
  22.             {
  23.                 return url;
  24.             }
  25.             set
  26.             {
  27.                 url = value;
  28.             }
  29.         }
  30.         public abstract void Load();
  31.     }
  32.     public class MusicFeed : Feed
  33.     {
  34.         string genre;
  35.         public string Genre
  36.         {
  37.             get
  38.             {
  39.                 return genre;
  40.             }
  41.             set
  42.             {
  43.                 genre = value;
  44.             }
  45.         }
  46.         public MusicFeed(string inName, string inUrl, string inGenre)
  47.         {
  48.             name = inName;
  49.             url = inUrl;
  50.             genre = inGenre;
  51.         }
  52.         public override void Load()
  53.         {
  54.             Form1.inputName.Text = name;
  55.         }
  56.     }


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
mood
Publicité
Posté le 26-11-2006 à 18:11:25  profilanswer
 

n°1481985
Piksou
Posté le 26-11-2006 à 19:37:14  profilanswer
 

résolu: http://www.developpez.net/forums/s [...] ost1546225


---------------
« 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

Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  C#/.NET managed

  [C# / .Net 2.0] Accès à des Winforms (sans doute trivial mais...)

 

Sujets relatifs
[C# .Net] Aller en bas de la page via un <asp:Button>Accès aux octets
[.Net 2 CLR] relation entre GetHashCode() et Equals()Option de compilation 16 bits sur Visual .NET ?
[Struts]accés aux ressources depuis une classe action[PHP] difference d'accès a un site par rapport au model
Soft pour surveiller les accès aux fichiers[C# .NET/base de données]
[C# .Net] Mettre en commun du code[.Net] Qui utilise CodeSmith + NetTiers ?
Plus de sujets relatifs à : [C# / .Net 2.0] Accès à des Winforms (sans doute trivial mais...)


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR