469,621 Members | 1,715 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,621 developers. It's quick & easy.

how to change the size of images in imagelist at runtime.

hai Anti Keskinen,
i have used
the following code MyListView->LargeImageList->ImageSize = gcnew
System::Drawing::Size(100,
100); // Sets large image size to 100, 100
here i am getting error like "gcnew is undeclared error",how to deeclare
'gcnew"
and when i am using in runtime to change the size of images in imagelist in
listview control in .net(forms application) by chnging one trckbar(like
tb1->Value),
the imagelist is disappearing,and if again i added images to that imagelist
the images r adding as currentimage size.
pls tell me how to change the size in runtime without destroying the images.
Thanks and Regards,
Sanjeev

Nov 17 '05 #1
2 7670
Hi Sanjeeva !

Please use the 'Reply Group' button of your news reader. It allows the chain
of messages to stay under the same topic, and following the discussion
becomes a whole lot easier.

Like I stated in my post, "gcnew" keyword is defined only in C++/CLI
context. This means that if you are using Visual Studio 2005 Beta, the
keyword will work and will do what it is supposed to do. In earlier
versions, it does not work, as C++/CLI is not supported yet.

What "gcnew" does is reserve memory for a new managed object on the heap. In
Managed C++, the equivalent is "new", I think. So, the call should look
like:

MyListView->LargeImageList->ImageSize = new System::Drawing::Size(100,100);

In the documentation, it says that when you set a new image size, the handle
is recreated. This means that you must order the listview to redraw itself.
If this does not work, then the only possibility is to create a copy of the
old imagelist with a new size property, then replace the old list, like
here: (This is Managed C++ code)

<snip starts>

// Somewhere at the begin of file, to avoid lots of typing
using System::Windows::Forms;

// Later in the file, where you need to change the imagelist size.
ImageList* pOldList = MyListView->LargeImageList;

ImageList* pNewList = new ImageList();
pNewList->ImageSize = new System::Drawing::Size(100, 100);
// Other setup for the new image list, like color depth and transparency, if
required.

IEnumerator* pOldListEnum = pOldList->Images->GetEnumerator();

pNewList->Images->Add( __try_cast<Bitmap*> (pOldListEnum->Current()) );

while ( pOldListEnum->MoveNext() )
pNewList->Images->Add( __try_cast<Bitmap*> (pOldListEnum->Current()) );

// The new image list is now a copy of the old one, with new image size set.
// Now we put it into the place of the old one
MyListView->LargeImageList = pNewList;

// The old one is discarded by the Garbage Collection at some point.

<snip ends>

I am not 100% certain that this approach will work. The idea is to create a
new imagelist, set a new size for it, and then systematically add the images
from the old list into the new list by using an enumerator to the old list.
Again, it is not certain whether ImageList::Images::Add will create a copy
of the image you add to it. This shouldn't make a difference in Managed C++,
though. However, it's a point that should be noted. So, do not use the code
snip blindly without examining it first, and debugging through it properly
to see if it REALLY works. I haven't tested it, so I do not know.

-Antti Keskinen
"Sanjeeva Reddy" <sanjeeva.reddy at yahoo no mail.com> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
hai Anti Keskinen,
i have used
the following code MyListView->LargeImageList->ImageSize = gcnew
System::Drawing::Size(100,
100); // Sets large image size to 100, 100
here i am getting error like "gcnew is undeclared error",how to deeclare
'gcnew"
and when i am using in runtime to change the size of images in imagelist
in
listview control in .net(forms application) by chnging one trckbar(like
tb1->Value),
the imagelist is disappearing,and if again i added images to that
imagelist
the images r adding as currentimage size.
pls tell me how to change the size in runtime without destroying the
images.
Thanks and Regards,
Sanjeev


