Exemplo n.º 1
0
        public void SetIcon(string resourceName)
        {
            var form = this as Form;

            if (form == null)
            {
                return;
            }
            var s = ResourceStreamer.GetResourceStreamByName(resourceName);

            if (s == null)
            {
                return;
            }

            try
            {
                var bmp     = new Bitmap(Image.FromStream(s));
                var resized = ImageUtil.ResizeBitmap(bmp, 32);

                form.Icon = Icon.FromHandle(resized.GetHicon());
            }
            catch (Exception ex)
            {
                Trace.WriteLine(String.Join("", new string[]
                                            { "Unable to load resource by name for form icon: ", resourceName, "\n", ex.Message, "\n", ex.StackTrace }));
            }
        }
Exemplo n.º 2
0
        public void SetIcon(string resourceName)
        {
            var s = ResourceStreamer.GetResourceStreamByName(resourceName);

            if (s == null)
            {
                return;
            }
            this.SetIcon(Image.FromStream(s));
        }
Exemplo n.º 3
0
        /// <summary>
        /// sets an icon on the picker button by a name of a resource to be found in one of the loaded assemblies
        /// </summary>
        /// <param name="resourceName">name of the resource to load, eg "doctor-icon.png"</param>
        public void SetButtonIcon(string resourceName)
        {
            var s = ResourceStreamer.GetResourceStreamByName(resourceName);

            if (s == null)
            {
                return;
            }
            var btn = Button as ButtonWin;

            if (btn != null)
            {
                btn.SetIcon(resourceName);
            }
        }
Exemplo n.º 4
0
        public static Stream GetResourceStreamByName(string name)
        {
            var splitChars = new char[] { '.' };
            var splitName  = name.Split(splitChars);

            foreach (var asm in AppDomain.CurrentDomain.GetAssemblies())
            {
                foreach (var rName in asm.GetManifestResourceNames())
                {
                    var parts = rName.Split(splitChars);
                    if (ResourceStreamer.RightMatchStringArray(parts, splitName))
                    {
                        return(asm.GetManifestResourceStream(rName));
                    }
                }
            }
            return(null);
        }