Results 1 to 5 of 5

Thread: Control Array

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Location
    India
    Posts
    318

    Control Array

    Hi,

    I'm working on C# with COM. I have a COM OLE control that I wish to create on the form as control array during runtime, as the number of cotrols depends on the number of files in the corresponding folder. How do I go about it? I'm attaching a pic of the form as to how I want it to be.

    Thanks
    Attached Images Attached Images  

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control Array

    A control array is just an array of controls, which you create like any other array. You'd declare the array at the class level and then create the object when you know the size, e.g.
    Code:
    private Button[,] buttons;
    
    private void CreateButtonArray(int rowCount, int columnCount)
    {
        this.buttons = new Button[rowCount, columnCount];
    }
    You could then use loops to populate the array.

    That said, I probably suggest that you use a TableLayoutPanel to lay out the controls on the form. You can then simply add the control to the panel and it will grow automatically as required, or you can place them explicitly. You can then loop through the rows and columns of the TLP to populate the 2D array, or you can just forget the array altogether and just access the controls by row and column in the TLP.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Location
    India
    Posts
    318

    Re: Control Array

    I tried, but it is not working. I think it is because it is an OLE control.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Control Array

    You tried what? If we don't see the code we can't know what's wrong with it.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jul 2003
    Location
    India
    Posts
    318

    Re: Control Array

    Looks like I have solved the issue. Here is the code.

    Code:
    private void TV_AfterSelect(object sender, TreeViewEventArgs e)
            {
                btnPrev.Enabled = false;
                btnNext.Enabled = false;
    
                TreeNode newSelected = e.Node;
                DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
    
                int numFile = 0;
    
                this.groupBox2.Controls.Clear();
    
                sldNum = nodeDirInfo.GetFiles("*.sld").Count();
                ShowSld();
    
                foreach (FileInfo file in nodeDirInfo.GetFiles("*.sld"))
                {
                         numFile++;
                        sldArray[numFile].FileName = file.FullName;
                 }
            }
    
            private void ShowSld()
            {
                int xPos = 10;// 140;
                int yPos = 23;// 140;
                AddControls("sld", sldNum); //Create slides.
                int n = 1;
                while (n < sldNum + 1)
                {
                    sldArray[n].Tag = n;
                    sldArray[n].Width = 125;
                    sldArray[n].Height = 115;
                    if (xPos > 570)
                    {
                        xPos = 10;
                        yPos = yPos + sldArray[n].Height + 28;
                    }
                    sldArray[n].Left = xPos;
                    sldArray[n].Top = yPos;
                    xPos = xPos + sldArray[n].Width + 15;
                    groupBox2.Controls.Add(sldArray[n]);
                    n++;
                }
            }
    
            private void AddControls(string anyControl, int cNumber)
            {
                switch (anyControl)
                {
                    case "sld":
    
                        sldArray = new AxSLIDELib.AxSlide[cNumber + 1];
                        for (int i = 0; i < cNumber + 1; i++)
                        {
                            sldArray[i] = new AxSLIDELib.AxSlide();
                        }
                        break;
    
                }
            }
    But my next problem is, if there are more than 15 files in the folder, how do I display it in the form using the Previous and Next button?

    Thanks

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