Skip to content

dataGridView doesn't respect font settings if new form's Font != DefaultFont #3033

Closed

Description

@kirsan31

---UPD---
Clarifications: #3033 (comment)

  • .NET Core Version: 3.1.2

  • Have you experienced this same bug with .NET Framework?: Yes, must set font of the form != DefaultFont

Problem description:
dataGridView doesn't respect font settings in Styles (DefaultCellStyle, ColumnHeadersDefaultCellStyle...):
Snipaste_2020-04-02_17-00-10

Expected behavior:
dataGridView must respect font settings.

Windows 7 x64.

Minimal repro:
WinFormsCoreTest3.zip

Activity

  1. added this to the 5.0 milestone on Apr 2, 2020
  2. added
    🪲 bug
    💥 regression-preview
    on Apr 2, 2020
  3. RussKie commented on Apr 2, 2020

    @RussKie
    Contributor

    Is this a blocker? If so, what is the impact? We need to have a good justification for the servicing team.

  4. kirsan31 commented on Apr 3, 2020

    @kirsan31
    ContributorAuthor

    @RussKie

    Is this a blocker? If so, what is the impact? We need to have a good justification for the servicing team.

    Yes of course! Grid control is totally broken - you can't customize fonts!!! In migration (to core) terms: every grid with custom fonts (in our apps it's all of them - 100%) are broken.

  5. Lydia-Shi commented on Apr 8, 2020

    @Lydia-Shi
    1. Framework project
      Set DataGridView ColumnHeadersDefaultCellStyle , run project and DataGridView Style show correctly. Then modify the Form font in Properties Window, Form1.Desginer. cs will be updated and influence DataGridVeiw style Settings, as follows:
      Framework
    2. Core project
      Copy the DataGridView ColumnHeadersDefaultCellStyle Settings from the Framework project, run project and DataGridView Style show correctly.
      Then add code “this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));” in Form1.Desginer.cs to change the Form Font, run project and DataGridView does not display the style of setting, result as below:
      Core11
  6. kirsan31 commented on Apr 8, 2020

    @kirsan31
    ContributorAuthor

    Confirmed - setting the form font breaks dataGridView fonts...
    Due to the change of the default font in core, we had to explicitly set the font in each form during migration.

  7. modified the milestones: 5.0 Previews 1-4, 5.0 on Apr 20, 2020
  8. SergeySmirnov-Akvelon commented on Jul 16, 2020

    @SergeySmirnov-Akvelon
    Contributor

    Hi @RussKie . I have reproduced this issue on .NET Framework (4.7.1 and 4.8) and .NET Core (3.1 and 5.0). Issue is reproduced when Form's file contains next code:
    this.Font = new System.Drawing.Font(...)
    CTI team also reproduced it on .NET Framework project (#3033 (comment)).
    I asked CTI team verify it and confirm. If this is confirmed, then we must remove the regression label

  9. weltkante commented on Jul 16, 2020

    @weltkante
    Contributor

    If this is confirmed, then we must remove the regression label

    I'd still consider fixing this important (and arguably a regression), since porting applications to .NET Core currently requires setting the font and thus triggering the bug, while on Desktop you could get away with not setting it.

    Alternatively implement #3001 then fixing this issue is (probably?) not so important anymore.

  10. kirsan31 commented on Jul 16, 2020

    @kirsan31
    ContributorAuthor

    @SergeySmirnov-Akvelon

    Form's file contains next code:
    this.Font = new System.Drawing.Font(...)

    This is not exactly the truth. Strictly speaking the problem appear when the form Font != DefaultFont.
    So this line

    this.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204)));

    will not break .net Framework version. And this:

    this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point);

    will not break .net core version.

    @weltkante

    Alternatively implement #3001 then fixing this issue is (probably?) not so important anymore.

    I am afraid that this will not help :( ...

    Also, during testing, I found that changing the form's Font - will delete ColumnHeadersDefaultCellStyle and RowHeadersDefaultCellStyle 😳

    DGV Intresting to check this in new core designer...

  11. RussKie commented on Jul 16, 2020

    @RussKie
    Contributor

    Also, during testing, I found that changing the form's Font - will delete ColumnHeadersDefaultCellStyle and RowHeadersDefaultCellStyle

    Please raise in the designer repo. /cc: @merriemcgaw

  12. 34 remaining items

  13. linked a pull request that will close this issueDo not reset user fonts in DataGridView #3875on Sep 16, 2020
  14. added this to the 5.0 RC2 milestone on Sep 16, 2020
  15. ghost removed
    🚧 work in progress
    on Sep 21, 2020
  16. modified the milestones: 5.0 RC2, 6.0 Preview1 on Sep 22, 2020
  17. Zheng-Li01 commented on Oct 14, 2020

    @Zheng-Li01
    Member

    Verified the issue with .NET SDK 5.0.100-rtm.20513.7 that the issue has been fixed that in runtime, the font of DataGridView ColumnHeaders, Cell, Rowheaders is changed as design time

  18. removed this from the 6.0 Preview1 milestone on Oct 19, 2021
  19. ghost locked as resolved and limited conversation to collaborators on Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    🪲 bugarea-controls-DataGridView

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions