Beispiel #1
0
        public void DrawCursorToImage(System.Drawing.Image img, Point cursorOffset)
        {
            if (IconHandle != IntPtr.Zero)
            {
                Point drawPosition = new Point(Position.X - cursorOffset.X, Position.Y - cursorOffset.Y);

                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(img))
                    using (System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(IconHandle))
                    {
                        g.DrawIcon(icon, (int)drawPosition.X, (int)drawPosition.Y);
                    }
            }
        }
Beispiel #2
0
    protected override void Paint(System.Drawing.Graphics graphics, System.Drawing.Rectangle clipBounds, System.Drawing.Rectangle cellBounds, int rowIndex, DataGridViewElementStates cellState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
    {
        base.Paint(graphics, clipBounds, cellBounds, rowIndex, cellState, value, "", errorText, cellStyle,
                   advancedBorderStyle, paintParts);

        var       cellValue        = Convert.IsDBNull(value) ? 0 : Convert.ToDecimal(value);
        const int horizontaloffset = 2;

        var parent = (LagerStatusColumn)this.OwningColumn;
        var fnt    = parent.InheritedStyle.Font;
        var icon   = Properties.Resources.lager;

        if (cellValue == 0)
        {
            icon = Properties.Resources.rest;
        }
        else if (cellValue < 0)
        {
            icon = Properties.Resources.question_white;
        }
        const int vertoffset = 0;

        graphics.DrawIcon(icon, cellBounds.X + horizontaloffset,
                          cellBounds.Y + vertoffset);
        var cellText = formattedValue.ToString();
        var textSize =
            graphics.MeasureString(cellText, fnt);
        //  Calculate the correct color:
        var textColor = parent.InheritedStyle.ForeColor;

        if ((cellState &
             DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
        {
            textColor = parent.InheritedStyle.
                        SelectionForeColor;
        }
        // Draw the text:
        using (var brush = new SolidBrush(textColor))
        {
            graphics.DrawString(cellText, fnt, brush,
                                cellBounds.X + icon.Width + 2,
                                cellBounds.Y + 0);
        }
    }
        public static System.Drawing.Bitmap GetIconAsImage(string Name)
        {
            System.IO.Stream stm = typeof(ResourceManager).Assembly.GetManifestResourceStream(string.Format("NzbDrone.Core.{0}.ico", Name));
            if (stm == null)
            {
                return(null);
            }
            System.Drawing.Bitmap bmp;
            using (System.Drawing.Icon ico = new System.Drawing.Icon(stm))
            {
                bmp = new System.Drawing.Bitmap(ico.Width, ico.Height);
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    g.DrawIcon(ico, 0, 0);
                }
            }

            return(bmp);
        }