Пример #1
0
        public int CompareTo(object obj)
        {
            if (obj != null && obj is GraphicLabel)
            {
                GraphicLabel gl = obj as GraphicLabel;
                return(_Text.CompareTo(gl.Text));
            } //if(obj != null && obj is GraphicLabel)

            return(1);
        } //public int CompareTo(object obj)
Пример #2
0
        protected override void Paint(Graphics graphics,
                                      Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
                                      DataGridViewElementStates elementState, object value,
                                      object formattedValue, string errorText,
                                      DataGridViewCellStyle cellStyle,
                                      DataGridViewAdvancedBorderStyle advancedBorderStyle,
                                      DataGridViewPaintParts paintParts)
        {
            base.Paint(graphics, clipBounds, cellBounds, rowIndex, elementState, value, "", errorText, cellStyle, advancedBorderStyle, paintParts);
            ToolTipText = "";

            if (value != null)
            {
                GraphicLabel gl = (GraphicLabel)value;
                if (gl != null)
                {
                    int imgWidth = cellBounds.Height - cellStyle.Padding.Vertical;

                    Rectangle imgrect = new Rectangle(
                        cellBounds.X + cellStyle.Padding.Left,
                        cellBounds.Y + cellStyle.Padding.Top,
                        imgWidth,
                        imgWidth);

                    Rectangle rect = new Rectangle(
                        imgrect.Right + cellStyle.Padding.Horizontal,
                        cellBounds.Y + cellStyle.Padding.Top,
                        cellBounds.Width - (imgWidth + cellStyle.Padding.Horizontal),
                        cellBounds.Height - cellStyle.Padding.Vertical);

                    if (gl.Image != null)
                    {
                        double factor = Convert.ToDouble(gl.Image.Height) / Convert.ToDouble(gl.Image.Width);
                        if (factor < 1.0)
                        {
                            int orgHeight = imgrect.Height;
                            imgrect.Height = Convert.ToInt32(factor * Convert.ToDouble(imgrect.Height));
                            orgHeight     -= imgrect.Height;
                            orgHeight     /= 2;

                            imgrect.Y += orgHeight;
                        } //if (factor < 1.0)

                        if (factor > 1.0)
                        {
                            int orgWidth = imgrect.Width;
                            imgrect.Width = Convert.ToInt32(Convert.ToDouble(imgrect.Width) / factor);
                            orgWidth     -= imgrect.Width;
                            orgWidth     /= 2;

                            imgrect.X += orgWidth;
                        } //if (factor > 1.0)

                        graphics.DrawImage(gl.Image, imgrect);
                    } //if (gl.Image != null)

                    if (gl.Text != "")
                    {
                        Brush b = null;
                        if ((elementState & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected)
                        {
                            b = new SolidBrush(cellStyle.SelectionForeColor);
                        }
                        else
                        {
                            b = new SolidBrush(cellStyle.ForeColor);
                        };

                        StringFormat fmt = new StringFormat();
                        fmt.Alignment     = StringAlignment.Near;
                        fmt.LineAlignment = StringAlignment.Center;
                        graphics.DrawString(gl.Text, cellStyle.Font, b, rect, fmt);

                        ToolTipText = gl.Text;
                    } //if (gl.Text != "")
                }     //if (gl != null)
            }         //if (value != null)
        }             //protected override void Paint( ...