Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Testo in C#
Forum - C# / VB.NET - Testo in C# - Pagina 2

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Segnala al moderatore
Postato alle 8:46
Domenica, 06/04/2008
Testo quotato

Postato originariamente da Dark_Limit:

Nessuno ha detto che form è l'oggetto..:k:


Ah sì?
Codice sorgente - presumibilmente Plain Text

  1. form2.label1.text="Testo"


Da questo codice si evince chiaramente che form2 viene considerato come oggetto, perchè solo da un'istanza di classe è possibile modificare le proprietà. Tu non scrivi mica:
Codice sorgente - presumibilmente Plain Text

  1. ArrayList.Items(2) = 3


ma
Codice sorgente - presumibilmente C# / VB.NET

  1. Dim D As New ArrayList
  2. '...
  3. D.Items(2) = 3


:D

Detto questo, se il form viene aperto dichiarandone una nuova istanza (dim d as new form2) bisognerebbe che questa istanza sia visibile da tutte le parti del progetto e non sia una variabile locale. Se invece si usa My.Forms.Form2 non c'è problema.

PM Quote
Avatar
Exit93 (Ex-Member)
Rookie


Messaggi: 34
Iscritto: 31/03/2008

Segnala al moderatore
Postato alle 11:14
Domenica, 06/04/2008
Il fatto è ke l'IDE non mi permette di fare con My.Forms.Form2, mi da errore!

PM Quote
Avatar
Dark_Limit (Ex-Member)
Expert


Messaggi: 220
Iscritto: 15/01/2008

Segnala al moderatore
Postato alle 14:21
Domenica, 06/04/2008
Testo quotato

Postato originariamente da Il Totem:

Testo quotato

Postato originariamente da Dark_Limit:

Nessuno ha detto che form è l'oggetto..:k:


Ah sì?
Codice sorgente - presumibilmente Plain Text

  1. form2.label1.text="Testo"


Da questo codice si evince chiaramente che form2 viene considerato come oggetto, perchè solo da un'istanza di classe è possibile modificare le proprietà. Tu non scrivi mica:
Codice sorgente - presumibilmente Plain Text

  1. ArrayList.Items(2) = 3


ma
Codice sorgente - presumibilmente C# / VB.NET

  1. Dim D As New ArrayList
  2. '...
  3. D.Items(2) = 3


:D

Detto questo, se il form viene aperto dichiarandone una nuova istanza (dim d as new form2) bisognerebbe che questa istanza sia visibile da tutte le parti del progetto e non sia una variabile locale. Se invece si usa My.Forms.Form2 non c'è problema.




Non è Visual Basic Totem, ma è C#. In C# non esiste my per cui basta mettere il nome del form direttamente..:D

PM Quote
Avatar
Exit93 (Ex-Member)
Rookie


Messaggi: 34
Iscritto: 31/03/2008

Segnala al moderatore
Postato alle 15:16
Domenica, 06/04/2008
Quindi come potrei fare:-?

PM Quote
Avatar
Exit93 (Ex-Member)
Rookie


Messaggi: 34
Iscritto: 31/03/2008

Segnala al moderatore
Postato alle 22:56
Domenica, 06/04/2008
Ho riguardato bene e non so come ora visual studio mi inizia a dire che la label non è accessibile a livello di protezione, la classe del form è public partial class, come gestisco quindi la protezione??

PM Quote
Avatar
Dark_Limit (Ex-Member)
Expert


Messaggi: 220
Iscritto: 15/01/2008

Segnala al moderatore
Postato alle 23:38
Domenica, 06/04/2008
La protezione può in alcuni casi coincidere con la visibilità..non ti conviene gestirla da codice come mi sembra di aver capito ma ti conviene modificarla dal pannello proprietà dell'IDE..cmq quasi sicuramente avrai la classe impostata su Protected !
Modificarla da codice a public partial class non avrebbe molto senso se non con un giro di funzioni..quindi se il compilatore ti da errore è perchè l'hai impostata su Protected..impostala su pubblic e qualora tu l'avessi già fatto ma non funzionasse reinstalla il compilatore o aggiorna il framework(anche se è molto improbabile che sia esso!)..:k:

PM Quote
Avatar
Exit93 (Ex-Member)
Rookie


Messaggi: 34
Iscritto: 31/03/2008