Nov 17 '05 #2
hai Antti Keskinen,
i have used like that ,it worked partially,but the images r blinking and
getting blured.
can u give any suggestion for that.
and i am having some more doubts:
1)how to get the preview of movie file to add in imagelist(i mean the first
frame of movie file. )
here i am giving code for adding images in my imagelist below.
imageList1->Images->Add(Image::FromFile("C:\\ar1.jpg");
like that only i want to add my movie files(first frame) to my imagelist.
2)imagetransition:in imagetrancistion i want to use transition filter like
horizontalwipe(means we have to get the imagefrom left side) and
verticalwipe(means we have to get the image from top ) and alphablend.
Thanks&Regards
Sanjeev.
"Antti Keskinen" <an************@REMOVEME.ee.tpu.fi> wrote in message
news:O4**************@TK2MSFTNGP15.phx.gbl...
Hi Sanjeeva !

Please use the 'Reply Group' button of your news reader. It allows the chain of messages to stay under the same topic, and following the discussion
becomes a whole lot easier.

Like I stated in my post, "gcnew" keyword is defined only in C++/CLI
context. This means that if you are using Visual Studio 2005 Beta, the
keyword will work and will do what it is supposed to do. In earlier
versions, it does not work, as C++/CLI is not supported yet.

What "gcnew" does is reserve memory for a new managed object on the heap. In Managed C++, the equivalent is "new", I think. So, the call should look
like:

MyListView->LargeImageList->ImageSize = new System::Drawing::Size(100,100);
In the documentation, it says that when you set a new image size, the handle is recreated. This means that you must order the listview to redraw itself. If this does not work, then the only possibility is to create a copy of the old imagelist with a new size property, then replace the old list, like
here: (This is Managed C++ code)

<snip starts>

// Somewhere at the begin of file, to avoid lots of typing
using System::Windows::Forms;

// Later in the file, where you need to change the imagelist size.
ImageList* pOldList = MyListView->LargeImageList;

ImageList* pNewList = new ImageList();
pNewList->ImageSize = new System::Drawing::Size(100, 100);
// Other setup for the new image list, like color depth and transparency, if required.

IEnumerator* pOldListEnum = pOldList->Images->GetEnumerator();

pNewList->Images->Add( __try_cast<Bitmap*> (pOldListEnum->Current()) );

while ( pOldListEnum->MoveNext() )
pNewList->Images->Add( __try_cast<Bitmap*> (pOldListEnum->Current()) );
// The new image list is now a copy of the old one, with new image size set. // Now we put it into the place of the old one
MyListView->LargeImageList = pNewList;

// The old one is discarded by the Garbage Collection at some point.

<snip ends>

I am not 100% certain that this approach will work. The idea is to create a new imagelist, set a new size for it, and then systematically add the images from the old list into the new list by using an enumerator to the old list. Again, it is not certain whether ImageList::Images::Add will create a copy
of the image you add to it. This shouldn't make a difference in Managed C++, though. However, it's a point that should be noted. So, do not use the code snip blindly without examining it first, and debugging through it properly
to see if it REALLY works. I haven't tested it, so I do not know.

-Antti Keskinen
"Sanjeeva Reddy" <sanjeeva.reddy at yahoo no mail.com> wrote in message
news:Oc**************@TK2MSFTNGP10.phx.gbl...
hai Anti Keskinen,
i have used
the following code MyListView->LargeImageList->ImageSize = gcnew
System::Drawing::Size(100,
100); // Sets large image size to 100, 100
here i am getting error like "gcnew is undeclared error",how to deeclare
'gcnew"
and when i am using in runtime to change the size of images in imagelist
in
listview control in .net(forms application) by chnging one trckbar(like
tb1->Value),
the imagelist is disappearing,and if again i added images to that
imagelist
the images r adding as currentimage size.
pls tell me how to change the size in runtime without destroying the
images.
Thanks and Regards,
Sanjeev



Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Silvia | last post: by
1 post views Thread by Anthony Boudouvas | last post: by
3 posts views Thread by Bruno Rodrigues | last post: by
2 posts views Thread by A. Solomon | last post: by
3 posts views Thread by Dean Slindee | last post: by
7 posts views Thread by Mitchell Vincent | last post: by
reply views Thread by Luis Arvayo | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.