Ejemplo n.º 1
0
        public void ImageListStreamer_RoundTripAndExchangeWithNet()
        {
            string netBlob;

            using (var imageList = new ImageList()
            {
                ImageSize = new Size(16, 16),
                TransparentColor = Color.White
            })
            {
                imageList.Images.Add(new Bitmap(16, 16));
                netBlob = BinarySerialization.ToBase64String(imageList.ImageStream);
            }

            // ensure we can deserialise NET serialised data and continue to match the payload
            ValidateResult(netBlob);
            // ensure we can deserialise NET Fx serialised data and continue to match the payload
            ValidateResult(ClassicImageListStreamer);

            void ValidateResult(string blob)
            {
                ImageListStreamer result = BinarySerialization.EnsureDeserialize <ImageListStreamer>(blob);

                using (NativeImageList nativeImageList = result.GetNativeImageList())
                {
                    Assert.True(SafeNativeMethods.ImageList_GetIconSize(new HandleRef(this, nativeImageList.Handle), out int x, out int y));
                    Assert.Equal(16, x);
                    Assert.Equal(16, y);
                    NativeMethods.IMAGEINFO imageInfo = new NativeMethods.IMAGEINFO();
                    Assert.True(SafeNativeMethods.ImageList_GetImageInfo(new HandleRef(this, nativeImageList.Handle), 0, imageInfo));
                    Assert.True(IntPtr.Zero != imageInfo.hbmImage);
                }
            }
        }
Ejemplo n.º 2
0
        private void ValidateImageListStreamer(string blob)
        {
            var result = BinarySerialization.EnsureDeserialize <ImageListStreamer>(blob);

            using (NativeImageList nativeImageList = result.GetNativeImageList())
            {
                Assert.True(SafeNativeMethods.ImageList_GetIconSize(new HandleRef(this, nativeImageList.Handle), out int x, out int y));
                Assert.Equal(16, x);
                Assert.Equal(16, y);
                NativeMethods.IMAGEINFO imageInfo = new NativeMethods.IMAGEINFO();
                Assert.True(SafeNativeMethods.ImageList_GetImageInfo(new HandleRef(this, nativeImageList.Handle), 0, imageInfo));
                Assert.True(IntPtr.Zero != imageInfo.hbmImage);
            }
        }
Ejemplo n.º 3
0
 /// <include file='doc\ImageList.uex' path='docs/doc[@for="ImageList.GetImageInfo"]/*' />
 /// <devdoc>
 /// </devdoc>
 /// <internalonly/>
 internal NativeMethods.IMAGEINFO GetImageInfo(int index)
 {
     if (index < 0 || index >= Images.Count)
     {
         throw new ArgumentOutOfRangeException(SR.GetString(SR.InvalidArgument,
                                                            "index",
                                                            index.ToString()));
     }
     NativeMethods.IMAGEINFO info = new NativeMethods.IMAGEINFO();
     if (SafeNativeMethods.ImageList_GetImageInfo(new HandleRef(this, Handle), index, info) == false)
     {
         throw new InvalidOperationException(SR.GetString(SR.ImageListGetFailed));
     }
     return(info);
 }
Ejemplo n.º 4
0
        private Size GetImageIconSize(int index)
        {
            var imgInfo = new NativeMethods.IMAGEINFO();
            int hr;

            if (_iImageList == null || Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
            {
                hr = NativeMethods.ImageList_GetImageInfo(_ptrImageList, index, ref imgInfo);
            }
            else
            {
                hr = _iImageList.GetImageInfo(index, ref imgInfo);
            }

            if (hr != 0)
            {
                Marshal.ThrowExceptionForHR(hr);
            }

            var rect = imgInfo.rcImage;

            return(new Size(rect.right - rect.left, rect.bottom - rect.top));
        }
Ejemplo n.º 5
0
 public static extern bool ImageList_GetImageInfo(HandleRef himl, int i, NativeMethods.IMAGEINFO pImageInfo);
Ejemplo n.º 6
0
        private Size GetImageIconSize(int index)
        {
            var imgInfo = new NativeMethods.IMAGEINFO();
            int hr;

            if (_iImageList == null || Thread.CurrentThread.GetApartmentState() == ApartmentState.MTA)
                hr = NativeMethods.ImageList_GetImageInfo(_ptrImageList, index, ref imgInfo);
            else hr = _iImageList.GetImageInfo(index, ref imgInfo);

            if (hr != 0)
                Marshal.ThrowExceptionForHR(hr);

            var rect = imgInfo.rcImage;
            return new Size(rect.right - rect.left, rect.bottom - rect.top);
        }