TabPage...Better/Simpler way

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • meh

    TabPage...Better/Simpler way

    I'm not sure if I have the right concept going. I am making a custom TabPage and executing it from a button click event. It works fine I'm just thinking I might be missing the finer points of the c# language. If not maybe I'm starting to catch on. Would like comments...bett er???...simpler ???...

    Here is the code....

    tia
    meh

    // Build New Tab Page
    //
    string title = "tabPage" + (tabControl1.Ta bCount + 1).ToString();
    TabPage myTabPage = new TabPage(title);
    tabControl1.Tab Pages.Add(myTab Page);
    //
    // Build New tabPage with treeView1
    //
    TreeView CurrTree = new TreeView();
    CurrTree.Dock = System.Windows. Forms.DockStyle .Fill;
    CurrTree.ImageI ndex = -1;
    CurrTree.Indent = 19;
    CurrTree.ItemHe ight = 16;
    CurrTree.Locati on = new System.Drawing. Point(0, 44);
    CurrTree.Name = "CurrTree" + (tabControl1.Ta bCount).ToStrin g();
    CurrTree.Select edImageIndex = -1;
    CurrTree.Size = new System.Drawing. Size(292, 428);
    CurrTree.TabInd ex = 3;
    // Adds new node as a child node of the currently selected node.
    TreeNode newNode = new TreeNode();
    newNode.Text = "Text for new node";
    newNode.ImageIn dex = 0;
    newNode.Selecte dImageIndex = 1;
    CurrTree.Nodes. Add(newNode);
    CurrTree.Select edNode = newNode;
    //
    // Build New tabPage with myComboBox
    //
    ComboBox myComboBox = new ComboBox();

    myComboBox.Dock = System.Windows. Forms.DockStyle .Top;
    myComboBox.Item Height = 13;
    myComboBox.Loca tion = new System.Drawing. Point(0, 23);
    myComboBox.Name = "comboBox" + (tabControl1.Ta bCount).ToStrin g();
    myComboBox.Size = new System.Drawing. Size(292, 21);
    myComboBox.TabI ndex = 2;
    myComboBox.Text = "comboBox" + (tabControl1.Ta bCount).ToStrin g();
    //
    myTabPage.Contr ols.Add(CurrTre e);
    myTabPage.Contr ols.Add(myCombo Box);
    //
    // keep the toolbar
    myTabPage.Contr ols.Add(tabTool Bar);
    //
    //
    tabControl1.Sel ectedTab = myTabPage;
    myTabPage.Text = CurrTree.Name;
    statusBar1.Pane ls[0].Text = myTabPage.Text;
    // tabToolBar.Brin gToFront();
    break;










  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: TabPage...Bette r/Simpler way

    meh,

    What you are doing basically seems correct. I am curious though, are
    you trying to do this dynamically? Is there a need to do it dynamically?
    If not, I would let the designer handle all of this.

    Hope this helps.

    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "meh" <nospammehogber g@cox.net> wrote in message
    news:OkRgZIsREH A.3504@TK2MSFTN GP09.phx.gbl...
    I'm not sure if I have the right concept going. I am making a custom
    TabPage and executing it from a button click event. It works fine I'm just
    thinking I might be missing the finer points of the c# language. If not
    maybe I'm starting to catch on. Would like
    comments...bett er???...simpler ???...

    Here is the code....

    tia
    meh

    // Build New Tab Page
    //
    string title = "tabPage" + (tabControl1.Ta bCount + 1).ToString();
    TabPage myTabPage = new TabPage(title);
    tabControl1.Tab Pages.Add(myTab Page);
    //
    // Build New tabPage with treeView1
    //
    TreeView CurrTree = new TreeView();
    CurrTree.Dock = System.Windows. Forms.DockStyle .Fill;
    CurrTree.ImageI ndex = -1;
    CurrTree.Indent = 19;
    CurrTree.ItemHe ight = 16;
    CurrTree.Locati on = new System.Drawing. Point(0, 44);
    CurrTree.Name = "CurrTree" + (tabControl1.Ta bCount).ToStrin g();
    CurrTree.Select edImageIndex = -1;
    CurrTree.Size = new System.Drawing. Size(292, 428);
    CurrTree.TabInd ex = 3;
    // Adds new node as a child node of the currently selected node.
    TreeNode newNode = new TreeNode();
    newNode.Text = "Text for new node";
    newNode.ImageIn dex = 0;
    newNode.Selecte dImageIndex = 1;
    CurrTree.Nodes. Add(newNode);
    CurrTree.Select edNode = newNode;
    //
    // Build New tabPage with myComboBox
    //
    ComboBox myComboBox = new ComboBox();

    myComboBox.Dock = System.Windows. Forms.DockStyle .Top;
    myComboBox.Item Height = 13;
    myComboBox.Loca tion = new System.Drawing. Point(0, 23);
    myComboBox.Name = "comboBox" + (tabControl1.Ta bCount).ToStrin g();
    myComboBox.Size = new System.Drawing. Size(292, 21);
    myComboBox.TabI ndex = 2;
    myComboBox.Text = "comboBox" + (tabControl1.Ta bCount).ToStrin g();
    //
    myTabPage.Contr ols.Add(CurrTre e);
    myTabPage.Contr ols.Add(myCombo Box);
    //
    // keep the toolbar
    myTabPage.Contr ols.Add(tabTool Bar);
    //
    //
    tabControl1.Sel ectedTab = myTabPage;
    myTabPage.Text = CurrTree.Name;
    statusBar1.Pane ls[0].Text = myTabPage.Text;
    // tabToolBar.Brin gToFront();
    break;


    Comment

    • meh

      #3
      Re: TabPage...Bette r/Simpler way

      Thanks Nick for the reply...
      Yes I am trying to do this dynamically.
      Yes there is a need
      Impossible to know ahead of time what the user will do with this. This was
      part of the spec ... that the user can "auto generate" multiple tabPages.
      I am migrating over to C# from VB and am using this to try out a more c#
      oriented philosophy.
      I know there was a bug in VB when distroying tab pages....but I have not run
      into that using C#.
      Again thanks for the feedback...


      meh
      "Nicholas Paldino [.NET/C# MVP]" <mvp@spam.guard .caspershouse.c om> wrote in
      message news:%23i%23xeH lTEHA.3844@TK2M SFTNGP11.phx.gb l...[color=blue]
      > meh,
      >
      > What you are doing basically seems correct. I am curious though, are
      > you trying to do this dynamically? Is there a need to do it dynamically?
      > If not, I would let the designer handle all of this.
      >
      > Hope this helps.
      >
      > --
      > - Nicholas Paldino [.NET/C# MVP]
      > - mvp@spam.guard. caspershouse.co m
      >
      > "meh" <nospammehogber g@cox.net> wrote in message
      > news:OkRgZIsREH A.3504@TK2MSFTN GP09.phx.gbl...
      > I'm not sure if I have the right concept going. I am making a custom
      > TabPage and executing it from a button click event. It works fine I'm[/color]
      just[color=blue]
      > thinking I might be missing the finer points of the c# language. If not
      > maybe I'm starting to catch on. Would like
      > comments...bett er???...simpler ???...
      >
      > Here is the code....
      >
      > tia
      > meh
      >
      > // Build New Tab Page
      > //
      > string title = "tabPage" + (tabControl1.Ta bCount + 1).ToString();
      > TabPage myTabPage = new TabPage(title);
      > tabControl1.Tab Pages.Add(myTab Page);
      > //
      > // Build New tabPage with treeView1
      > //
      > TreeView CurrTree = new TreeView();
      > CurrTree.Dock = System.Windows. Forms.DockStyle .Fill;
      > CurrTree.ImageI ndex = -1;
      > CurrTree.Indent = 19;
      > CurrTree.ItemHe ight = 16;
      > CurrTree.Locati on = new System.Drawing. Point(0, 44);
      > CurrTree.Name = "CurrTree" + (tabControl1.Ta bCount).ToStrin g();
      > CurrTree.Select edImageIndex = -1;
      > CurrTree.Size = new System.Drawing. Size(292, 428);
      > CurrTree.TabInd ex = 3;
      > // Adds new node as a child node of the currently selected node.
      > TreeNode newNode = new TreeNode();
      > newNode.Text = "Text for new node";
      > newNode.ImageIn dex = 0;
      > newNode.Selecte dImageIndex = 1;
      > CurrTree.Nodes. Add(newNode);
      > CurrTree.Select edNode = newNode;
      > //
      > // Build New tabPage with myComboBox
      > //
      > ComboBox myComboBox = new ComboBox();
      >
      > myComboBox.Dock = System.Windows. Forms.DockStyle .Top;
      > myComboBox.Item Height = 13;
      > myComboBox.Loca tion = new System.Drawing. Point(0, 23);
      > myComboBox.Name = "comboBox" + (tabControl1.Ta bCount).ToStrin g();
      > myComboBox.Size = new System.Drawing. Size(292, 21);
      > myComboBox.TabI ndex = 2;
      > myComboBox.Text = "comboBox" + (tabControl1.Ta bCount).ToStrin g();
      > //
      > myTabPage.Contr ols.Add(CurrTre e);
      > myTabPage.Contr ols.Add(myCombo Box);
      > //
      > // keep the toolbar
      > myTabPage.Contr ols.Add(tabTool Bar);
      > //
      > //
      > tabControl1.Sel ectedTab = myTabPage;
      > myTabPage.Text = CurrTree.Name;
      > statusBar1.Pane ls[0].Text = myTabPage.Text;
      > // tabToolBar.Brin gToFront();
      > break;
      >
      >[/color]


      Comment

      Working...