DataGridView Paint Stacked Headers - PullRequest
0 голосов
/ 10 мая 2019

Я жду заголовки над ячейкой, но у меня странное поведение, в верхнем левом углу первой ячейки сложен или нарисован текст, который не виден в то время.

Я разместил весь код, который я использую для рисования, прокрутки и рисования ячеек, но я понятия не имею, что не так в коде, который вызывает это странное поведение.

См. Изображение:
stacked text

 private void DataGridView_overview_Paint(object sender, PaintEventArgs e)
        {
            Rectangle r0 = dataGridView_overview.GetCellDisplayRectangle(0, -1, true);
            Rectangle r1 = dataGridView_overview.GetCellDisplayRectangle(3, -1, true);
            Rectangle r2 = dataGridView_overview.GetCellDisplayRectangle(6, -1, true);
            Rectangle r3 = dataGridView_overview.GetCellDisplayRectangle(9, -1, true);
            Rectangle r4 = dataGridView_overview.GetCellDisplayRectangle(14, -1, true);
            Rectangle r5 = dataGridView_overview.GetCellDisplayRectangle(18, -1, true);
            Rectangle r6 = dataGridView_overview.GetCellDisplayRectangle(20, -1, true);
            Rectangle r7 = dataGridView_overview.GetCellDisplayRectangle(23, -1, true);
            Rectangle r8 = dataGridView_overview.GetCellDisplayRectangle(25, -1, true);
            Rectangle r9 = dataGridView_overview.GetCellDisplayRectangle(27, -1, true);
            Rectangle r10 = dataGridView_overview.GetCellDisplayRectangle(30, -1, true);
            Rectangle r11 = dataGridView_overview.GetCellDisplayRectangle(32, -1, true);
            Rectangle r12 = dataGridView_overview.GetCellDisplayRectangle(34, -1, true);
            Rectangle r13 = dataGridView_overview.GetCellDisplayRectangle(36, -1, true);
            Rectangle r14 = dataGridView_overview.GetCellDisplayRectangle(39, -1, true);
            Rectangle r15 = dataGridView_overview.GetCellDisplayRectangle(42, -1, true);
            Rectangle r16 = dataGridView_overview.GetCellDisplayRectangle(44, -1, true);
            Rectangle r17 = dataGridView_overview.GetCellDisplayRectangle(46, -1, true);
            Rectangle r18 = dataGridView_overview.GetCellDisplayRectangle(49, -1, true);
            Rectangle r19 = dataGridView_overview.GetCellDisplayRectangle(52, -1, true);
            Rectangle r20 = dataGridView_overview.GetCellDisplayRectangle(56, -1, true);

            int w2 = dataGridView_overview.GetCellDisplayRectangle(4, -1, true).Width;
            int w3 = dataGridView_overview.GetCellDisplayRectangle(5, -1, true).Width;

            int w4 = dataGridView_overview.GetCellDisplayRectangle(7, -1, true).Width;
            int w5 = dataGridView_overview.GetCellDisplayRectangle(8, -1, true).Width;

            int w6 = dataGridView_overview.GetCellDisplayRectangle(10, -1, true).Width;
            int w7 = dataGridView_overview.GetCellDisplayRectangle(11, -1, true).Width;
            int w8 = dataGridView_overview.GetCellDisplayRectangle(12, -1, true).Width;
            int w9 = dataGridView_overview.GetCellDisplayRectangle(13, -1, true).Width;

            int w10 = dataGridView_overview.GetCellDisplayRectangle(15, -1, true).Width;
            int w11 = dataGridView_overview.GetCellDisplayRectangle(16, -1, true).Width;

            int w12 = dataGridView_overview.GetCellDisplayRectangle(18, -1, true).Width;

            int w13 = dataGridView_overview.GetCellDisplayRectangle(21, -1, true).Width;
            int w14 = dataGridView_overview.GetCellDisplayRectangle(22, -1, true).Width;

            int w15 = dataGridView_overview.GetCellDisplayRectangle(24, -1, true).Width;

            int w16 = dataGridView_overview.GetCellDisplayRectangle(26, -1, true).Width;

            int w17 = dataGridView_overview.GetCellDisplayRectangle(28, -1, true).Width;
            int w18 = dataGridView_overview.GetCellDisplayRectangle(29, -1, true).Width;

            int w19 = dataGridView_overview.GetCellDisplayRectangle(31, -1, true).Width;

            int w20 = dataGridView_overview.GetCellDisplayRectangle(33, -1, true).Width;

            int w21 = dataGridView_overview.GetCellDisplayRectangle(35, -1, true).Width;

            int w22 = dataGridView_overview.GetCellDisplayRectangle(37, -1, true).Width;
            int w23 = dataGridView_overview.GetCellDisplayRectangle(38, -1, true).Width;

            int w24 = dataGridView_overview.GetCellDisplayRectangle(40, -1, true).Width;
            int w25 = dataGridView_overview.GetCellDisplayRectangle(41, -1, true).Width;

            int w26 = dataGridView_overview.GetCellDisplayRectangle(43, -1, true).Width;

            int w27 = dataGridView_overview.GetCellDisplayRectangle(45, -1, true).Width;

            int w28 = dataGridView_overview.GetCellDisplayRectangle(47, -1, true).Width;
            int w29 = dataGridView_overview.GetCellDisplayRectangle(48, -1, true).Width;

            int w30 = dataGridView_overview.GetCellDisplayRectangle(50, -1, true).Width;
            int w31 = dataGridView_overview.GetCellDisplayRectangle(51, -1, true).Width;

            int w32 = dataGridView_overview.GetCellDisplayRectangle(52, -1, true).Width;
            int w33 = dataGridView_overview.GetCellDisplayRectangle(53, -1, true).Width;
            int w34 = dataGridView_overview.GetCellDisplayRectangle(54, -1, true).Width;
            int w35 = dataGridView_overview.GetCellDisplayRectangle(55, -1, true).Width;

            int w36 = dataGridView_overview.GetCellDisplayRectangle(57, -1, true).Width;
            int w37 = dataGridView_overview.GetCellDisplayRectangle(58, -1, true).Width;
            int w38 = dataGridView_overview.GetCellDisplayRectangle(59, -1, true).Width;
            int w39 = dataGridView_overview.GetCellDisplayRectangle(60, -1, true).Width;

            r0.X += 1;
            r0.Y += 1;
            r0.Width = r0.Width + w2 + w3;
            r0.Height = r0.Height / 2 - 2;

            r1.X += 1;
            r1.Y += 1;
            r1.Width = r1.Width + w2 + w3;
            r1.Height = r1.Height / 2 - 2;

            r2.X += 1;
            r2.Y += 1;
            r2.Width = r2.Width + w4 + w5;
            r2.Height = r2.Height / 2 - 2;

            r3.X += 1;
            r3.Y += 1;
            r3.Width = r3.Width + w6 + w7 + w8 +w9;
            r3.Height = r3.Height / 2 - 2;

            r4.X += 1;
            r4.Y += 1;
            r4.Width = r4.Width + w10 + w11;
            r4.Height = r4.Height / 2 - 2;

            r5.X += 1;
            r5.Y += 1;
            r5.Width = r5.Width + w12;
            r5.Height = r5.Height / 2 - 2;

            r6.X += 1;
            r6.Y += 1;
            r6.Width = r6.Width + w13 + w14;
            r6.Height = r6.Height / 2 - 2;

            r7.X += 1;
            r7.Y += 1;
            r7.Width = r7.Width + w15;
            r7.Height = r7.Height / 2 - 2;

            r8.X += 1;
            r8.Y += 1;
            r8.Width = r8.Width + w16;
            r8.Height = r8.Height / 2 - 2;

            r9.X += 1;
            r9.Y += 1;
            r9.Width = r9.Width + w17 + w18;
            r9.Height = r9.Height / 2 - 2;

            r10.X += 1;
            r10.Y += 1;
            r10.Width = r10.Width + w19;
            r10.Height = r10.Height / 2 - 2;

            r11.X += 1;
            r11.Y += 1;
            r11.Width = r11.Width + w20;
            r11.Height = r11.Height / 2 - 2;

            r12.X += 1;
            r12.Y += 1;
            r12.Width = r12.Width + w21;
            r12.Height = r12.Height / 2 - 2;

            r13.X += 1;
            r13.Y += 1;
            r13.Width = r13.Width + w22 + w23;
            r13.Height = r13.Height / 2 - 2;

            r14.X += 1;
            r14.Y += 1;
            r14.Width = r14.Width + w24 + w25;
            r14.Height = r14.Height / 2 - 2;

            r15.X += 1;
            r15.Y += 1;
            r15.Width = r15.Width + w26;
            r15.Height = r15.Height / 2 - 2;

            r16.X += 1;
            r16.Y += 1;
            r16.Width = r16.Width + w27;
            r16.Height = r16.Height / 2 - 2;

            r17.X += 1;
            r17.Y += 1;
            r17.Width = r17.Width + w28 + w29;
            r17.Height = r17.Height / 2 - 2;

            r18.X += 1;
            r18.Y += 1;
            r18.Width = r18.Width + w30 + w31;
            r18.Height = r18.Height / 2 - 2;

            r19.X += 1;
            r19.Y += 1;
            r19.Width = r19.Width + w32 + w33 + w34 + w35;
            r19.Height = r19.Height / 2 - 2;

            r20.X += 1;
            r20.Y += 1;
            r20.Width = r20.Width + w36 + w37 + w38 + w39;
            r20.Height = r20.Height / 2 - 2;

            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r0);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r1);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r2);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r3);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r4);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r5);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r6);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r7);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r8);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r9);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r10);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r11);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r12);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r13);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r14);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r15);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r16);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r17);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r18);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r19);
            e.Graphics.FillRectangle(new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.BackColor), r20);

            StringFormat format = new StringFormat();

            format.Alignment = StringAlignment.Center;
            format.LineAlignment = StringAlignment.Center;

            e.Graphics.DrawString("Item Level", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r1, format);
            e.Graphics.DrawString("Heart Of Azeroth", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r2, format);
            e.Graphics.DrawString("Enchants", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r3, format);
            e.Graphics.DrawString("World Quests Done", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r4, format);
            e.Graphics.DrawString("Island Expedition", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r5, format);
            e.Graphics.DrawString("Mythic Dungeons Done", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r6, format);
            e.Graphics.DrawString("Mythic Dungeons Done", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r7, format);
            e.Graphics.DrawString("Raider.IO Score", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r8, format);
            e.Graphics.DrawString("Raid Bosses Killed", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r9, format);
            e.Graphics.DrawString("Reputations", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r10, format);
            e.Graphics.DrawString("Achievements", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r11, format);
            e.Graphics.DrawString("Mounts Owned", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r12, format);
            e.Graphics.DrawString("Unique Pets Owned", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r13, format);
            e.Graphics.DrawString("Professions", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r14, format);
            e.Graphics.DrawString("Honor Level", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r15, format);
            e.Graphics.DrawString("Honorable Kills", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r16, format);
            e.Graphics.DrawString("Current Ratings (PvP)", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r17, format);
            e.Graphics.DrawString("Highest Ever Ratings (PvP)", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r18, format);
            e.Graphics.DrawString("Games Played This Season (PvP)", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r19, format);
            e.Graphics.DrawString("Games Played This Week (PvP)", dataGridView_overview.ColumnHeadersDefaultCellStyle.Font, new SolidBrush(dataGridView_overview.ColumnHeadersDefaultCellStyle.ForeColor), r20, format);
        }

        private void DataGridView_overview_Scroll(object sender, ScrollEventArgs e)
        {
            Rectangle rtHeader = dataGridView_overview.DisplayRectangle;
            rtHeader.Height = dataGridView_overview.ColumnHeadersHeight / 2;
            dataGridView_overview.Invalidate(rtHeader);
        }

        private void DataGridView_overview_CellPainting(object sender, DataGridViewCellPaintingEventArgs e)
        {
           if (e.RowIndex == -1 && e.ColumnIndex > -1)
            {
                Rectangle r2 = e.CellBounds;
                r2.Y += e.CellBounds.Height / 2;
                r2.Height = e.CellBounds.Height / 2;
                e.PaintBackground(r2, true);
                e.PaintContent(r2);
                e.Handled = true;
            }
        }
...