Ok, one thing that does puzzle me is

private void ShowSld(int sldCnt)
        {

            int xPos = 10;// 140;
            int yPos = 23;// 140;
            this.groupBox2.Controls.Clear();
            while (n < sldCnt)
            {
                    sldArray[n].Tag = n;
                    sldArray[n].Width = 125;
                    sldArray[n].Height = 115;
                    if (xPos > 570)
                    {
                        xPos = 10;
                        yPos = yPos + sldArray[n].Height + 35;
                    }
                    sldArray[n].Left = xPos;
                    sldArray[n].Top = yPos;
                    xPos = xPos + sldArray[n].Width + 15;

                    groupBox2.Controls.Add(sldArray[n]);
                    sldArray[n].FileName = filCol[n].FullName;

                    n++;
            }
         }

At face value, it would seem the start variable should work out but then you dont seem to use it in your actual display.. and you rely on "n" which could get changed in a number of places, but, the while loop would at least end at the right end..

You might want to tweak that so it maybe has a more reliable output - as for example, if you displayed page 3, and selected a slide, n goes back to 0.

use of local variables would overcome the concerns about last state, but it would be easier to pass a start+end variable pair to your function as a result.

I thought we were trying to hint you toward a ShowPage(int pageno) type of implementation.

Then inside ShowPage, you could determine the start and end indexes for the page. (I'm presuming here that pageno starts at zero.)

int startidx = pageno * 15;
int endidx = min(startidx + 15, sldNum);
// sldNum is the member that has the maximum slide number, right?
for (ii = startidx; ii < endix; ii++)
{
    // size and position the control sldArray[ii]
    // I might have written the code differently, but your code should work.
}
btnNext.Enabled = endidx < sldNum;
btnPrev.Enabled = startidx > 0;

We were - but the method chosen kinda works, except its a little more confused :)

I thought we were trying to hint you toward a ShowPage(int pageno) type of implementation.

Then inside ShowPage, you could determine the start and end indexes for the page. (I'm presuming here that pageno starts at zero.)

int startidx = pageno * 15;
int endidx = min(startidx + 15, sldNum);
// sldNum is the member that has the maximum slide number, right?
for (ii = startidx; ii < endix; ii++)
{
    // size and position the control sldArray[ii]
    // I might have written the code differently, but your code should work.
}
btnNext.Enabled = endidx < sldNum;
btnPrev.Enabled = startidx > 0;

Hey, thanks! That's a sweet short code. I shall use this code.

We were - but the method chosen kinda works, except its a little more confused

Yes, it is confusing.:( Here's the code for Previous button.

private void btnPrev_Click(object sender, EventArgs e)
        {
            btnNext.Enabled = true;
            if (end == sldNum)
            {
                end = end - (sldNum % 15);
            }
            else if (end < sldNum)
            {
                end = end - 15;
            }

            n = end - 15;
            ShowSld(end);
        }

I thought we were trying to hint you toward a ShowPage(int pageno) type of implementation.

Then inside ShowPage, you could determine the start and end indexes for the page. (I'm presuming here that pageno starts at zero.)

int startidx = pageno * 15;
int endidx = min(startidx + 15, sldNum);
// sldNum is the member that has the maximum slide number, right?
for (ii = startidx; ii < endix; ii++)
{
    // size and position the control sldArray[ii]
    // I might have written the code differently, but your code should work.
}
btnNext.Enabled = endidx < sldNum;
btnPrev.Enabled = startidx > 0;

How do I increment the pageno? The initial page can start with 0 from the TV_AfterSelect event. But what about the Next and Previous buttons?

Thanks

It worked! :icon_exclaim:

Here is my code:

private void TV_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.groupBox2.Controls.Clear();
            n = 0;

            TreeNode newSelected = e.Node;
            DirectoryInfo nodeDirInfo = (DirectoryInfo)newSelected.Tag;
            filCol = nodeDirInfo.GetFiles("*.sld");
            sldNum = nodeDirInfo.GetFiles("*.sld").Count();
            
            btnPrev.Enabled = false;

            if (sldNum > 15)
            {
                btnNext.Enabled = true;
            }

            if (sldNum > 0)
            {
                AddControls("sld", sldNum);
                showPage(0);
             }
        }

        private void showPage(int pageno)
        {
            int xPos = 10;// 140;
            int yPos = 23;// 140;
            this.groupBox2.Controls.Clear();

            int startidx = pageno * 15;
            int endidx = Math.Min(startidx + 15, sldNum);

            for(int iSld = startidx; iSld < endidx; iSld++)
            {
                sldArray[iSld].Tag = iSld;
                sldArray[iSld].Width = 125;
                sldArray[iSld].Height = 115;

                if (xPos > 570)
                {
                    xPos = 10;
                    yPos = yPos + sldArray[iSld].Height + 35;
                }
                sldArray[iSld].Left = xPos;
                sldArray[iSld].Top = yPos;
                xPos = xPos + sldArray[iSld].Width + 15;

                groupBox2.Controls.Add(sldArray[iSld]);
                sldArray[iSld].FileName = filCol[iSld].FullName;
            }

            btnNext.Enabled = endidx < sldNum;
            btnPrev.Enabled = startidx > 0;
        }

        private void AddControls(string anyControl, int cNumber)
        {
            switch (anyControl)
            {
                case "sld":

                    sldArray = new AxSlide.AxSlide[cNumber + 1];
                    for (int i = 0; i < cNumber + 1; i++)
                    {
                        sldArray[i] =new AxSlide.AxSlide();
                    }
                    break;
             }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            iNext++;
            showPage(iNext);
        }

        private void btnPrev_Click(object sender, EventArgs e)
        {
            iNext--;
            showPage(iNext);
        }

Finally :p

now mark it as solved :)

Thank you soooooo much for your help!...

I have a question more.:P

When I double click on a slide, how do I pass the filename to display a zoomed image of the slide?

public void DblClickSld(object sender, System.EventArgs e)
        {
            frmZoom fZ = new frmZoom();

            MessageBox.Show((string)((AxSlide.AxSlide)sender).FileName.ToString());

            fZ.Show();
        }

Added this to showPage()

sldArray[iCtl].LButtonDblClk += new System.EventHandler(DblClickSld);

Thats a whole new question :P make a new thread of it, and mark this one as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.