12 Replies - 381 Views - Last Post: 14 May 2019 - 04:10 AM Rate Topic: -----

#1 Gamezdude   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 03-July 14

Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 01:47 PM

Hi All

Im trying to make my program add a new tabpage with a textbox inside. Ive looked around the net and cannot find a solution that works.

What am I doing wrong?

private TextBox txtBoxClone = new TextBox();
        private TabPage tabPageClone = new TabPage();

        public Form1()
        {
            InitializeComponent();
            txtBoxClone.Multiline = true;
            txtBoxClone.ReadOnly = true;
            txtBoxClone.Location = new Point(6, 6);
            txtBoxClone.Size = new Size(380, 315);
        }

private void LoadModules(int fileQty)
        {
            for (int i = 1; i <= fileQty; i++)
            {
                Console.WriteLine("i = " + i);
                tabPageClone.Name = "tabPageMod" + i;
                tabPageClone.Text = "Module " + i;

                Console.WriteLine("Text: " + tabPageClone.Text + "Name: " + tabPageClone.Name);

                tabPageClone.Controls.Add(txtBoxClone);
                txtBoxClone.Location = new Point(25, 25);

                tabMenu.TabPages.Add(tabPageClone);
            }
        }
            }


Is This A Good Question/Topic? 0
  • +

Replies To: Visual Studio, How to make a Tab Page with a Textbox inside?

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15063
  • View blog
  • Posts: 60,150
  • Joined: 12-June 08

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 01:50 PM

What's the project type? Winform? WPF? ASP.NET 4? Razor/Core 2.1?
Was This Post Helpful? 0
  • +
  • -

#3 Gamezdude   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 03-July 14

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 02:00 PM

I believe its Winform

Edit: Or it might be WPF. If im to be honest, im going by memory and I dont know how to find out. I did some google'ing and nothing made sense to whats in front of me.

This post has been edited by Skydiver: 14 May 2019 - 04:09 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15063
  • View blog
  • Posts: 60,150
  • Joined: 12-June 08

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 02:19 PM

Let's take a step back. Where is this project coming from and why is bits 'from memory'? That seems.. odd.

To be clear the app runs on a desktop, somewhere, right? It's not a website?
Was This Post Helpful? 0
  • +
  • -

#5 Gamezdude   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 03-July 14

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 02:22 PM

It does run on desktop :)/>
When I boot up Visual Studio, it gives me the option to choose a template. I recall choosing either WinForm or WPF.

This post has been edited by Skydiver: 14 May 2019 - 04:09 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#6 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15063
  • View blog
  • Posts: 60,150
  • Joined: 12-June 08

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 02:34 PM

So the mystery continues. I take it this is not a new project?

When looking at your solution explorer, and the solution is open, do you see '.designer' or '.resx' files or '.xaml'?
Was This Post Helpful? 0
  • +
  • -

#7 Gamezdude   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 03-July 14

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 02:40 PM

I have...
Form1.Designer.cs (Not sure if it counts as .designer)
Form1.resx
Resources.resx
Resources.Designer.cs

This post has been edited by Skydiver: 14 May 2019 - 04:08 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#8 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15063
  • View blog
  • Posts: 60,150
  • Joined: 12-June 08

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 02:50 PM

Woah.. okay.. so Let's go with this is a winform C# project.

If you look at the documentation for a winform tab control you'll notice there is a collection for 'tab pages'.

It's also called out here:

Quote

A TabControl contains tab pages, which are represented by TabPage objects that you add through the TabPages property.
https://docs.microso...etframework-4.8

I would thing the most illustrative way to do this would be to create an instance of a tab page. Give it a name, add your textbox control to that, etc, and then add that entire object to your control via the 'tabpages' property/collection of the control.
Was This Post Helpful? 0
  • +
  • -

#9 Gamezdude   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 03-July 14

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 03:02 PM

