none
tabControl RRS feed

  • Frage

  • hallo,

    ich habe erst mit c# angefangen und habe nun schon einiges ausprobiert, wie Textboxen etc. Ich habe nun ein TabControl eingefügt, diese auch benannt. Nun stellt sich mir die Frage, wie ich Texte dort einfügen kann?


    Gruß

    Mittwoch, 14. September 2011 06:53

Antworten

  • int a = 3 + 4

    // a bei klcick auf tabPage3 anzeigen??

    Du kannst keinen Text anzeigen, dafür brauchst Du ein Control (bspw. Textbox, Label, ...) in der Registerkarte, in dem Du dann den gewünschten Inhalt anzeigen kannst.

     


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    • Als Antwort markiert as_1985 Mittwoch, 14. September 2011 08:30
    • Tag als Antwort aufgehoben as_1985 Mittwoch, 14. September 2011 08:30
    • Als Antwort markiert as_1985 Mittwoch, 14. September 2011 08:31
    Mittwoch, 14. September 2011 07:47
    Moderator
  • Hallo A.,

    • ... // a bei klcick auf tabPage3 anzeigen??

    zum Beispiel so:

        private void tabPage3_Click(object sender, System.EventArgs e)
        {
          int a = 3 + 4;
          if (!tabPage3.Controls.ContainsKey("textBox1"))
          {
            TextBox textbox1 = new TextBox();
            tabPage3.Controls.Add(textBox1);
          }
          tabPage3.Controls["textBox1"].Text = a.ToString();
        }
    


    normal hat man aber eben, wie ich schon gesagt hatte, ein TextBox-Control (o.ä.) in die TabPage zugefügt und setzt dann nur noch die Text-Eigenschaft des TextBox-Controls.

     


    ciao Frank
    • Als Antwort markiert as_1985 Mittwoch, 14. September 2011 08:30
    Mittwoch, 14. September 2011 08:22

