Draw() публичный Метод

Draw the given symbol to fill the rectange in that graphics.
public Draw ( Graphics g, Color color, RectangleF rect ) : void
g System.Drawing.Graphics Graphics to draw in.
color Color Color to use for drawing.
rect System.Drawing.RectangleF The rectange to fill.
Результат void
Пример #1
0
        private void listBoxSymbols_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();

            if (e.Index >= 0)
            {
                string id = (string)listBoxSymbols.Items[e.Index];

                // Get bounds of where to draw the symbol and its text.
                RectangleF symbolGraphicsBounds = e.Bounds;
                symbolGraphicsBounds.Width = symbolGraphicsBounds.Height;

                RectangleF textBounds = e.Bounds;
                textBounds.X += symbolGraphicsBounds.Width + 4;

                // Get color to draw with. Draw customize ones in red when not selected.
                Color foreColor;
                if ((e.State & DrawItemState.Selected) == 0 && TextIsCustomized(id))
                {
                    foreColor = Color.Red;
                }
                else
                {
                    foreColor = e.ForeColor;
                }

                // Draw the symbol.
                SmoothingMode oldSmoothing = e.Graphics.SmoothingMode;
                e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;

                Symbol symbol = symbolDB[id];
                symbol.Draw(e.Graphics, foreColor, symbolGraphicsBounds);

                e.Graphics.SmoothingMode = oldSmoothing;

                // Draw the text. Use English if we're customizing text, otherwise use the set language.
                string langId = useAsLocalizeTool ? "en" : LangId;
                string text   = symbol.GetName(langId);

                StringFormat stringFormat = new StringFormat(StringFormat.GenericDefault);
                stringFormat.Alignment     = StringAlignment.Near;
                stringFormat.LineAlignment = StringAlignment.Center;
                e.Graphics.DrawString(text, e.Font, new SolidBrush(foreColor), textBounds, stringFormat);
            }

            e.DrawFocusRectangle();
        }
Пример #2
0
        // The images for given symbols are cached, so we only render each one once.
        Image GetSymbolImage(Symbol symbol)
        {
            if (symbolImageCacheStandard != symbolDB.Standard)
            {
                symbolImageCacheStandard = symbolDB.Standard;
                symbolImageCache.Clear();
            }

            if (!symbolImageCache.ContainsKey(symbol.Id))
            {
                // Create a bitmap and draw into it.
                Bitmap   bm = new Bitmap(symbol.IsWide ? boxSize * 8 : boxSize, boxSize);
                Graphics g  = Graphics.FromImage(bm);
                g.Clear(Color.Transparent);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                symbol.Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height));
                g.Dispose();

                symbolImageCache.Add(symbol.Id, bm);
            }

            return(symbolImageCache[symbol.Id]);
        }
Пример #3
0
        // The images for given symbols are cached, so we only render each one once.
        Image GetSymbolImage(Symbol symbol)
        {
            if (!symbolImageCache.ContainsKey(symbol.Id)) {

                // Create a bitmap and draw into it.
                Bitmap bm = new Bitmap(symbol.IsWide ? boxSize * 8 : boxSize, boxSize);
                Graphics g = Graphics.FromImage(bm);
                g.Clear(Color.Transparent);
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
                symbol.Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height));
                g.Dispose();

                symbolImageCache.Add(symbol.Id, bm);
            }

            return symbolImageCache[symbol.Id];
        }
Пример #4
0
 public void DrawSymbol(Symbol sym, RectangleF rect)
 {
     sym.Draw(g, Color.Black, rect);
 }