Announcement

Collapse
No announcement yet.

Von einer Form in die andere etwas eintragen

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Von einer Form in die andere etwas eintragen

    Guten Tag Liebe Community,

    ich stehe leider vor einem Rätsel und ersuche daher eure Hilfe.
    Ich möchte gerne das wenn ich auf Form2 etwas in eine textbox eingebe und bestätige das es auf Form1 in ein ToolStripSplitButton1 eingetragen wird.

    Erst dachte ich das ginge vieleicht mit Items.Add aber das geht nicht.
    Wäre euch sehr danbar für eine kleine Hilfestellung.

    Mit freundlichen Grüßen

    Stefan Frank

  • #2
    Hallo,

    ein konkretes Beispiel kann ich leider nicht verwenden, weil die verwendete Sprache (VB oder C#) nicht bekannt ist. Generell würde ich so vorgehen:
    1. Das 1. Formular veröffentlicht den ToolStripSplitButton1 über eine Eigenschaft (Property) oder eine Methode, die von Form2 aufgerufen werden kann.
    2. Der Form2 wird ein Verweis auf das 1. Formular übergeben (in VB könnte das ein Modul als Brückenkopf sein, in C# ein überladener Constructor).
    3. Wenn im Form2 die TextBox verlassen wird, ruft Form2 über den Verweis die öffentliche Methode des 1. Formulars auf.

    Comment


    • #3
      Hallo Stefan!

      Hier ein Beispiel zu der von Andreas beschriebenen Weise.

      1. Form, welche den Button enthaelt:
      Code:
      /// <summary>
      /// Public property for setting the toolstripbutton's caption
      /// </summary>
      public string SetButtonCaption
      {
          set
          {
              // Set the caption and refresh / invalidate the button
              this.toolStripButton1.Text = value;
              this.toolStripButton1.Invalidate();
          }
      }
      
      /// <summary>
      /// Open a second form and pass the current form as reference
      /// </summary>
      /// <param name="sender"></param>
      /// <param name="e"></param>
      private void btnForm2_Click(object sender, EventArgs e)
      {
          ToolstripForm2 frm = new ToolstripForm2(this);
          frm.Show();
      }
      2. Form, welche den Text fuer den Button setzt:
      Code:
      /// <summary>
      /// Overloaded constructor which takes a form as parameter
      /// </summary>
      /// <param name="callingForm"></param>
      public ToolstripForm2(Form callingForm)
          : this()
      {
          // save a reference of the parent form inside this property
          this.CallingForm = callingForm;
      }
      
      private Form _callingForm;
      /// <summary>
      /// Reference to the parent form (from constructor)
      /// </summary>
      public Form CallingForm
      {
          get { return this._callingForm; }
          set { this._callingForm = value; }
      }
      
      private void button1_Click(object sender, EventArgs e)
      {
          // pass the given text to the parent's form property (TStriptButtonCaption)
          (this.CallingForm as ToolstripForm).SetButtonCaption = this.textBox1.Text;
      }
      *-- robert.oh. --*

      Comment


      • #4
        Es handelt sich im Vb.Net und dafür geht leider beides nicht . Oder ich setzte es Falsch um. Bleibt mur wohl erst mal nur der Weg über Registry oder ini.

        Comment


        • #5
          Das obige Beispiel funktioniert auch in VB.NET - zwar nicht mit dem selben Code, aber die Funktionsweise bleibt gleich.
          *-- robert.oh. --*

          Comment

          Working...
          X