示例#1
0
        /// <summary>
        /// Sets CellWidth, CellHeight properties based on the size of the first png icon found at the specified path.
        /// </summary>
        public void ChooseIconCellSize(string path)
        {
            if (!Directory.Exists(path))
            {
                return;
            }

            CellWidth  = 32;
            CellHeight = 32;

            // let's try to determine real size by first file
            try
            {
                string[] files = Directory.GetFiles(path);
                foreach (string filename in files)
                {
                    string ext = Path.GetExtension(filename);

                    if (ext.EqualsIgnoreCase(".png"))
                    {
                        var size = GdiPlusHelper.GetIconSize(filename);
                        if (size != default(Size))
                        {
                            CellWidth  = size.Width;
                            CellHeight = size.Height;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageService.Current.Info("Failed to load icon: " + ex.Message);
            }
        }
示例#2
0
        /// <summary>
        /// Changes the texture
        /// </summary>
        private void SelectionTextureChanged()
        {
            string filename = textureControl1.SelectedPath;

            if (string.IsNullOrWhiteSpace(filename))
            {
                return;
            }

            var clrTransparent = GdiPlusHelper.GetTransparentColor(filename);

            var img = BitmapSource.Open(filename, true);

            {
                img.TransparentColorFrom = clrTransparent;
                img.TransparentColorTo   = clrTransparent;
                img.UseTransparentColor  = true;

                _style.Marker.Icon = img;

                DrawPreview();
            }

            btnApply.Enabled = true;
        }
示例#3
0
        /// <summary>
        /// This gets called to instruct the element to draw itself in the appropriate spot of the graphics object
        /// </summary>
        protected override void Draw(Graphics g, bool printing, bool export, int x, int y)
        {
            var oldHint = g.TextRenderingHint;

            g.TextRenderingHint = _textHint;

            using (Brush colorBrush = new SolidBrush(_color))
            {
                using (var sf = GdiPlusHelper.GetStringFormat(_contentAlignment))
                {
                    var r = new RectangleF {
                        X = x, Y = y, Width = Rectangle.Width, Height = Rectangle.Height
                    };
                    g.DrawString(_text, _font, colorBrush, r, sf);
                }
            }

            g.TextRenderingHint = oldHint;
        }