Esempio n. 1
0
        public static ImageSource ToImageSource(this Icon icon)
        {
            int hashCode = icon.GetHashCode();

            if (Cache.ContainsKey(hashCode))
            {
                return(Cache[hashCode]);
            }

            Bitmap bitmap  = icon.ToBitmap();
            IntPtr hBitmap = bitmap.GetHbitmap();

            var imageSource = CreateBitmapSourceFromHBitmap(hBitmap, IntPtr.Zero, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());

            if (!DeleteObject(hBitmap))
            {
                throw new Win32Exception();
            }

            Cache.Add(hashCode, imageSource);

            return(imageSource);
        }
Esempio n. 2
0
		/// <summary>
		/// Adds scope node to the scope tree
		/// </summary>
		internal ScopeNode AddScopeNode(ScopeNode parent, string text, Icon largeIcon, Icon smallIcon, ResultViewControl resultView, NodeType nodeType, object tag)
		{
			string smallIconName = smallIcon.GetHashCode().ToString();
			if (!this.smallImages.Images.ContainsKey(smallIconName))
			{
				this.smallImages.Images.Add(smallIconName, smallIcon);
			}
			ScopeNode node = new ScopeNode();
			node.Text = text;
			node.ResultView = resultView;
			node.SmallIcon = smallIcon;
			node.LargeIcon = largeIcon;
			node.ImageKey = smallIconName;
			node.SelectedImageKey = smallIconName;
			node.NodeType = nodeType;
			node.Populated = false;
			node.Tag = tag;
			if (parent == null)
			{
				scopeTree.Nodes.Add(node);
			}
			else
			{
				parent.Nodes.Add(node);
			}
			//add fake node to show +
			node.Nodes.Add(" ");
			return node;
		}