Alle Antworten

  • Hallo A.,
    Du ziehst normal einfach Control, wie zum Beispiel eine TextBox (oder zum Beispiel ein Label), aus der ToolBox in die gewünschte Registerkarte. Man kann über den kleinen Pfeil rechts oben an dem TabControl auch eine neue Registerkarte zufügen.
    [Galileo Computing :: Visual C# 2008 – 14.18 Registerkarten mit »TabControl«]
    http://openbook.galileocomputing.de/visual_csharp/visual_csharp_14_018.htm
    Hier auch mal ein Demo-Code, der nur Code benutzt, um ein TabControl zu erzeugen (ähnlich dem aus der MSDN) :
    // Form1.Designer.cs löschen
    using System.Windows.Forms;
    using System.ComponentModel;
    using System.Drawing;
    
    namespace WinTabDemo // ggf. mit dem Namespace Deiner App ersetzen
    {
      public partial class Form1 : Form
      {
        private Container components;
        private RadioButton tab3RadioButton2;
        private RadioButton tab3RadioButton1;
        private CheckBox tab2CheckBox3;
        private CheckBox tab2CheckBox2;
        private CheckBox tab2CheckBox1;
        private Label tab1Label1;
        private Button tab1Button1;
        private TabPage tabPage3;
        private TabPage tabPage2;
        private TabPage tabPage1;
        private TabControl tabControl1;
    
        public Form1()
        {
          InitializeComponent();
        }
    
        private void InitializeComponent()
        {
          components = new Container();
          tabPage1 = new TabPage();
          tab2CheckBox3 = new CheckBox();
          tab3RadioButton2 = new RadioButton();
          tabControl1 = new TabControl();
          tab2CheckBox2 = new CheckBox();
          tab2CheckBox1 = new CheckBox();
          tab3RadioButton1 = new RadioButton();
          tab1Label1 = new Label();
          tabPage3 = new TabPage();
          tabPage2 = new TabPage();
          tab1Button1 = new Button();
    
          tabPage1.Text = "tabPage1";
          tabPage1.Size = new Size(256, 214);
          tabPage1.TabIndex = 0;
          tab2CheckBox3.Location = new Point(32, 136);
          tab2CheckBox3.Text = "checkBox3";
          tab2CheckBox3.Size = new Size(176, 32);
          tab2CheckBox3.TabIndex = 2;
          tab2CheckBox3.Visible = true;
          tab3RadioButton2.Location = new Point(40, 72);
          tab3RadioButton2.Text = "radioButton2";
          tab3RadioButton2.Size = new Size(152, 24);
          tab3RadioButton2.TabIndex = 1;
          tab3RadioButton2.Visible = true;
          tabControl1.Location = new Point(16, 16);
          tabControl1.Size = new Size(264, 240);
          tabControl1.SelectedIndex = 0;
          tabControl1.TabIndex = 0;
          tab2CheckBox2.Location = new Point(32, 80);
          tab2CheckBox2.Text = "checkBox2";
          tab2CheckBox2.Size = new Size(176, 32);
          tab2CheckBox2.TabIndex = 1;
          tab2CheckBox2.Visible = true;
          tab2CheckBox1.Location = new Point(32, 24);
          tab2CheckBox1.Text = "checkBox1";
          tab2CheckBox1.Size = new Size(176, 32);
          tab2CheckBox1.TabIndex = 0;
          tab3RadioButton1.Location = new Point(40, 32);
          tab3RadioButton1.Text = "radioButton1";
          tab3RadioButton1.Size = new Size(152, 24);
          tab3RadioButton1.TabIndex = 0;
          tab1Label1.Location = new Point(16, 24);
          tab1Label1.Text = "label1";
          tab1Label1.Size = new Size(224, 96);
          tab1Label1.TabIndex = 1;
          tabPage3.Text = "tabPage3";
          tabPage3.Size = new Size(256, 214);
          tabPage3.TabIndex = 2;
          tabPage2.Text = "tabPage2";
          tabPage2.Size = new Size(256, 214);
          tabPage2.TabIndex = 1;
          tab1Button1.Location = new Point(88, 144);
          tab1Button1.Size = new Size(80, 40);
          tab1Button1.TabIndex = 0;
          tab1Button1.Text = "button1";
          tab1Button1.Click += tab1Button1_Click;
          Text = "Form1";
    
          tabPage2.Controls.Add(tab2CheckBox3);
          tabPage2.Controls.Add(tab2CheckBox2);
          tabPage2.Controls.Add(tab2CheckBox1);
    
          tabPage3.Controls.Add(tab3RadioButton2);
          tabPage3.Controls.Add(tab3RadioButton1);
    
          tabPage1.Controls.Add(tab1Label1);
          tabPage1.Controls.Add(tab1Button1);
    
          Controls.Add(tabControl1);
    
          tabControl1.Controls.Add(tabPage1);
          tabControl1.Controls.Add(tabPage2);
          tabControl1.Controls.Add(tabPage3);
        }
    
        private void tab1Button1_Click(object sender, System.EventArgs e)
        {
          MessageBox.Show((sender as Button).Text + " geklickt");
        }
      }
    }
    

    ciao Frank
    Mittwoch, 14. September 2011 07:20
  • Nun, wie ich Registerkarten adde, etc weiß ich und habe ich bereits getan. Habe allerdings Probleme Text dahinein zu bekommen, z.b.

    private void tabPage3_Click(object sender, EventArgs e)

    {

    int a = 3 + 4

    // a bei klcick auf tabPage3 anzeigen??

    }

    Mittwoch, 14. September 2011 07:42
  • int a = 3 + 4

    // a bei klcick auf tabPage3 anzeigen??

    Du kannst keinen Text anzeigen, dafür brauchst Du ein Control (bspw. Textbox, Label, ...) in der Registerkarte, in dem Du dann den gewünschten Inhalt anzeigen kannst.

     


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET
    http://www.asp-solutions.de/ - Consulting, Development
    http://www.aspnetzone.de/ - ASP.NET Zone, die ASP.NET Community
    • Als Antwort markiert as_1985 Mittwoch, 14. September 2011 08:30
    • Tag als Antwort aufgehoben as_1985 Mittwoch, 14. September 2011 08:30
    • Als Antwort markiert as_1985 Mittwoch, 14. September 2011 08:31
    Mittwoch, 14. September 2011 07:47
    Moderator
  • Hallo A.,

    • ... // a bei klcick auf tabPage3 anzeigen??

    zum Beispiel so:

        private void tabPage3_Click(object sender, System.EventArgs e)
        {
          int a = 3 + 4;
          if (!tabPage3.Controls.ContainsKey("textBox1"))
          {
            TextBox textbox1 = new TextBox();
            tabPage3.Controls.Add(textBox1);
          }
          tabPage3.Controls["textBox1"].Text = a.ToString();
        }
    


    normal hat man aber eben, wie ich schon gesagt hatte, ein TextBox-Control (o.ä.) in die TabPage zugefügt und setzt dann nur noch die Text-Eigenschaft des TextBox-Controls.

     


    ciao Frank
    • Als Antwort markiert as_1985 Mittwoch, 14. September 2011 08:30
    Mittwoch, 14. September 2011 08:22
  • Alles klar, vielen Dank - hat mir geholfen.
    Mittwoch, 14. September 2011 08:30