Page 1 of 2 12 LastLast
Results 1 to 40 of 47

Thread: classes

  1. #1

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729

    classes

    PHP Code:
        class mother
        
    {
            public 
    void myMain()
            {
            }

            class 
    child
            
    {
                public 
    void test()
                {
                }
            }
        } 
    well..how can i make that the child class can access the myMain function in the mother class?

  2. #2
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    PHP Code:
    public class Mother
    {
        public 
    void myMain()
        {
            
    MessageBox.Show("myMain");
        }

        class 
    child
        
    {
            
    Mother mother = new Mother();

            public 
    void test()
            {
                
    mother.myMain();
            }
        }

    Dont gain the world and lose your soul

  3. #3

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    yea but i dont want a NEW mother...i want to use that instanciated class mother..what i really want to do is a class that has inside itself a collection of all items...the class itself is the mother, and the collection is a class inherited from BaseCollection or DicitionaryCollection..and i want that when i add a new item to the child class(the collection) it at the same time executes a command in the mother class (the mother class is inherited from a tabPage, and i want that when a new item to the collection is added it calls a function that will draw a button into the panel)...well...how i am supose to do this?

  4. #4
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    maybe this?
    PHP Code:
    using System;
    using System.Collections;
    namespace 
    NestedClassTest
    {
        public class 
    MainApp
        
    {
            public static 
    void Main(string[] args)
            {
                
    Mother mother = new Mother();
                
    mother.AddChild(new Mother.Child("Sally"));
                
    mother.AddChild(new Mother.Child("Chris"));
                
                
    Console.ReadLine();
            }
        }

        public class 
    Mother
        
    {
            private 
    ArrayList children = new ArrayList();
            public 
    void DrawButton(object obj)
            {
                
    Console.WriteLine("Drawing button for {0}...",((Child)obj).name);
            }
            public 
    void RemoveButton(object obj)
            {
                
    Console.WriteLine("Removing button for {0}...", ((Child)obj).name );
            }
            public 
    void AddChild(object obj)
            {
                
    children.Add(obj);
                
    DrawButton(obj);
            }
            public 
    void RemoveChild(object obj)
            {
                
    children.Remove(obj);
                
    RemoveButton(obj);
            }
            public class 
    Child
            
    {
                public 
    string name "";
                public 
    Child() {}
                public 
    Child(string name)
                {
                    
    this.name name;
                }
            }
        }



  5. #5
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I tried something similar but it did'nt work. Now I see why. I was instantiating the child class like this:

    Code:
    child chd = new child(); //child was not coming up in intellisense
    Dont gain the world and lose your soul

  6. #6

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm pvb tks..but there should be another way..when u put a listbox in ur form u dont have to put all thhis code to add a new item to the listbox,dont u?
    PHP Code:
                Mother mother = new Mother();
                
    mother.AddChild(new Mother.Child("Sally"));
                
    mother.AddChild(new Mother.Child("Chris")); 
    hmm...arent there any other ways?

  7. #7
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    well, here's the code to load a listbox:
    PHP Code:
    this.listBox1 = new System.Windows.Forms.ListBox();
    this.listBox1.Items.Add("Chris");
    this.listBox1.Items.Add("Sally"); 
    only reason i have a nested class in my example named Child is because the original post had it. If you really didn't want the Child class then you can rewrite it this way:
    PHP Code:
    using System;
    using System.Collections;
    namespace 
    NestedClassTest
    {
        public class 
    MainApp
        
    {
            public static 
    void Main(string[] args)
            {
                
    Mother mother = new Mother();
                
    mother.AddChild("Sally");
                
    mother.AddChild("Chris");
                
    Console.ReadLine();
            }
        }

        public class 
    Mother
        
    {
            private 
    ArrayList children = new ArrayList();
            public 
    void DrawButton(object obj)
            {
                
    Console.WriteLine("Drawing button ... {0}"obj.ToString());
            }
            public 
    void RemoveButton(object obj)
            {
                
    Console.WriteLine("Removing button ... {0}"obj.ToString());
            }
            public 
    void AddChild(object obj)
            {
                
    children.Add(obj);
                
    DrawButton(obj);
            }
            public 
    void RemoveChild(object obj)
            {
                
    children.Remove(obj);
                
    RemoveButton(obj);
            }
        }



  8. #8

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    no man, the Child Class is a BaseCollection class! i want 2 classes, one that is a tabPage and another that is a BaseCollection-inherited class

  9. #9

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    but that ideas isnt bad...hehe lol ..maybe i use a private arraylist and then create my own functions..welll.

  10. #10

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    hmm well...now how do i make that the users make this:

    myClass mclass = new myClass();

    mclass.items.add("...)";

    ??

  11. #11
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    k, how bout this guy:
    PHP Code:
    using System;
    using System.Collections;
    namespace 
    NestedClassTest
    {
        public class 
    MainApp
        
    {
            public static 
    void Main(string[] args)
            {
                
    Mother mother = new Mother();
                
    mother.Items.Add("Chris");
                
    Console.WriteLine(mother[0].ToString());
                
    Console.ReadLine();
            }
        }

        public class 
    Mother
        
    {
            private 
    ArrayList items = new ArrayList();
            public 
    object this[int index]
            {
                
    get
                
    {
                    if (
    index || index > (items.Count 1))
                        throw new 
    IndexOutOfRangeException();
                    else
                        return 
    items[index];
                }            
            }
            public 
    ArrayList Items
            
    {
                
    get { return items; }
            }
        }



  12. #12

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    let me check ..but it looks just like i want it

  13. #13

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i've reed about indexeres and that but i dont understand what is this:

    public object this[int index]
    {
    get
    {
    if (index < 0 || index > (items.Count - 1))
    throw new IndexOutOfRangeException();
    else
    return items[index];
    }
    }

    what is that? i know its a data type but what really?
    \m/\m/

  14. #14
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    it's just the return type of the indexer, so when you do ArrayList.Add, the Add method takes an object as a parameter. Basically all the indexer does is return the same Type that is contained within the ArrayList. So what you have is a really generic collection that can hold anything that's an object. If you know your collection will always only hold strings then the type of the indexer would be "string".

  15. #15
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    Lightbulb

    You could do something like this too:
    PHP Code:
    static void Main(string[] args)
    {
        
    Mother MyMum = new Mother();

        
    // Add children
        
    MyMum.Add"Tommy" );
        
    MyMum.Add"Simon" );
        
    MyMum.Add( new Child("Bill") );
        
    MyMum.Add( new Child("William") );

        
    // Write out child names
        
    Console.WriteLine("Kid1: {0}", ((Child)MyMum[0]).Name);
        
    Console.WriteLine("Kid2: {0}", ((Child)MyMum[1]).Name);
        
    Console.WriteLine("Kid3: {0}", ((Child)MyMum[2]).Name);
        
    Console.WriteLine("Kid4: {0}", ((Child)MyMum[3]).Name);
        
    // or
        
    Console.WriteLine("Kid1: {0}"MyMum[0].ToString());
        
    Console.WriteLine("Kid2: {0}"MyMum[1].ToString());

        
    Console.ReadLine();
    }

    class 
    Mother ArrayList
    {

        
    // Add child by name
        
    public int Add(string NewChildName)
        {
            return 
    base.Add(new Child(NewChildName));
        }

        
    // Add child by a new child object
        
    public override int Add(object NewChild)
        {
            if (
    NewChild.GetType() == Type.GetType("CollectionTest.Child"))
                return 
    base.AddNewChild );
            else
                return 
    base.Count;
        }
    }

    class 
    Child
    {
        private 
    string childName;

        public 
    Child(string Name)
        {
            
    childName Name;
        }

        public 
    string Name
        
    {
            
    get {return childName; }
            
    set {childName value; }
        }

        public 
    override string ToString()
        {
            return 
    childName.ToString();
        }

    It all depends on how you want to use the object (your mother).
    -scott
    he he he

  16. #16

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i changed the type to string but it keeps saying in the IDE intelsense that it's an object ArrayList
    \m/\m/

  17. #17
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    Smile

    PT,
    I think you will have to change the type to string as well as casting the ArrayList to string for the return of the indexer method.
    -scott
    he he he

  18. #18

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah ok tks ill try
    \m/\m/

  19. #19

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    dakmn im getting damn confused..tomorrow ill give another try at this
    \m/\m/

  20. #20
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327

    Wink try this:

    PHP Code:
    public string this[int Index]
    {
        
    get 
        
    {
            
    // exception will be thrown by ArrayList if Index is out of bounds
            
    return Items[Index].ToString();
        }

    -scott
    he he he

  21. #21

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    no, the problem is:

    how do i make that MY commands of the arraylist appear in the .Items part of the class?

    i want by eg put:

    myClass.Items.MakeFolder
    myClass.Items.MakeFile

    how do i make this? i tryed making what someone of u done but i seem to not can do it..i am making something wrong
    \m/\m/

  22. #22
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    Code:
    using System;
    using System.Collections;
    namespace NestedClassTest
    {
    	public class MainApp
    	{
    		public static void Main(string[] args)
    		{
    			MyClass myClass = new MyClass();
    			myClass.Items.MakeFile(@"C:\myfile\something.txt");		
    			myClass.Items.MakeFolder(@"C:\somefolder");
    			Console.ReadLine();
    		}
    	}
    	public class MyClass
    	{
    		private ArrayListEx items = new ArrayListEx();
    		public ArrayListEx Items
    		{
    			get { return items; }
    		}	
    	}
    	public class ArrayListEx : ArrayList
    	{
    		public void MakeFolder(string path)
    		{
    			Console.WriteLine("Making a folder here: {0}", path);
    		}
    		public void MakeFile(string path)
    		{
    			Console.WriteLine("Making a file here: {0}", path);
    		}
    	}
    }

  23. #23

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    but the problem is still the same..if the upper class is a tabPage how do i make that the subclass can draw a button on the tabPage?
    \m/\m/

  24. #24
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    assuming the code from pvb...

    PHP Code:
    interface IDrawButton
    {
        
    DrawButton(int int);
    }

    public class 
    MyApp IDrawButton
    {
        public 
    MyApp()
        {
            
    items.SetDrawInterfacethis );
        }
    ...
    }

    public class 
    ArrayListEx ArrayList
    {
        
    IDrawButton parentToDraw;

        
    // Make a reference to the parent's IDrawButton interface
        
    public void SetDrawInterfaceobject Parent )
        {
            
    parentToDraw = (IDrawButton)Parent;
        }

        
    // Call the parent's DrawButton method though the IDrawButton interface
        
    public void DrawButton()
        {
            
    parentToDraw.DrawButton;
        }
    ...

    Is that what you are trying to do??
    -scott
    he he he

  25. #25

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    no it isnt..when i come from school ill explain again
    \m/\m/

  26. #26

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    the problem is i want it to draw the button in the ADD() of the collection..

    myClass.Items.Add()
    \m/\m/

  27. #27
    Hyperactive Member Scott Penner's Avatar
    Join Date
    Dec 2000
    Location
    Mountain View
    Posts
    327
    I guess I'm still uncertain about what you are trying to accomplish.

    Essentially, anything is possible. You can have your children call into their parent via a reference to the parent object. You can have delegates that the parent consumes. You can inherit from a collection to provide the collection functionality (Parent[n].Method()) or you can use composition to provide the collection functionality (Parent.Kids[n].Method() and Parent.Kids.Method()).

    Maybe you could describe some broader examples a what you are doing (not showing the classes).
    -scott
    he he he

  28. #28

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    did u ever look at a listbox?

    it has what it appears to be an instance of a class called Items...it's probably a collection or something like that but right now it doesnt mattar much...now..when u make ListBox.Items.Add() ur in that moment using the Items class that has a Add function...that function will add to the collection 1item and ALSO will add one line to the GUI(interface) of the listbox...but to add that line to the listbox it somewhat will have to reference the listbox class that is the class that has the Items' class inside.

    i am making a class inheriting from tabPage...i want to have just like a listbox an Items field that inside has some kind of collection...and when i make the tabPage.Items.Add() it adds to the collection 1item and also creates a button on the tabPage...how do i make this?

    was i more explicit now?
    \m/\m/

  29. #29
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    alright, this is it(lol):
    PHP Code:
                    public class PanelEx Panel
        
    {    
            private 
    int height 0;
            private 
    int width 0;
            private 
    int top 0;
            private 
    int left 0;
            private 
    PanelItems items null;

            public 
    PanelItems Items
            
    {
                
    get { return items; }
            }
            public 
    PanelEx()
            {
                
    base.Height height;
                
    base.Width width;
                
    base.Top top;
                
    base.Left top;
                
    items = new PanelItems(this);
            }
            public 
    PanelEx(int Heightint Widthint Topint Left)
            {
                
    base.Height height Height;
                
    base.Width width Width;
                
    base.Top top Top;
                
    base.Left left Left;
                
    items = new PanelItems(this);
            }
            public 
    void CoverForm(Form frm)
            {
                
    this.Height frm.Height;
                
    this.Width frm.Width;
                
    this.Refresh();
            }
            public class 
    PanelItems CollectionBase
            
    {
                private 
    PanelEx parent null;
                private 
    PanelItems(){}
                public 
    PanelItems(PanelEx Parent)
                {
                    
    parent Parent;
                }
                public 
    void Add(string ButtonName)
                {
                    
    Button btn null;
                    if (
    this.List.Count 0)
                    {
                        
    Button lastButton = ((Button)this.List[this.List.Count 1]);
                        
    int newLeft lastButton.Left lastButton.Width;
                        
    btn getButton(ButtonName25500newLeft);
                    }
                    else
                    {
                        
    btn getButton(ButtonName255000);
                    }                
                    
    add(btn);
                }
                public 
    void Add(string ButtonNameint Heightint Width)
                {
                    
    Button btn getButton(ButtonNameHeightWidth00);
                    
    add(btn);
                }
                public 
    void Add(string ButtonNameint Heightint Widthint Topint Left)
                {
                    
    Button btn getButton(ButtonNameHeightWidthTopLeft);
                    
    add(btn);
                }
                private 
    void add(Button btn)
                {
                    
    parent.Controls.Add(btn);
                    
    this.List.Add(btn);
                }
                protected 
    void btn_Click(object senderSystem.EventArgs e)
                {
                    
    MessageBox.Show(((Button)sender).Text);
                }
                private 
    Button getButton(string textint heightint widthint topint left)
                {
                    
    Button btn = new Button();
                    
    btn.Text text;
                    
    btn.Height height;
                    
    btn.Width width;
                    
    btn.Top top;
                    
    btn.Left left;
                    
    btn.Click += new System.EventHandler(btn_Click);
                    return 
    btn;
                }
            }
        } 
    usage, in the Form_Load event put this:
    PHP Code:
    private void Form1_Load(object senderSystem.EventArgs e)
    {
        
    PanelEx myPanel = new PanelEx();
        
    myPanel.CoverForm(this);
        
    myPanel.Items.Add("Chris");
        
    myPanel.Items.Add("Sally");
        
    myPanel.Items.Add("Joe");
        
    this.Controls.Add(myPanel);

    i left out alot of rules, just gives the basic concept. lol, lemme guess, not quite what you're lookin for?

  30. #30

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    it has nothing to do with what i asked!!!

    kiddin..ill look at it now
    \m/\m/

  31. #31

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    very well done..that was what i was looking for! i've already tryed used the 'this' method but it didnt work...i think it's because it must have the thing = null first and only in the constructor assign the value to the var..
    \m/\m/

  32. #32

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    well im working really cool now but now i've come with another question...how do i make something like this

    PHP Code:
    myClass.Items[0].Text;
    myClass.Items[0].Status;
    myClass.Items[0].Progress
    i know it uses an indexer but what about the following thing?
    \m/\m/

  33. #33
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    easy, in terms of the example i last posted, create new class that represents the object you plan on adding to your collection, I'll call mine ButtonEx that inherits from Button:
    PHP Code:
    public class ButtonEx Button
    {
        public 
    string Status;
        public 
    string Progress;
        public 
    ButtonEx()
        {
            
    Status "Some Status";
            
    Progress "Some Progress";
        }

    Then change all references to the Button class to the ButtonEx class(now with new super properties) and the PanelEx code looks like this:
    Code:
    public class PanelEx : Panel
    {	
    	private int height = 0;
    	private int width = 0;
    	private int top = 0;
    	private int left = 0;
    	private PanelItems items = null;
    	
    	public PanelItems Items
    	{
    		get { return items; }
    	}
    	public PanelEx()
    	{
    		base.Height = height;
    		base.Width = width;
    		base.Top = top;
    		base.Left = top;
    		items = new PanelItems(this);
    	}
    	public PanelEx(int Height, int Width, int Top, int Left)
    	{
    		base.Height = height = Height;
    		base.Width = width = Width;
    		base.Top = top = Top;
    		base.Left = left = Left;
    		items = new PanelItems(this);
    	}
    	public void CoverForm(Form frm)
    	{
    		this.Height = frm.Height;
    		this.Width = frm.Width;
    		this.Refresh();
    	}
    	public class PanelItems : CollectionBase
    	{
    		private PanelEx parent = null;
    		private PanelItems(){}
    		//indexer
    		public ButtonEx this [int index]
    		{
    			get { return (ButtonEx)this.List[index]; }
    		}
    		public PanelItems(PanelEx Parent)
    		{
    			parent = Parent;
    		}
    		public void Add(string ButtonName)
    		{
    			ButtonEx btn = null;
    			if (this.List.Count > 0)
    			{
    				ButtonEx lastButton = ((ButtonEx)this.List[this.List.Count - 1]);
    				int newLeft = lastButton.Left + lastButton.Width;
    				btn = getButton(ButtonName, 25, 50, 0, newLeft);
    			}
    			else
    			{
    				btn = getButton(ButtonName, 25, 50, 0, 0);
    			}				
    			add(btn);
    		}
    		public void Add(string ButtonName, int Height, int Width)
    		{
    			ButtonEx btn = getButton(ButtonName, Height, Width, 0, 0);
    			add(btn);
    		}
    		public void Add(string ButtonName, int Height, int Width, int Top, int Left)
    		{
    			ButtonEx btn = getButton(ButtonName, Height, Width, Top, Left);
    			add(btn);
    		}
    		private void add(ButtonEx btn)
    		{
    			parent.Controls.Add(btn);
    			this.List.Add(btn);
    		}
    		protected void btn_Click(object sender, System.EventArgs e)
    		{
    			MessageBox.Show(((ButtonEx)sender).Text);
    		}
    		private ButtonEx getButton(string text, int height, int width, int top, int left)
    		{
    			ButtonEx btn = new ButtonEx();
    			btn.Text = text;
    			btn.Height = height;
    			btn.Width = width;
    			btn.Top = top;
    			btn.Left = left;
    			btn.Click += new System.EventHandler(btn_Click);
    			return btn;
    		}
    	}
    
    }
    Note the indexer i added to the PanelItems:
    Code:
    public ButtonEx this [int index]
    {
    	get { return (ButtonEx)this.List[index]; }
    }
    This enables the user of your class to use the notation:
    Code:
    myPanel.Items.Add("Chris");
    MessageBox.Show (myPanel.Items[0].Status);
    MessageBox.Show (myPanel.Items[0].Progress);

  34. #34

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    in IDE it looks ok but when in run-time it gives me the following error:

    PHP Code:
                public devSingleItem this[int index]
                {
                    
    get
                    
    {
                        if (
    index > -&& _array.Count >= index)
                        {
                            return (
    devSingleItem)_array[index];
                        }
                        else
                        {
                            throw (new 
    ArgumentOutOfRangeException("Error",null,"The given index was out of bounds"));
                        }
                    }
                } 
    An unhandled exception of type 'System.InvalidCastException' occurred in deviantion.exe

    Additional information: Specified cast is not valid.


    \m/\m/

  35. #35
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    hmmm...how do you declare "_array"?

  36. #36

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    PHP Code:
    using System;
    using System.Collections;
    using System.Windows.Forms;

    namespace 
    deviation
    {
        public class 
    devTab System.Windows.Forms.TabPage
        
    {
            private 
    devItems _items null;

            public 
    devTab(string caption)
            {
                
    _items = new devItems(this);
                
    this.Text caption;
            }

            public 
    devItems Items
            
    {
                
    get
                
    {
                    return 
    _items;
                }
            }

            public class 
    devItems
            
    {
                private 
    devTab _parent null;
                private 
    devOptions _options null;
                private 
    ArrayList _array = new ArrayList();

                public 
    devItems(devTab instance)
                {
                    
    _parent instance;
                    
    _options = new devOptions(this);
                }

                public 
    devSingleItem this[int index]
                {
                    
    get
                    
    {
                        if (
    index > -&& _array.Count >= index)
                        {
                            return (
    devSingleItem)_array[index];
                        }
                        else
                        {
                            throw (new 
    ArgumentOutOfRangeException("Error",null,"The given index was out of bounds"));
                        }
                    }
                }
                    public 
    devOptions Options
                
    {
                    
    get
                    
    {
                        return 
    _options;
                    }
                }

                
    /// <summary>
                /// Adds an item to the devTab
                /// </summary>
                /// <param name="url">The url of the picture to be downloaded</param>
                /// <param name="buttonWidth"></param>
                /// <param name="buttonHeight"></param>
                
    public void Add(string urlint buttonWidthint buttonHeight)
                {
                    
    _array.Add((string)url);
                    
    Button button = new Button();
                    
    _parent.Controls.Add(button);
                }

                public class 
    devSingleItem
                
    {
                    public 
    string Status;
                    public 
    string Progress;
                    public 
    devSingleItem()
                    {
                        
    Status "Some Status";
                        
    Progress "Some Progress";
                    }

                }

                public class 
    devOptions
                
    {
                    private 
    devItems _parent null;

                    private 
    int _numberOfPictures;
                    private 
    int _pictureWidth;
                    private 
    int _pictureHeight;
                    private 
    int _spaceWidthBetweenPictures;
                    private 
    int _spaceHeightBetweenPictures;
                    private 
    bool _canDownload true;

                    
    /// <summary>
                    /// Gets the number of pictures in the current devTab
                    /// </summary>
                    
    public int numberOfPictures
                    
    {
                        
    get
                        
    {
                            return 
    _numberOfPictures;
                        }
                        
    set
                        
    {
                            
    _numberOfPictures value;
                        }
                    }

                    
    /// <summary>
                    /// Gets / Sets the width size in pixels of the pictures in the current devTab
                    /// </summary>
                    
    public int pictureWidth
                    
    {
                        
    get
                        
    {
                            return 
    _pictureWidth;
                        }
                        
    set
                        
    {
                            
    _pictureWidth value;
                        }
                    }

                    
    /// <summary>
                    /// Gets / Sets the height size in pixels of the pictures in the current devTab
                    /// </summary>
                    
    public int pictureHeight
                    
    {
                        
    get
                        
    {
                            return 
    _pictureHeight;
                        }
                        
    set
                        
    {
                            
    _pictureHeight value;
                        }
                    }

                    
    /// <summary>
                    /// Gets / Sets the width size in pixels of the space between pictures
                    /// in the current devTab
                    /// </summary>
                    
    public int spaceWidthBetweenPictures
                    
    {
                        
    get
                        
    {
                            return 
    _spaceWidthBetweenPictures;
                        }
                        
    set
                        
    {
                            
    _spaceWidthBetweenPictures value;
                        }
                    }

                    
    /// <summary>
                    /// Gets / Sets the height size in pixels of the space between pictures
                    /// in the current devTab
                    /// </summary>
                    
    public int spaceHeightBetweenPictures
                    
    {
                        
    get
                        
    {
                            return 
    _spaceHeightBetweenPictures;
                        }
                        
    set
                        
    {
                            
    _spaceHeightBetweenPictures value;
                        }
                    }

                    
    /// <summary>
                    /// Defines if the pictures in the current devTab can be downloaded
                    /// into the buttons
                    /// </summary>
                    
    public bool canDownload
                    
    {
                        
    get
                        
    {
                            return 
    _canDownload;
                        }
                        
    set
                        
    {
                            
    _canDownload value;
                        }
                    }

                    public 
    devOptions(devItems instance)
                    {
                        
    _parent instance;
                    }
                }
            }
        }

    array:
    PHP Code:
                private ArrayList _array = new ArrayList(); 
    \m/\m/

  37. #37
    Hyperactive Member
    Join Date
    Aug 2002
    Location
    Fort Collins, CO
    Posts
    366
    It looks like your ArrayList stores stuff other than of type devSingleItem, so you possibly you're trying to cast a String type stored in your ArrayList as type devSingleItem which will throw an exception. Make sure you're only storing items of type devSingleItem in your ArrayList. I think this is the guy that's saving your string:
    VB Code:
    1. public void Add(string url, int buttonWidth, int buttonHeight)
    2.             {
    3.                 [b]_array.Add((string)url);[/b]
    4.                 Button button = new Button();
    5.                 _parent.Controls.Add(button);
    6.             }
    i get the feeling this is probably going to mess things up a bit for ya...

  38. #38

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    i removed the (string) casting and still givin me error =\
    \m/\m/

  39. #39

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    ah now i re-read ur post and i think i understood...just let me thing a bit..lool
    \m/\m/

  40. #40

    Thread Starter
    yay gay PT Exorcist's Avatar
    Join Date
    Apr 2002
    Location
    . . . my reason of shame
    Posts
    2,729
    well...i removed all the things that might cause trouble because of their data type and still the bug
    \m/\m/

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width