Segnala al moderatore
Postato alle 14:00
Lunedì, 07/04/2008
la classe la aveva messa public partial visual studio senza che io facessi niente, cmq guardando il codice di designer del form ci sono delle cose private, eccoti il codice (escluso namespace), dimmi se devo modificare qualcosa:
Codice sorgente - presumibilmente Delphi

  1. partial class Form2
  2.         {
  3.                 /// <summary>
  4.                 /// Required designer variable.
  5.                 /// </summary>
  6.                 private System.ComponentModel.IContainer components = null;
  7.  
  8.                 /// <summary>
  9.                 /// Clean up any resources being used.
  10.                 /// </summary>
  11.                 /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
  12.                 protected override void Dispose(bool disposing)
  13.                 {
  14.                         if (disposing && (components != null))
  15.                         {
  16.                                 components.Dispose();
  17.                         }
  18.                         base.Dispose(disposing);
  19.                 }
  20.  
  21.                 #region Windows Form Designer generated code
  22.  
  23.                 /// <summary>
  24.                 /// Required method for Designer support - do not modify
  25.                 /// the contents of this method with the code editor.
  26.                 /// </summary>
  27.                 private void InitializeComponent()
  28.                 {
  29.             this.groupBox1 = new System.Windows.Forms.GroupBox();
  30.             this.button3 = new System.Windows.Forms.Button();
  31.             this.button2 = new System.Windows.Forms.Button();
  32.             this.button1 = new System.Windows.Forms.Button();
  33.             this.textBox1 = new System.Windows.Forms.TextBox();
  34.             this.groupBox2 = new System.Windows.Forms.GroupBox();
  35.             this.textBox4 = new System.Windows.Forms.TextBox();
  36.             this.label3 = new System.Windows.Forms.Label();
  37.             this.textBox3 = new System.Windows.Forms.TextBox();
  38.             this.label2 = new System.Windows.Forms.Label();
  39.             this.checkBox1 = new System.Windows.Forms.CheckBox();
  40.             this.label1 = new System.Windows.Forms.Label();
  41.             this.button4 = new System.Windows.Forms.Button();
  42.             this.textBox2 = new System.Windows.Forms.TextBox();
  43.             this.button6 = new System.Windows.Forms.Button();
  44.             this.button5 = new System.Windows.Forms.Button();
  45.             this.groupBox1.SuspendLayout();
  46.             this.groupBox2.SuspendLayout();
  47.             this.SuspendLayout();
  48.             //
  49.             // groupBox1
  50.             //
  51.             this.groupBox1.Controls.Add(this.button3);
  52.             this.groupBox1.Controls.Add(this.button2);
  53.             this.groupBox1.Controls.Add(this.button1);
  54.             this.groupBox1.Controls.Add(this.textBox1);
  55.             this.groupBox1.Location = new System.Drawing.Point(12, 12);
  56.             this.groupBox1.Name = "groupBox1";
  57.             this.groupBox1.Size = new System.Drawing.Size(395, 94);
  58.             this.groupBox1.TabIndex = 0;
  59.             this.groupBox1.TabStop = false;
  60.             this.groupBox1.Text = "Priorità Email";
  61.             //
  62.             // button3
  63.             //
  64.             this.button3.Location = new System.Drawing.Point(67, 54);
  65.             this.button3.Name = "button3";
  66.             this.button3.Size = new System.Drawing.Size(75, 23);
  67.             this.button3.TabIndex = 3;
  68.             this.button3.Text = "Bassa";
  69.             this.button3.UseVisualStyleBackColor = true;
  70.             this.button3.Click += new System.EventHandler(this.button3_Click);
  71.             //
  72.             // button2
  73.             //
  74.             this.button2.Location = new System.Drawing.Point(148, 54);
  75.             this.button2.Name = "button2";
  76.             this.button2.Size = new System.Drawing.Size(75, 23);
  77.             this.button2.TabIndex = 2;
  78.             this.button2.Text = "Normale";
  79.             this.button2.UseVisualStyleBackColor = true;
  80.             this.button2.Click += new System.EventHandler(this.button2_Click);
  81.             //
  82.             // button1
  83.             //
  84.             this.button1.Location = new System.Drawing.Point(229, 54);
  85.             this.button1.Name = "button1";
  86.             this.button1.Size = new System.Drawing.Size(75, 23);
  87.             this.button1.TabIndex = 1;
  88.             this.button1.Text = "Alta";
  89.             this.button1.UseVisualStyleBackColor = true;
  90.             this.button1.Click += new System.EventHandler(this.button1_Click);
  91.             //
  92.             // textBox1
  93.             //
  94.             this.textBox1.Location = new System.Drawing.Point(138, 19);
  95.             this.textBox1.Name = "textBox1";
  96.             this.textBox1.ReadOnly = true;
  97.             this.textBox1.Size = new System.Drawing.Size(100, 20);
  98.             this.textBox1.TabIndex = 0;
  99.             this.textBox1.Text = "Alta";
  100.             //
  101.             // groupBox2
  102.             //
  103.             this.groupBox2.Controls.Add(this.textBox4);
  104.             this.groupBox2.Controls.Add(this.label3);
  105.             this.groupBox2.Controls.Add(this.textBox3);
  106.             this.groupBox2.Controls.Add(this.label2);
  107.             this.groupBox2.Controls.Add(this.checkBox1);
  108.             this.groupBox2.Controls.Add(this.label1);
  109.             this.groupBox2.Controls.Add(this.button4);
  110.             this.groupBox2.Controls.Add(this.textBox2);
  111.             this.groupBox2.Location = new System.Drawing.Point(12, 112);
  112.             this.groupBox2.Name = "groupBox2";
  113.             this.groupBox2.Size = new System.Drawing.Size(395, 190);
  114.             this.groupBox2.TabIndex = 1;
  115.             this.groupBox2.TabStop = false;
  116.             this.groupBox2.Text = "Server SMTP";
  117.             //
  118.             // textBox4
  119.             //
  120.             this.textBox4.Location = new System.Drawing.Point(67, 140);
  121.             this.textBox4.Name = "textBox4";
  122.             this.textBox4.PasswordChar = '&#9679;';
  123.             this.textBox4.ReadOnly = true;
  124.             this.textBox4.Size = new System.Drawing.Size(182, 20);
  125.             this.textBox4.TabIndex = 7;
  126.             //
  127.             // label3
  128.             //
  129.             this.label3.AutoSize = true;
  130.             this.label3.Location = new System.Drawing.Point(6, 143);
  131.             this.label3.Name = "label3";
  132.             this.label3.Size = new System.Drawing.Size(59, 13);
  133.             this.label3.TabIndex = 6;
  134.             this.label3.Text = "Password: ";
  135.             //
  136.             // textBox3
  137.             //
  138.             this.textBox3.Location = new System.Drawing.Point(67, 107);
  139.             this.textBox3.Name = "textBox3";
  140.             this.textBox3.ReadOnly = true;
  141.             this.textBox3.Size = new System.Drawing.Size(182, 20);
  142.             this.textBox3.TabIndex = 5;
  143.             //
  144.             // label2
  145.             //
  146.             this.label2.AutoSize = true;
  147.             this.label2.Location = new System.Drawing.Point(6, 110);
  148.             this.label2.Name = "label2";
  149.             this.label2.Size = new System.Drawing.Size(58, 13);
  150.             this.label2.TabIndex = 4;
  151.             this.label2.Text = "Username:";
  152.             //
  153.             // checkBox1
  154.             //
  155.             this.checkBox1.AutoSize = true;
  156.             this.checkBox1.Location = new System.Drawing.Point(6, 81);
  157.             this.checkBox1.Name = "checkBox1";
  158.             this.checkBox1.Size = new System.Drawing.Size(175, 17);
  159.             this.checkBox1.TabIndex = 3;
  160.             this.checkBox1.Text = "Il server richiede autenticazione";
  161.             this.checkBox1.UseVisualStyleBackColor = true;
  162.             this.checkBox1.CheckedChanged += new System.EventHandler(this.checkBox1_CheckedChanged);
  163.             //
  164.             // label1
  165.             //
  166.             this.label1.AutoSize = true;
  167.             this.label1.Location = new System.Drawing.Point(6, 42);
  168.             this.label1.Name = "label1";
  169.             this.label1.Size = new System.Drawing.Size(372, 13);
  170.             this.label1.TabIndex = 2;
  171.             this.label1.Text = "Se il server predefinito (out.alice.it) non dovesse funzionare puoi cambiarlo qui" +
  172.                 "";
  173.             //
  174.             // button4
  175.             //
  176.             this.button4.Location = new System.Drawing.Point(310, 17);
  177.             this.button4.Name = "button4";
  178.             this.button4.Size = new System.Drawing.Size(75, 23);
  179.             this.button4.TabIndex = 1;
  180.             this.button4.Text = "Lista Server";
  181.             this.button4.UseVisualStyleBackColor = true;
  182.             this.button4.Click += new System.EventHandler(this.button4_Click);
  183.             //
  184.             // textBox2
  185.             //
  186.             this.textBox2.Location = new System.Drawing.Point(9, 19);
  187.             this.textBox2.Name = "textBox2";
  188.             this.textBox2.Size = new System.Drawing.Size(295, 20);
  189.             this.textBox2.TabIndex = 0;
  190.             this.textBox2.Text = "out.alice.it";
  191.             //
  192.             // button6
  193.             //
  194.             this.button6.Location = new System.Drawing.Point(198, 308);
  195.             this.button6.Name = "button6";
  196.             this.button6.Size = new System.Drawing.Size(209, 49);
  197.             this.button6.TabIndex = 8;
  198.             this.button6.Text = "Chiudi";
  199.             this.button6.UseVisualStyleBackColor = true;
  200.             this.button6.Click += new System.EventHandler(this.button6_Click);
  201.             //
  202.             // button5
  203.             //
  204.             this.button5.Location = new System.Drawing.Point(12, 308);
  205.             this.button5.Name = "button5";
  206.             this.button5.Size = new System.Drawing.Size(180, 49);
  207.             this.button5.TabIndex = 8;
  208.             this.button5.Text = "Predefiniti";
  209.             this.button5.UseVisualStyleBackColor = true;
  210.             this.button5.Click += new System.EventHandler(this.button5_Click);
  211.             //
  212.             // Form2
  213.             //
  214.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
  215.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
  216.             this.ClientSize = new System.Drawing.Size(419, 369);
  217.             this.ControlBox = false;
  218.             this.Controls.Add(this.button5);
  219.             this.Controls.Add(this.button6);
  220.             this.Controls.Add(this.groupBox2);
  221.             this.Controls.Add(this.groupBox1);
  222.             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  223.             this.MaximizeBox = false;
  224.             this.Name = "Form2";
  225.             this.ShowInTaskbar = false;
  226.             this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  227.             this.Text = "Opzioni";
  228.             this.groupBox1.ResumeLayout(false);
  229.             this.groupBox1.PerformLayout();
  230.             this.groupBox2.ResumeLayout(false);
  231.             this.groupBox2.PerformLayout();
  232.             this.ResumeLayout(false);
  233.  
  234.                 }
  235.  
  236.                 #endregion
  237.  
  238.         private System.Windows.Forms.GroupBox groupBox1;
  239.         private System.Windows.Forms.Button button3;
  240.         private System.Windows.Forms.Button button2;
  241.         private System.Windows.Forms.Button button1;
  242.         private System.Windows.Forms.TextBox textBox1;
  243.         private System.Windows.Forms.GroupBox groupBox2;
  244.         private System.Windows.Forms.Label label1;
  245.         private System.Windows.Forms.Button button4;
  246.         private System.Windows.Forms.TextBox textBox2;
  247.         private System.Windows.Forms.TextBox textBox4;
  248.         private System.Windows.Forms.Label label3;
  249.         private System.Windows.Forms.TextBox textBox3;
  250.         private System.Windows.Forms.Label label2;
  251.         private System.Windows.Forms.CheckBox checkBox1;
  252.         private System.Windows.Forms.Button button6;
  253.         private System.Windows.Forms.Button button5;
  254.         }


PM Quote
Avatar
Dark_Limit (Ex-Member)
Expert


Messaggi: 220
Iscritto: 15/01/2008

Segnala al moderatore
Postato alle 14:33
Lunedì, 07/04/2008
Ciao..se non ti modofica il valore in public il compilatore allora devi farlo tu ma nn so se funziona perchè non l'ho mai fatto manualmente da codice(al massimo fai un backup del progetto)..Guardando ultravelocemente il sorgente del designer del form, modifica in pubblic la label che a te interessa che è Private :

Codice sorgente - presumibilmente C# / VB.NET

  1. private System.Windows.Forms.Label label1;
  2.         private System.Windows.Forms.Label label3;
  3.         private System.Windows.Forms.Label label2;


Ultima modifica effettuata da Dark_Limit il 07/04/2008 alle 14:35
PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo