IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

[C#] problème d'affichage d'une nouvelle Form


Sujet :

C#

  1. #1
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut [C#] problème d'affichage d'une nouvelle Form
    Bonjour,

    J'ai créer une deuxième Form dans mon projet. Dans ma Form principale, j'ai créer un menu et lorsque je clique dessus, j'aimerais ouvrir la deuxième Form.

    J'ai simplement mis

    form2.Show();

    La nouvelle form s'affiche, mais elle est vide, elle ne contient pas les textBox que j'ai inséré au début....

    Je ne comprends pas ce problème...

    Merci...

  2. #2
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    Comment as-tu appellé ta 2ème form : form2 :

  3. #3
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut
    Je l'ai appelé form2

    public Form form2 = new Form();

    Mais lorsque j'ajoute une nouvelle form, la déclaration automatique arrive :

    public Form2 form2 = new Form2();

    et ça me dit qu'il y a une erreur.... donc je la change à

    public Form form2 = new Form();

    J'ouvre ma nouvelle form depuis ma première.... et je place des TextBox sur ma nouvelle form et j'aimerais avoir accès depuis ma première forme....

  4. #4
    Rédacteur
    Avatar de Thomas Lebrun
    Profil pro
    Inscrit en
    Octobre 2002
    Messages
    9 161
    Détails du profil
    Informations personnelles :
    Âge : 42
    Localisation : France

    Informations forums :
    Inscription : Octobre 2002
    Messages : 9 161
    Points : 19 434
    Points
    19 434
    Par défaut
    On pourrait voir to ncode (de tes form) :

  5. #5
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut
    form1 Forme principale

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
     
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
    using System.Data;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
    using System.Text;
     
     
    namespace CLIENT
    {
    	/// <summary>
    	/// Description résumée de Form1.
    	/// </summary>
    	public class Form1 : System.Windows.Forms.Form
    	{
    		private SoftWIRE.ErrorCatcher errorCatcher1;
    		private System.Windows.Forms.ListBox listBox1;
    		private System.Windows.Forms.Button button1;
    		/// <summary>
    		/// Variable nécessaire au concepteur.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
            private Form form2 = new Form();
    		private Thread _thread1;
    		private Thread threadAffiche;
     
    		private System.Windows.Forms.TextBox textBox1;
    		byte [] _TableauDoubleParam = new byte[256];
    		byte [] ReceiveSimVitesse = new byte[1024];
    		byte [] ReceiveSimPosition = new byte[1024];
    		byte [] ReceiveSimId = new byte[1024];
     
    		byte [] ReceiveData = new byte[128];
     
    		byte [] ByteParamSend = new byte[128];
    		byte [] ByteParamReceive = new byte[128];
     
    		string [] TableauParam = new string[22];
     
     
    		double [] DataVitesseReceive = new double[1024];
     
     
    		private System.Windows.Forms.Splitter splitter1;
    		byte [] ReceiveSimIq = new byte[1024];
    		private System.Windows.Forms.TextBox textBox2;
    		private System.Windows.Forms.TextBox textBox3;
    		private System.Windows.Forms.TextBox textBox4;
    		private System.Windows.Forms.TextBox textBox5;
    		private System.Windows.Forms.TextBox textBox6;
     
    		private SoftWIRE.VI.StripChart stripChart1;
    		private System.Windows.Forms.Button button2;
    		private System.Windows.Forms.MainMenu mainMenu1;
    		private System.Windows.Forms.MenuItem menuItem1;
    		private System.Windows.Forms.MenuItem menuItem2;
    		private System.Windows.Forms.MenuItem menuItem3;
     
    		public Socket ClientSocket;
     
    		public Form1()
    		{
    			//
    			// Requis pour la prise en charge du Concepteur Windows Forms
    			//
    			InitializeComponent();
     
    			//
    			// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
    			//
    			SoftWIRE.Diagram.Initialize(this);
    		}
     
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if (components != null) 
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
     
    		#region Windows Form Designer generated code
    		/// <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.errorCatcher1 = new SoftWIRE.ErrorCatcher();
    			this.listBox1 = new System.Windows.Forms.ListBox();
    			this.button1 = new System.Windows.Forms.Button();
    			this.textBox1 = new System.Windows.Forms.TextBox();
    			this.splitter1 = new System.Windows.Forms.Splitter();
    			this.textBox2 = new System.Windows.Forms.TextBox();
    			this.textBox3 = new System.Windows.Forms.TextBox();
    			this.textBox4 = new System.Windows.Forms.TextBox();
    			this.textBox5 = new System.Windows.Forms.TextBox();
    			this.textBox6 = new System.Windows.Forms.TextBox();
    			this.stripChart1 = new SoftWIRE.VI.StripChart();
    			this.button2 = new System.Windows.Forms.Button();
    			this.mainMenu1 = new System.Windows.Forms.MainMenu();
    			this.menuItem1 = new System.Windows.Forms.MenuItem();
    			this.menuItem2 = new System.Windows.Forms.MenuItem();
    			this.menuItem3 = new System.Windows.Forms.MenuItem();
    			this.SuspendLayout();
    			// 
    			// errorCatcher1
    			// 
    			this.errorCatcher1.AllowThrowExceptions = false;
    			this.errorCatcher1.CancelBlock = false;
    			this.errorCatcher1.ControlIn = true;
    			this.errorCatcher1.ControlName = "errorCatcher1";
    			this.errorCatcher1.DisplayFormat = SoftWIRE.DisplayFormat.MsgBox;
    			this.errorCatcher1.FileName = "";
    			this.errorCatcher1.FormName = "Form1";
    			this.errorCatcher1.Location = new System.Drawing.Point(20000, 20000);
    			this.errorCatcher1.LogToFile = false;
    			this.errorCatcher1.Name = "errorCatcher1";
    			this.errorCatcher1.Namespace = null;
    			this.errorCatcher1.Size = new System.Drawing.Size(25, 25);
    			this.errorCatcher1.SoftWIRE_Tag = null;
    			this.errorCatcher1.TabIndex = 0;
    			this.errorCatcher1.TabStop = false;
    			// 
    			// listBox1
    			// 
    			this.listBox1.Location = new System.Drawing.Point(0, 176);
    			this.listBox1.Name = "listBox1";
    			this.listBox1.Size = new System.Drawing.Size(256, 121);
    			this.listBox1.TabIndex = 0;
    			// 
    			// button1
    			// 
    			this.button1.Location = new System.Drawing.Point(16, 8);
    			this.button1.Name = "button1";
    			this.button1.Size = new System.Drawing.Size(104, 23);
    			this.button1.TabIndex = 1;
    			this.button1.Text = "Connecter";
    			this.button1.Click += new System.EventHandler(this.button1_Click);
    			// 
    			// textBox1
    			// 
    			this.textBox1.Location = new System.Drawing.Point(128, 8);
    			this.textBox1.Name = "textBox1";
    			this.textBox1.TabIndex = 2;
    			this.textBox1.Text = "192.168.2.10";
    			// 
    			// splitter1
    			// 
    			this.splitter1.Name = "splitter1";
    			this.splitter1.Size = new System.Drawing.Size(3, 310);
    			this.splitter1.TabIndex = 3;
    			this.splitter1.TabStop = false;
    			// 
    			// textBox2
    			// 
    			this.textBox2.Location = new System.Drawing.Point(16, 40);
    			this.textBox2.Name = "textBox2";
    			this.textBox2.TabIndex = 4;
    			this.textBox2.Text = "1.01";
    			// 
    			// textBox3
    			// 
    			this.textBox3.Location = new System.Drawing.Point(16, 64);
    			this.textBox3.Name = "textBox3";
    			this.textBox3.TabIndex = 5;
    			this.textBox3.Text = "100";
    			// 
    			// textBox4
    			// 
    			this.textBox4.Location = new System.Drawing.Point(16, 88);
    			this.textBox4.Name = "textBox4";
    			this.textBox4.TabIndex = 6;
    			this.textBox4.Text = "34";
    			// 
    			// textBox5
    			// 
    			this.textBox5.Location = new System.Drawing.Point(16, 112);
    			this.textBox5.Name = "textBox5";
    			this.textBox5.TabIndex = 7;
    			this.textBox5.Text = "15.78";
    			// 
    			// textBox6
    			// 
    			this.textBox6.Location = new System.Drawing.Point(16, 136);
    			this.textBox6.Name = "textBox6";
    			this.textBox6.TabIndex = 8;
    			this.textBox6.Text = "1000";
    			// 
    			// stripChart1
    			// 
    			this.stripChart1.AllowThrowExceptions = false;
    			this.stripChart1.AutoScale = SoftWIRE.VI.AutoScale.Both;
    			this.stripChart1.BackColor = System.Drawing.SystemColors.Control;
    			this.stripChart1.Border = SoftWIRE.VI.Border.Etched;
    			this.stripChart1.BufferSize = 2001;
    			this.stripChart1.CancelBlock = false;
    			this.stripChart1.Caption = "";
    			this.stripChart1.ControlIn = true;
    			this.stripChart1.ControlName = "stripChart1";
    			this.stripChart1.ControlSurface = SoftWIRE.VI.ControlSurface.Highlighted;
    			this.stripChart1.DateTimeFormat = SoftWIRE.VI.StripChart.DateLabelFormat.Time_HHMMSS;
    			this.stripChart1.DateTimeMode = false;
    			this.stripChart1.DisplaySize = 600;
    			this.stripChart1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
    			this.stripChart1.ForeColor = System.Drawing.SystemColors.ControlText;
    			this.stripChart1.FormName = "Form1";
    			this.stripChart1.Location = new System.Drawing.Point(272, 8);
    			this.stripChart1.MajorGrid = new SoftWIRE.VI.Grid(false, System.Drawing.Color.Gray, System.Drawing.Drawing2D.DashStyle.Solid);
    			this.stripChart1.MinorGrid = new SoftWIRE.VI.Grid(false, System.Drawing.Color.Gray, System.Drawing.Drawing2D.DashStyle.Solid);
    			this.stripChart1.Name = "stripChart1";
    			this.stripChart1.Namespace = null;
    			this.stripChart1.PlotBackgroundColor = System.Drawing.Color.Linen;
    			this.stripChart1.Plots = new SoftWIRE.VI.Plot[] {
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.Red, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.RoyalBlue, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.Purple, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.Turquoise, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.Magenta, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.Aqua, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.CadetBlue, true),
    																new SoftWIRE.VI.Plot(1, System.Drawing.Drawing2D.DashStyle.Solid, System.Drawing.Color.LightSlateGray, true)};
    			this.stripChart1.Size = new System.Drawing.Size(288, 200);
    			this.stripChart1.SoftWIRE_Tag = null;
    			this.stripChart1.StepSize = 1;
    			this.stripChart1.TabIndex = 9;
    			this.stripChart1.XAxis = new SoftWIRE.VI.ScrollableAxis(4, 3, System.Drawing.Color.Red, System.Drawing.Color.Black, System.Drawing.Color.Black, new System.Drawing.Font("Arial", 8F), 1, "", SoftWIRE.VI.AxisPlacement.Bottom);
    			this.stripChart1.YAxis = new SoftWIRE.VI.Axis(0, 10, 4, 3, System.Drawing.Color.Red, System.Drawing.Color.Black, System.Drawing.Color.Black, new System.Drawing.Font("Arial", 8F), 1, "", SoftWIRE.VI.AxisPlacement.Left);
    			// 
    			// button2
    			// 
    			this.button2.Location = new System.Drawing.Point(272, 216);
    			this.button2.Name = "button2";
    			this.button2.Size = new System.Drawing.Size(104, 23);
    			this.button2.TabIndex = 10;
    			this.button2.Text = "Afficher";
    			this.button2.Click += new System.EventHandler(this.button2_Click);
    			// 
    			// mainMenu1
    			// 
    			this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    																					  this.menuItem1});
    			// 
    			// menuItem1
    			// 
    			this.menuItem1.Index = 0;
    			this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
    																					  this.menuItem2,
    																					  this.menuItem3});
    			this.menuItem1.Text = "Paramètres";
    			// 
    			// menuItem2
    			// 
    			this.menuItem2.Index = 0;
    			this.menuItem2.Text = "Paramètres du moteur";
    			this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
    			// 
    			// menuItem3
    			// 
    			this.menuItem3.Index = 1;
    			this.menuItem3.Text = "Paramètres de la simultation";
    			this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
    			// 
    			// Form1
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(568, 310);
    			this.Controls.AddRange(new System.Windows.Forms.Control[] {
    																		  this.button2,
    																		  this.stripChart1,
    																		  this.textBox6,
    																		  this.textBox5,
    																		  this.textBox4,
    																		  this.textBox3,
    																		  this.textBox2,
    																		  this.splitter1,
    																		  this.textBox1,
    																		  this.button1,
    																		  this.listBox1});
    			this.Menu = this.mainMenu1;
    			this.Name = "Form1";
    			this.Text = "Client";
    			this.Load += new System.EventHandler(this.Form1_Load);
    			this.ResumeLayout(false);
     
    		}
    		#endregion
     
    		/// <summary>
    		/// Point d'entrée principal de l'application.
    		/// </summary>
    		[STAThread]
    		static void Main() 
    		{
    			Application.Run(new Form1());
    		}
     
     
     
    		private void ThrFunc1()
    		{ 
    			// Traitement effectué par le thread. Calculs est une fonction quelconque de notre Form
    			IPAddress ip = IPAddress.Parse(textBox1.Text);
    			IPEndPoint ipEnd = new IPEndPoint (ip,8000);
     
    			Socket ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     
    			try
    			{
     
    				ClientSocket.Connect(ipEnd);
     
    				if(ClientSocket.Connected==true)
    				{
    					listBox1.Items.Add("Connecté au serveur " +ClientSocket.LocalEndPoint.ToString());
    				}
     
    				LectureParam();
     
    				// Envoi des paramètres au serveur
     
    				for(int n=0;n<5;n++)
    				{
    					// Je converti le paramètre de String vers un tableau de Byte
    					ByteParamSend = Encoding.ASCII.GetBytes(TableauParam[n]);
     
    					// J'envoi le paramètre sous forme d'un tableau de Byte
    					ClientSocket.Send(ByteParamSend,0,ByteParamSend.Length,SocketFlags.None);
     
    					// Affiche le paramètre dans la ListBox
    					//listBox1.Items.Add(TableauParam[n]);
     
    					// Je me met en Réception pour attendre la confirmation. Je n'utilise pas cette
    					// confirmation, c'est juste pour synchroniser le dialogue.
    					ClientSocket.Receive(ByteParamReceive,0,ByteParamReceive.Length,SocketFlags.None);
     
    					// Je remplis de caractères vide la Tableau de Réception car si la valeur
    					// suivante est plus courte en nombre de Byte, je retrouverais les anciens 
    					// byte.
    					ByteParamSend = Encoding.ASCII.GetBytes("                  ");
    				}
     
     
     
    				// Boucle de Réception des résultats de la simulation.
    				// Pour l'instant, je reçois seulement les valeurs de la vitesse, mais pour
    				// les autres valeurs, il s'agit simplement de répéter la boucle.
    				for(int n=0;n<600;n++)
    				{
    					// Réception de la première valeur sous forme d'un tableau de BYTE
    					ClientSocket.Receive(ReceiveData,0,ReceiveData.Length,SocketFlags.None);
     
    					// Conversion de la valeur en String.
    					string DataVitesse = Encoding.ASCII.GetString(ReceiveData);
     
    					// Envoi de la même valeur pour indiquer au serveur qui la valeur a bien
    					// été reçue. Il s'agit d'un confirmation qui permettera au server d'envoyer 
    					// la valeur suivante
    					ClientSocket.Send(ReceiveData,0,ReceiveData.Length,SocketFlags.None);
     
    					// Convertir la valeur reçue "string" en une valeur DOUBLE
    					double DataDouble = Convert.ToDouble(DataVitesse);
     
    					// Stocker la valeur dans un tableau de DOUBLE pour pouvoir ensuite 
    					// l'afficher à l'aide d'un graphique. Ce tableau pourra également être
    					// utilisé pour trouver la valeur maximale ou autre chose.
    					DataVitesseReceive[n]=DataDouble;
     
    					// Affichage des valeurs reçues dans la ListBox
    					// listBox1.Items.Add(DataDouble.ToString());
    				}
    				listBox1.Items.Add("Simulation Terminée");
     
    			}
    			catch(SocketException E)
    			{
    				MessageBox.Show(E.Message);
    			}
    		}
     
     
    		private void ThrAffiche()
    		{ 
    			for(int n=0;n<600;n++)
    			{
    				this.stripChart1.Operate();
    				this.stripChart1.Value=DataVitesseReceive[n];	
    			}
    		}
     
    		private void StartThread()
    		{
    			// ThrFunc est la fonction exécutée par le thread.
    			_thread1 = new Thread(new ThreadStart(ThrFunc1));
    			// Démarrage du thread.
    			_thread1.Start();
    		}
     
    		private void StartThreadAffiche()
    		{
    			// ThrFunc est la fonction exécutée par le thread.
    			threadAffiche = new Thread(new ThreadStart(ThrAffiche));
    			// Démarrage du thread.
    			threadAffiche.Start();
    		}
     
    		private void LectureParam()
    		{
    			TableauParam[0]=textBox2.Text;
    			TableauParam[1]=textBox3.Text;
    			TableauParam[2]=textBox4.Text;
    			TableauParam[3]=textBox5.Text;
    			TableauParam[4]=textBox6.Text;
    		}
     
     
     
    		private void button1_Click(object sender, System.EventArgs e)
    		{
    			StartThread();
    		}
     
    		private void Form1_Load(object sender, System.EventArgs e)
    		{
     
    		}
     
    		private void button2_Click(object sender, System.EventArgs e)
    		{
    			StartThreadAffiche();
    		}
     
    		private void menuItem2_Click(object sender, System.EventArgs e)
    		{
    			form2.Show();
    		}
     
    		private void menuItem3_Click(object sender, System.EventArgs e)
    		{
     
    		}
     
     
    	}
    }

    form2 : Forme que je veux ouvrir en cliquant sur le menu...


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    using System;
    using System.Drawing;
    using System.Collections;
    using System.ComponentModel;
    using System.Windows.Forms;
     
    namespace SoftWireCLIENT
    {
    	/// <summary>
    	/// Description résumée de Form2.
    	/// </summary>
    	public class Form2 : System.Windows.Forms.Form
    	{
    		private System.Windows.Forms.TextBox textBox1;
    		/// <summary>
    		/// Variable nécessaire au concepteur.
    		/// </summary>
    		private System.ComponentModel.Container components = null;
     
    		public Form2()
    		{
    			//
    			// Requis pour la prise en charge du Concepteur Windows Forms
    			//
    			InitializeComponent();
     
    			//
    			// TODO : ajoutez le code du constructeur après l'appel à InitializeComponent
    			//
    		}
     
    		/// <summary>
    		/// Nettoyage des ressources utilisées.
    		/// </summary>
    		protected override void Dispose( bool disposing )
    		{
    			if( disposing )
    			{
    				if(components != null)
    				{
    					components.Dispose();
    				}
    			}
    			base.Dispose( disposing );
    		}
     
    		#region Windows Form Designer generated code
    		/// <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.textBox1 = new System.Windows.Forms.TextBox();
    			this.SuspendLayout();
    			// 
    			// textBox1
    			// 
    			this.textBox1.Location = new System.Drawing.Point(112, 80);
    			this.textBox1.Name = "textBox1";
    			this.textBox1.TabIndex = 0;
    			this.textBox1.Text = "textBox1";
    			// 
    			// Form2
    			// 
    			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
    			this.ClientSize = new System.Drawing.Size(292, 266);
    			this.Controls.AddRange(new System.Windows.Forms.Control[] {
    																		  this.textBox1});
    			this.Name = "Form2";
    			this.Text = "Form2";
    			this.Load += new System.EventHandler(this.Form2_Load);
    			this.ResumeLayout(false);
     
    		}
    		#endregion
     
    		private void Form2_Load(object sender, System.EventArgs e)
    		{
     
    		}
    	}
    }

  6. #6
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut
    est-ce normal que lorsque je crée une nouvelle forme dans mon projet, elle se déclare automatiquement dans la forme 1 de la manière suivante :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    private Form2 form2 = new Form2();
    le nom de la nouvelle forme est : Form2

    Cette déclaration automatique provoque une erreur....

    C'est vraiment bizarre... est-ce que je dois ajouter un using????

  7. #7
    Membre actif
    Homme Profil pro
    Création de jeux video (en amateur)
    Inscrit en
    Mars 2003
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cantal (Auvergne)

    Informations professionnelles :
    Activité : Création de jeux video (en amateur)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2003
    Messages : 408
    Points : 260
    Points
    260
    Par défaut
    moi ca me parait bizarre qu'il te le mette dans Form1. Parcequ'a priori Form1 et Form2 n'ont pas de raison d'être reliés.

    Si j'étais toi, je virerais cette ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    private Form2 form2 = new Form2();
    et je la remettrai quand j'en ai besoin (par exemple lors d'un clic sur un bouton)
    ZTAB (Ze Text Adventure Builder)

    Logiciel très intuitif et ergonomique de création de jeux d'aventure et de livres dont vous êtes le héros.

    http://sites.google.com/site/ztabsoft/

  8. #8
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut
    Ok, j'ai enlevé la déclaration. J'aimerais que ma nouvelle form s'affiche lorsque je clique dans le menu. J'ai écris le code suivant...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    		private void menuItem2_Click(object sender, System.EventArgs e)
    		{
    			Form Form2 = new Form();
    			Form2.Show();
    		}
    Ma nouvelle fenêtre s'affiche effectivement, mais elle est complêtement vide, elle ne contient pas la TextBox que j'ai introduit et je n'ai même pas de titre sur ma nouvelle forme....
    Je ne comprends pas du tout ce qui se passe...
    Merci de m'aider...
    Fred.

  9. #9
    Expert éminent
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Points : 7 879
    Points
    7 879
    Par défaut
    Déjà Form1 et Form2 n'ont pas le mêm espace de noms (CLIENT et SoftWireCLIENT) donc
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    private void menuItem2_Click(object sender, System.EventArgs e) 
     { 
       SoftWireCLIENT.Form2 f = new SoftWireCLIENT.Form2(); 
       f.Show(); 
     }
    De plus verife que dans ton Espace de noms CLIENT il ne traine pas une vieille classe Form2 qui ne sert plus à rien
    Pour le bien de ceux qui vous lisent, ayez à coeur le respect du forum et de ses règles

  10. #10
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut
    Encore une fois merci beaucoup neguib....

    ça fonctionne....

    Merci merci merci....

  11. #11
    Membre actif
    Homme Profil pro
    Création de jeux video (en amateur)
    Inscrit en
    Mars 2003
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cantal (Auvergne)

    Informations professionnelles :
    Activité : Création de jeux video (en amateur)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2003
    Messages : 408
    Points : 260
    Points
    260
    Par défaut
    merci Harry_polin...
    ZTAB (Ze Text Adventure Builder)

    Logiciel très intuitif et ergonomique de création de jeux d'aventure et de livres dont vous êtes le héros.

    http://sites.google.com/site/ztabsoft/

  12. #12
    Expert éminent
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Points : 7 879
    Points
    7 879
    Par défaut
    Citation Envoyé par Harry_polin
    merci Harry_polin...
    mais oui mais oui mais bon tu aurais pu lui signaler le problème des namespaces explicitement
    Pour le bien de ceux qui vous lisent, ayez à coeur le respect du forum et de ses règles

  13. #13
    Membre actif
    Homme Profil pro
    Création de jeux video (en amateur)
    Inscrit en
    Mars 2003
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cantal (Auvergne)

    Informations professionnelles :
    Activité : Création de jeux video (en amateur)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2003
    Messages : 408
    Points : 260
    Points
    260
    Par défaut
    Toute participation constructive menant à la résolution d'un problème mérite d'être remerciée, et pas uniquement la dernière.
    ZTAB (Ze Text Adventure Builder)

    Logiciel très intuitif et ergonomique de création de jeux d'aventure et de livres dont vous êtes le héros.

    http://sites.google.com/site/ztabsoft/

  14. #14
    Expert éminent
    Avatar de neguib
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    3 627
    Détails du profil
    Informations personnelles :
    Âge : 64
    Localisation : Suisse

    Informations forums :
    Inscription : Mai 2005
    Messages : 3 627
    Points : 7 879
    Points
    7 879
    Par défaut
    Citation Envoyé par Harry_polin
    Toute participation constructive menant à la résolution d'un problème mérite d'être remerciée, et pas uniquement la dernière.
    Que Dieu t'entende
    Pour le bien de ceux qui vous lisent, ayez à coeur le respect du forum et de ses règles

  15. #15
    Membre actif
    Homme Profil pro
    Création de jeux video (en amateur)
    Inscrit en
    Mars 2003
    Messages
    408
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Cantal (Auvergne)

    Informations professionnelles :
    Activité : Création de jeux video (en amateur)
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2003
    Messages : 408
    Points : 260
    Points
    260
    Par défaut
    Citation Envoyé par neguib
    Que Dieu t'entende
    Si tu as l'occasion de le croiser, demande-lui d'ôter ses boule Quies.
    ZTAB (Ze Text Adventure Builder)

    Logiciel très intuitif et ergonomique de création de jeux d'aventure et de livres dont vous êtes le héros.

    http://sites.google.com/site/ztabsoft/

  16. #16
    Membre à l'essai
    Inscrit en
    Décembre 2004
    Messages
    35
    Détails du profil
    Informations forums :
    Inscription : Décembre 2004
    Messages : 35
    Points : 19
    Points
    19
    Par défaut
    Merci Harry _polin.... excuse moi... je remercie tout le monde.....

    C'est un très bon forum ou les gens sont parfait....

    Merci a tout le monde.....

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Problème d'affichage avec une nouvelle librairie
    Par reito dans le forum Struts 1
    Réponses: 0
    Dernier message: 22/07/2010, 12h22
  2. Affichage d'une form dans une nouvelle form
    Par Djang0 dans le forum C++Builder
    Réponses: 8
    Dernier message: 26/08/2009, 10h11
  3. Problème d'affichage d'une form en mode [Design]
    Par helico2 dans le forum C++/CLI
    Réponses: 0
    Dernier message: 17/04/2008, 10h37
  4. Problème d'affichage d'une form en mode [Design]
    Par helico2 dans le forum C++/CLI
    Réponses: 2
    Dernier message: 16/04/2008, 13h23
  5. form.show affichage d'une nouvelle fiche
    Par nadia2222 dans le forum Bases de données
    Réponses: 1
    Dernier message: 10/06/2007, 06h44

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo