A1VBCode Forums

Control Array


http://www.a1vbcode.com/vbforums/Topic26672.aspx

By shers - 1/7/2009

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

By shers - 1/10/2009

Looks like I have solved the issue. Here is the 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