dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.42k stars 984 forks source link

The code generated by the DataGridView control has extra code for the RowTemplate.Height property #4461

Closed Tanya-Solyanik closed 1 year ago

Tanya-Solyanik commented 3 years ago

Problem description:

The generated code for dataGirdView1 has extra code for the RowTemplate.Height property. For the newly created control at 100% scaling, designer should generate the same value as is defined by the DefaultValueAttribute

image

Expected behavior: RowTemplate.Height line should not be generated

image

Minimal repro:

  1. Create a Winforms .Net Core application.
  2. Add a DataGridView to from designer.
  3. Double click to open Form1.Designer.cs file in Solution Explorer.
  4. Observe the generated code of the dataGridView1.

Note from Dustin: DataGridViewRow.Height has a [DefaultValue(22)] attribute, so the code-gen above is expected if the value is 25.

Tanya-Solyanik commented 3 years ago

DefaultValueAttribute should be adjusted to match the new default font

RussKie commented 2 years ago

Similar to https://github.com/dotnet/winforms/issues/4463#issuecomment-768831519.

Closing due to age. We can reopen it if/when we receive customer feedback.

kirsan31 commented 2 years ago

@RussKie

Closing due to age. We can reopen it if/when we receive customer feedback.

You have it for a long time already.

I was hoping that when you deal with this issue, I will be able to raise that too. Instead, you closed this one :)

Current issue is more fatal then my previous. To break Font scaling in my reported issue you was needed to add some styles. But with this - when simple adding new DataGridView (not always - see below) to the form - you completely break DPI and Font scaling 😁 And even if you fix it manually, you have to do it again and again after every use of the designer...

Details:

  1. this.dataGridView1.RowTemplate.Height = 25; line not always adding to Form1.Designer.cs. You need to open properties of dataGridView1 for this.
  2. There is a complete out of sync between the real values and what the designer shows.

https://user-images.githubusercontent.com/17767561/154912798-8bc356b9-c28e-4168-bbf7-98c30ca056ba.mp4

  1. Broken DPI scale: Snipaste_2022-02-21_10-40-55
RussKie commented 2 years ago

Thank you for linking the bug.

RussKie commented 2 years ago

@merriemcgaw can you please help prioritising this?

https://github.com/dotnet/winforms/issues/4463 should be considered as part of the fix.

kirsan31 commented 2 years ago

/cc @merriemcgaw

dreddy-work commented 2 years ago

@RussKie / @merriemcgaw this needs broader fix for every Control/Property impacted by the default Font change. So far i see two bugs in this context but there could be more.

merriemcgaw commented 2 years ago

We'll try to get to this in .NET 7, based on the feedback. We decided to do a deep dive into the default values and figure out what the best path foreword is.

John-Qiao commented 1 year ago

I duplicated the feedback ticket: https://developercommunity.visualstudio.com/t/Setting-DataGridViewRowHeight--22-in-P/10227470 with this issue.

merriemcgaw commented 1 year ago

Thanks @John-Qiao @dmitrii-drobotov - is this something that can go on your team's backlog?

dmitrii-drobotov commented 1 year ago

@dmitrii-drobotov - is this something that can go on your team's backlog?

Sure, I added it to our backlog.

dkazennov commented 1 year ago

Probably the best way to affect this Issue is to separate value of the Height property (in DataGridViewRow class) from the Thickness property (which in turn depends on Control.DefaultFont.Height). After that the DefaultValue attribute can be removed, new private const can be introduced as was proposed by @RussKie (with implementation of the Reset and ShouldSerialize methods).

This sets the correct intended value to the property in the property browser, and there is still the extra code.

image image

kirsan31 commented 1 year ago

@dkazennov thank you very match for doing this!

I want ask the team about related (but designer) issue - any chance this will be fixed? It's really very tiring to delete extra font instances every time after changing the form in the designer, and if you forget about it, font scaling breaks :(

paul1956 commented 1 year ago

I open 2 separate issue through Feedback with Extra Styles being generated for DataGridView and the format of the file alternates with every change (spaces are added and deleted) in comments and New Lines are deleted if initialized string is last before comment. Is the correct format for a comment the first or second, it seems to be inconsistent.

    '
    'Comment
   '

or

     '
    ' Comment
    '

Are there any test that compare results after each edit to look for side effects?

Tanya-Solyanik commented 1 year ago

I want ask the team about related (but designer) issue

The images are gone from the vs feedback website. @kirsan31 - could you please explain repro steps? Or even better - open individual issues in this repo.

@merriemcgaw - FYI.

kirsan31 commented 1 year ago

The images are gone from the vs feedback website. @kirsan31 - could you please explain repro steps?

Yea they are gone :( But we have gif form one of the responses: https://user-images.githubusercontent.com/4403806/118398742-578e5b00-b69d-11eb-9181-35f1045fb1f3.gif that explain one part of the issue.

Or even better - open individual issues in this repo.

Wil do...

dmitrii-drobotov commented 1 year ago

We have those images in the linked designer issue (https://github.com/microsoft/winforms-designer/issues/2225), I will duplicate it here as well: [pic1.png] pic1 [pic2.png] pic2 [gif1.gif] gif1 [gif2.gif] gif2

@kirsan31 - can you confirm these are the same images from the feedback post?

kirsan31 commented 1 year ago

@dmitrii-drobotov

@kirsan31 - can you confirm these are the same images from the feedback post?

Yes, they are 👍 Do I still need to create a new issue with them + description from original post?

dkazennov commented 1 year ago

@kirsan31 it would be great to have a new issue. Thanks!

kirsan31 commented 1 year ago

Or even better - open individual issues in this repo.

Done: https://github.com/dotnet/winforms/issues/8593

Nora-Zhou01 commented 1 year ago

Verified this on .NET latest build: 8.0.100-preview.3.23152.5, issue was fixed, RowTemplate.Height line cannot be generated and DataGridViewRow.Height value is 25. The screenshot as same as above. data

p