VintaSoft Imaging .NET SDK and Plug-ins Discussions

Questions, comments and suggestions concerning VintaSoft Imaging .NET SDK.

Board index < VintaSoft Imaging < VintaSoft Imaging .NET SDK and Plug-ins Discussions

We are migrating to new forums engine, no new registration or posting currently available. TIA for your patience.

Programmatically Rearranging Images



Programmatically Rearranging Images

Post by tplambeck »

I've got an image viewer displaying a multipage PDF. I need to move the pages up or down in the document using a context menu. Moving them up in the image collection works fine, down not so much. I'm sure I have a simple mistake in my code here. Does anyone see the issue?
private void moveUpToolStripMenuItem_Click(object sender, EventArgs e)
{
    int curIndex = pdfViewer.FocusedIndex;
    int[] vwIndex = new int[1] {pdfViewer.FocusedIndex};
    
    if (curIndex > 0)
    {
        pdfViewer.Images.MoveRange(curIndex - 1, vwIndex);
        pdfViewer.FocusedIndex = curIndex - 1;
    }
}

private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
{
    int curIndex = pdfViewer.FocusedIndex;
    int[] vwIndex = new int[1] {pdfViewer.FocusedIndex};

    if (curIndex < pdfViewer.Images.Count - 1)
    {
        pdfViewer.Images.MoveRange(curIndex + 1, vwIndex);
        pdfViewer.FocusedIndex = curIndex + 1;
    }
}


Re: Programmatically Rearranging Images

Post by Alex »

Hello,

You have the problem with the moveDownToolStripMenuItem_Click method because your code has logical mistake. In your code you are trying to insert element with index "curIndex" into position "curIndex + 1" and this means that you are trying to insert element after itself - this action will not change order of images in image collection.

Here is correct code for moveDownToolStripMenuItem_Click method:
private void moveDownToolStripMenuItem_Click(object sender, EventArgs e)
{
    int curIndex = thumbnailViewer1.FocusedIndex;
    int[] vwIndex = new int[1] { thumbnailViewer1.FocusedIndex };

    if (curIndex < thumbnailViewer1.Images.Count - 1)
    {
        thumbnailViewer1.Images.MoveRange(curIndex + 2, vwIndex);
        thumbnailViewer1.FocusedIndex = curIndex + 1;
    }
}
Best regards, Alexander


Re: Programmatically Rearranging Images

Post by tplambeck »

Thanks, Alex makes perfect sense now. Once again, great support!


Page 1 from 1: 1