Im already getting frostbitten feet now...
As far as im aware, thats literally what I did. I made the instance, named it, added a textbox to it and added it to the control.
private TextBox txtBoxClone = new TextBox();
        private TabPage tabPageClone = new TabPage();

        public Form1()
        {
            InitializeComponent();
            txtBoxClone.Multiline = true;
            txtBoxClone.ReadOnly = true;
            txtBoxClone.Location = new Point(6, 6);
            txtBoxClone.Size = new Size(380, 315);
        }

private void LoadModules(int fileQty)
        {
            for (int i = 1; i <= fileQty; i++)
            {
                Console.WriteLine("i = " + i);
                tabPageClone.Name = "tabPageMod" + i;
                tabPageClone.Text = "Module " + i;

                Console.WriteLine("Text: " + tabPageClone.Text + "Name: " + tabPageClone.Name);

                tabPageClone.Controls.Add(txtBoxClone);
                txtBoxClone.Location = new Point(25, 25);

                tabMenu.TabPages.Add(tabPageClone);
            }
        }
            }

This post has been edited by Skydiver: 14 May 2019 - 04:09 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#10 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15063
  • View blog
  • Posts: 60,150
  • Joined: 12-June 08

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 03:05 PM

Okay? Now explain to folk why that isn't working.

Is there an error? If so copy/paste it here.

Is it producing unexpected results? If so explain what is happening vs what is supposed to be happening.

I'm not certain why you have those as global variables, but would highly recommend making them local to the function.
Was This Post Helpful? 0
  • +
  • -

#11 Gamezdude   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 03-July 14

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 03:22 PM

Ok. There are No errors. No unexpected results.
What is supposed to happen, is in every tab created, there should be a textbox inside.

Im assuming I did something wrong with the code.

Its as Black and White as that. I have no other information telling my otherwise.

I shall heed your recommendation and make those variables local.

I had to retype this post 3 times (incase I come across as rude) as its really starting to :censored:/>/>/> me off. So im going to call it a day.

This post has been edited by Skydiver: 14 May 2019 - 04:10 AM
Reason for edit:: Removed unnecessary quote. No need to quote the post above yours.

Was This Post Helpful? 0
  • +
  • -

#12 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 223
  • View blog
  • Posts: 1,260
  • Joined: 05-December 13

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 13 May 2019 - 04:57 PM

You can iterate the current collection of TabPages, and then when you land on the one you want, add your controls to it. Do this ::
        TextBox tb1 = new TextBox();
        TabPage tp1 = new TabPage();
        public Form1()
        {
            InitializeComponent();
            tabControl1.TabPages.Add("NewTab");
            
            foreach (TabPage tabPage in tabControl1.TabPages)
            {
                if (tabPage.Text == "NewTab")
                {
                    tb1.Name = "tbox1";
                    tb1.Text = "Hello";
                    tabPage.Controls.Add(tb1);
                }
                
            }
        }

If you are using a TabPage created dynamically, then you need to set that TabPages properties before adding it to the collection of new tabpages. Like this ::
        TextBox tb1 = new TextBox();
        TabPage tp1 = new TabPage();
        public Form1()
        {
            InitializeComponent();
            tp1.Text = "NewTab";
            tp1.Name = "NewTabPage1";
            tabControl1.TabPages.Add(tp1);
            
            foreach (TabPage tabPage in tabControl1.TabPages)
            {
                if (tabPage.Text == "NewTab")
                {
                    tb1.Name = "tbox1";
                    tb1.Text = "Hello";
                    tabPage.Controls.Add(tb1);
                }
                
            }
        }


Hope this helps.
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 6914
  • View blog
  • Posts: 23,508
  • Joined: 05-May 12

Re: Visual Studio, How to make a Tab Page with a Textbox inside?

Posted 14 May 2019 - 04:10 AM

Gamezdude: There is no need to quote the post above yours. Just use the big Reply button or the Fast Reply area.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1