public void CreateMultipleIconFromSameHandle()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico")))
            {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.Handle;
                using (Icon icon2 = Icon.FromHandle(handle))
                {
                    Assert.AreEqual(16, icon2.Height, "2.Height");
                    Assert.AreEqual(16, icon2.Width, "2.Width");
                    Assert.AreEqual(handle, icon2.Handle, "2.Handle");
                    IconTest.SaveAndCompare("Handle2", icon2, false);
                }
                using (Icon icon3 = Icon.FromHandle(handle))
                {
                    Assert.AreEqual(16, icon3.Height, "3.Height");
                    Assert.AreEqual(16, icon3.Width, "3.Width");
                    Assert.AreEqual(handle, icon3.Handle, "3.Handle");
                    IconTest.SaveAndCompare("Handle3", icon3, false);
                }
            }
            // unlike other cases (HICON, HBITMAP) handle DOESN'T survives original icon disposal
            // commented / using freed memory is risky ;-)
        }
        public void CreateMultipleIconFromSameHICON()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico")))
            {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.ToBitmap().GetHicon();
            }
            // HICON survives
            using (Icon icon2 = Icon.FromHandle(handle))
            {
                Assert.AreEqual(16, icon2.Height, "2.Height");
                Assert.AreEqual(16, icon2.Width, "2.Width");
                Assert.AreEqual(handle, icon2.Handle, "2.Handle");
                IconTest.SaveAndCompare("HICON2", icon2, false);
            }
            using (Icon icon3 = Icon.FromHandle(handle))
            {
                Assert.AreEqual(16, icon3.Height, "3.Height");
                Assert.AreEqual(16, icon3.Width, "3.Width");
                Assert.AreEqual(handle, icon3.Handle, "3.Handle");
                IconTest.SaveAndCompare("HICON", icon3, false);
            }
        }
        public void HandleRoundtrip()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico")))
            {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.Handle;
                using (Icon icon2 = Icon.FromHandle(handle))
                {
                    Assert.AreEqual(16, icon2.Height, "FromHandle.Height");
                    Assert.AreEqual(16, icon2.Width, "FromHandle.Width");
                    Assert.AreEqual(handle, icon2.Handle, "FromHandle.Handle");
                    IconTest.SaveAndCompare("Handle", icon2, false);
                }
            }
            // unlike other cases (HICON, HBITMAP) handle DOESN'T survives original icon disposal
            // commented / using freed memory is risky ;-)

            /*using (Icon icon3 = Icon.FromHandle (handle)) {
             *      Assert.AreEqual (0, icon3.Height, "Survivor.Height");
             *      Assert.AreEqual (0, icon3.Width, "Survivor.Width");
             *      Assert.AreEqual (handle, icon3.Handle, "Survivor.Handle");
             * }*/
        }
示例#4
0
文件: TestIcon.cs 项目: nsivov/mono
        public void HiconRoundtrip()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestResourceHelper.GetFullPathOfResource("Test/System.Drawing/bitmaps/16x16x16.ico"))) {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.ToBitmap().GetHicon();
            }
            // HICON survives
            using (Icon icon2 = Icon.FromHandle(handle)) {
                Assert.AreEqual(16, icon2.Height, "Survivor.Height");
                Assert.AreEqual(16, icon2.Width, "Survivor.Width");
                Assert.AreEqual(handle, icon2.Handle, "Survivor.Handle");
                IconTest.SaveAndCompare("HICON", icon2, false);
            }
        }
示例#5
0
        public void HiconRoundtrip()
        {
            IntPtr handle;

            using (Icon icon = new Icon(TestBitmap.getInFile("bitmaps/16x16x16.ico"))) {
                Assert.AreEqual(16, icon.Height, "Original.Height");
                Assert.AreEqual(16, icon.Width, "Original.Width");
                handle = icon.ToBitmap().GetHicon();
            }
            // HICON survives
            using (Icon icon2 = Icon.FromHandle(handle)) {
                Assert.AreEqual(16, icon2.Height, "Survivor.Height");
                Assert.AreEqual(16, icon2.Width, "Survivor.Width");
                Assert.AreEqual(handle, icon2.Handle, "Survivor.Handle");
                IconTest.SaveAndCompare("HICON", icon2, false);
            }
        }