Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. General programming ideea, just so I go the right way

General programming ideea, just so I go the right way

Scheduled Pinned Locked Moved C#
csharpquestionvisual-studiotutoriallounge
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sodevrom
    wrote on last edited by
    #1

    Hello, I am just starting out with C# and I need an ideea on how to go ahead with my software. This is not a direct programming question but more like a programming approach. I am making an application in c# and .net (vs 20008) and my software contains a tab control. I add tabs in the tab control from 5 buttons (each button adds a different tab). The tabs will contain different forms in it. Now I store every tab in a list, just so I can delete them with ease. Now for my dilema. Each of the 5 buttons creates a different object, a different form (a window that contains forms) in the tab. It's easy to store the tabs in a list becouse they all have the same type. Give me an ideea on how I can store different objects in the tab control (so every tab of the tab control will have a single object). I need to know what object I have in a tab, so that when I delete the tab, I also delete the object. I don't know if I explain correctly, but I here is an image below, just so you have a better picture of what I want : www.sodevrom.net/object1.jpg So here is what I have got so far : *************a list that contains the tabs : public List lTabs=new List(); *************I add the tabs like this : (the text deppends on what button I click on) lTabs.Add(new TabPage()); lTabs[lTabs.Count - 1].Text = "Button 1"; cTab.Controls.Add(lTabs[lTabs.Count - 1]); *************I delete the tabs like this : lTabs[0].Dispose(); So how can I asign some objects so I can do something like this : lObjs[lObjs.Count - 1]=new Object1 ( or object 2 or object 3 deppending on the button I press) and lObjs.destroy(); Thank you in advance

    L 1 Reply Last reply
    0
    • S sodevrom

      Hello, I am just starting out with C# and I need an ideea on how to go ahead with my software. This is not a direct programming question but more like a programming approach. I am making an application in c# and .net (vs 20008) and my software contains a tab control. I add tabs in the tab control from 5 buttons (each button adds a different tab). The tabs will contain different forms in it. Now I store every tab in a list, just so I can delete them with ease. Now for my dilema. Each of the 5 buttons creates a different object, a different form (a window that contains forms) in the tab. It's easy to store the tabs in a list becouse they all have the same type. Give me an ideea on how I can store different objects in the tab control (so every tab of the tab control will have a single object). I need to know what object I have in a tab, so that when I delete the tab, I also delete the object. I don't know if I explain correctly, but I here is an image below, just so you have a better picture of what I want : www.sodevrom.net/object1.jpg So here is what I have got so far : *************a list that contains the tabs : public List lTabs=new List(); *************I add the tabs like this : (the text deppends on what button I click on) lTabs.Add(new TabPage()); lTabs[lTabs.Count - 1].Text = "Button 1"; cTab.Controls.Add(lTabs[lTabs.Count - 1]); *************I delete the tabs like this : lTabs[0].Dispose(); So how can I asign some objects so I can do something like this : lObjs[lObjs.Count - 1]=new Object1 ( or object 2 or object 3 deppending on the button I press) and lObjs.destroy(); Thank you in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      I'm not sure I understand the problem correctly, but you can always add an arbitrary number of controls to a Control via its Controls collection. In your case it would look like this:

      	private void button\_Click(object sender, EventArgs e)
      	{
      		TabPage tabPage = new TabPage(((Button)sender).Text);
      
      		Label label = new Label();
      		label.Text = "Label";
      		label.Location = new Point(10, 10);
      		label.Size = new Size(100, 36);
      
      		Button button = new Button();
      		button.Text = "Button";
      		button.Location = new Point(10, 50);
      		button.Size = new Size(100, 36);
      
      		tabPage.Controls.Add(label);
      		tabPage.Controls.Add(button);
      
      		tabControl1.TabPages.Add(tabPage);
      	}
      

      There's no need to manually destroy the controls unless they need to be disposed. regards

      S 1 Reply Last reply
      0
      • L Lost User

        I'm not sure I understand the problem correctly, but you can always add an arbitrary number of controls to a Control via its Controls collection. In your case it would look like this:

        	private void button\_Click(object sender, EventArgs e)
        	{
        		TabPage tabPage = new TabPage(((Button)sender).Text);
        
        		Label label = new Label();
        		label.Text = "Label";
        		label.Location = new Point(10, 10);
        		label.Size = new Size(100, 36);
        
        		Button button = new Button();
        		button.Text = "Button";
        		button.Location = new Point(10, 50);
        		button.Size = new Size(100, 36);
        
        		tabPage.Controls.Add(label);
        		tabPage.Controls.Add(button);
        
        		tabControl1.TabPages.Add(tabPage);
        	}
        

        There's no need to manually destroy the controls unless they need to be disposed. regards

        S Offline
        S Offline
        sodevrom
        wrote on last edited by
        #3

        Hi, Thank you for the reply but my question is more on how to go on with C#, a technique on how to think. But anyways, if I add controls in a tab page, and if I delete the tab page, are the controls from the tab page auto deleted ? And again, let say I want to refer to an object that I added in a tab page, how can I add it so I can keep evidence of where the object is. Let me give you a better example : Tab Control ->Tab Page1 ->object1 (generated from class Object1) ->Tab Page2 ->object2 (generated from class Object1) ->Tab Page3 ->object3 (generated from class Object2). How can I store the 3 objects so I can access them with ease. As I sayed, I can access the tab pages very easy : lTabs[0] I can't do the save for the objects. I would want to make it like this : lOBj[0] I can't do that becouse object1, and 3 (or 2 and 3) are different, and I can't make a list to store objects from different classes, right ? Did I explain good now ?

        L 1 Reply Last reply
        0
        • S sodevrom

          Hi, Thank you for the reply but my question is more on how to go on with C#, a technique on how to think. But anyways, if I add controls in a tab page, and if I delete the tab page, are the controls from the tab page auto deleted ? And again, let say I want to refer to an object that I added in a tab page, how can I add it so I can keep evidence of where the object is. Let me give you a better example : Tab Control ->Tab Page1 ->object1 (generated from class Object1) ->Tab Page2 ->object2 (generated from class Object1) ->Tab Page3 ->object3 (generated from class Object2). How can I store the 3 objects so I can access them with ease. As I sayed, I can access the tab pages very easy : lTabs[0] I can't do the save for the objects. I would want to make it like this : lOBj[0] I can't do that becouse object1, and 3 (or 2 and 3) are different, and I can't make a list to store objects from different classes, right ? Did I explain good now ?

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          sodevrom wrote:

          But anyways, if I add controls in a tab page, and if I delete the tab page, are the controls from the tab page auto deleted ?

          Unless the controls contain no unmanaged resources there should be no problems, but I'm not entirely sure myself.

          sodevrom wrote:

          How can I store the 3 objects so I can access them with ease. As I sayed, I can access the tab pages very easy : lTabs[0] I can't do the save for the objects. I would want to make it like this : lOBj[0] I can't do that becouse object1, and 3 (or 2 and 3) are different, and I can't make a list to store objects from different classes, right ?

          Do you want to store multiple objects per tab page or only one object per tab page? If it's only one object per tab page, then you can put it into the Tag property of the tab page and access it like that: object obj = lTabs[index].Tag If you want to store multiple objects per tab page, then you could also store a List<object> into the Tag property. Another solution would be to store this array in a Dictionary<TabPage, List<object>> and access the list ob objects via List<object> objects = dic[TabPage]; regards

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups