0

I have a problem with the Font size. I have 2 Labels, both have the same properties, except 1 is red and underlined. So when I'm debugging, they should look the same. But the red & underlined is looking much bigger.

In the code I have all labels sizes set on 12, and if I check this, VB is confirming. But as you can see on the image, RED is much bigger then the black.

The 2 images on the left are taken seperatly (not debugging and debugging) on the right I took them while debugging and the top then is the original and bottom one is the one showing in debugging.

Below that you can see the font property, but in the code I have;

(Where: pu_FontSize = 12)

Private Sub FrmEnterPassword_Load(sender As Object, e As EventArgs) Handles Me.Load
    For Each ctrl As Control In Me.Controls
        ctrl.Font = New Font(ctrl.Font.FontFamily, pu_FontSize, ctrl.Font.Style)
    Next
End Sub

Can anyone help me, as I have no idea how to make those the same and this way look ugly.

Screencopy of labels

Jimi
  • 29,621
  • 8
  • 43
  • 61
Hans
  • 1
  • 3
  • Have you verified whether the *offending* Label is actually part of the Form.Controls collection or instead is *parented* to some other control (the `For Each ctrl As Control In Me.Controls` won't select it)? – Jimi Dec 08 '18 at 11:36
  • Hello Jimi, Thanks you for your reply. But yes I checked this and it is all parent to the form itself. I even test with the code inside the For Next loop and added test = ctrl.name. And all controls came thru. – Hans Dec 08 '18 at 14:50
  • I've tried to replicate the problem but couldn't. What I noticed is that the Font has a strange measure, something that you usually find in WPF, not in WinForms. Is it a Custom Control? Is there something that modifies the Font size or other properties? Have you tried to use another Font (Segoe UI, for example)? – Jimi Dec 08 '18 at 14:59
  • Hello Jimi, I just checked again and it seems that the problem is with Windows Scaling. If I put at 100% then it is okay. But when I increase to above 100% then I got this problem. Also when I remove the code part, there is no problem. But I can't figure out what is wrong in that code. But I will try as you say with another font – Hans Dec 08 '18 at 15:07
  • Just for one of the Labels?. Weird. Anyway, this means that your application is not DPI Aware. You need to add the `app.manifest` if you don't already have it, then uncomment (or add, depending on the VB.Net version) the DPIAware section of the manifest. Use this answer as reference: [How to configure an app to run correctly on a machine with a high DPI setting](https://stackoverflow.com/questions/13228185/how-to-configure-an-app-to-run-correctly-on-a-machine-with-a-high-dpi-setting-e?answertab=active#tab-top). Also, see whether that Label has `UseCompatibleTextRenderingDefault` set to true. – Jimi Dec 08 '18 at 15:10
  • Hello Jimi, just tried with font Segoe UI and this doesn't show this problem. So will be then that Sans Serif problem. Thanks for your help, I didn't think about this font part. But will then use this Segoe UI thru all the program. – Hans Dec 08 '18 at 15:13
  • Hello Jimi, I never done this app,config change. Do I need to copy just somewhere between and or right above or below this but still in between of and ?? By the way the app.manifest looked the same as the link that you send. And also by the way, it is standard label not custom. – Hans Dec 08 '18 at 15:29
  • It's not the `app.config`, it's the `app.manifest` you have to edit. Follow the example in the answer I linked. If you don't have an `app.manifest` add one using the `Project->Add...` shortcut and find `app.manifest` among the standard objects yu can add to a Project. You just need to uncomment the section that contains `true`. If it's not there (VB.Net version dependent) add the whole section as shown in the link. – Jimi Dec 08 '18 at 15:34
  • Hello Jimi, got it. uncomment the Windows 10 in the app.manifest But it doesn't change, with Microsoft Sans Seriff, so I will use the font Segoe UI, which will do the job. Thanks for your help. – Hans Dec 08 '18 at 15:53
  • That section is unrelated to the DPI Awareness settings. The section that follows is the right one where you find `true`. – Jimi Dec 08 '18 at 15:57
  • This is and was already like so. – Hans Dec 08 '18 at 15:58
  • Yep. Have you uncommented it (removing the `` blocks)? – Jimi Dec 08 '18 at 15:58
  • This I now did and indeed it works all much better. Also with some screens, I couldn't use startposition -- Centerscreen and needed to adjust by code. But this also is working like a charme. You are much appreciated for your patience and help. – Hans Dec 08 '18 at 16:06
  • And I'm sorry for the missundrstandings, as I never worked with this app.manifest before and was not sure about these <-- and --> – Hans Dec 08 '18 at 16:08
  • No problem. We're all here to learn something new :) – Jimi Dec 08 '18 at 16:09

0 Answers0