Results 1 to 7 of 7

Thread: Idea to represent a sort of "Dark mode" in VB.NET

  1. #1

    Thread Starter
    Addicted Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    149

    Idea to represent a sort of "Dark mode" in VB.NET

    Well, hi. You may already guess what I've done so far:
    Code:
    Me.BackColor = Color.Black
    Me.ForeColor = Color.White
    For dark mode and
    Code:
    Me.BackColor = Color.White
    Me.ForeColor = Color.Black
    for light mode in an super easy way. But always cheap is cheap... it achieved with some problems let's say side effects. "Me" literally contains all of the controls but somehow 1) UserControls does not follow the color changing commands. plus 2) Some controls like Tab Control tab headers are always white therefore, they don't follow the color neither.

    What options you people recommend? Newer .NET frameworks may cover this feature already or calling a simple code to do that right? Or Parallel.For all controls to toggle their colour?
    Last edited by pourkascheff; Nov 16th, 2022 at 12:16 AM.
    𝕬𝖒𝖎𝖗 𝕽. 𝕻𝖔𝖚𝖗𝖐𝖆𝖘𝖈𝖍𝖊𝖋𝖋

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    109,290

    Re: Idea to represent a sort of "Dark mode" in VB.NET

    If you want to customise the look and feel of your app, you really ought to be using WPF rather than WinForms. It was built from the ground up to be customisable. If you want to stick with WinForms and it's not working with user controls then you'd have to throw in a recursive call. The tabs on a TabControl would take more work. On that, this is old but should still be applicable.

  3. #3
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    513

    Re: Idea to represent a sort of "Dark mode" in VB.NET

    Add interface for themed controls with one method that will set colors according theme. Implement the interface in every of your forms and controls. Create theme manager class and pass the root form and do what jmc said - scan recursively and if the control implements the theme interface - call the method to change the theme. This way you will have routine in each form and user control that you have to write and it will set the right colors of all standard controls in the form/user control.

  4. #4
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    513

    Re: Idea to represent a sort of "Dark mode" in VB.NET

    Small improvement could be to pass theme object with pre-defined colors (instead of dark/light parameter) so your forms and controls will be painted in these colors and you can quickly change the theme not only from light to dark but also to different color scheme - blue, red, green, lighter or darker variants of colors.

    It is a lot of work to get everything right, but when it's ready you will get nice looking UI.

  5. #5
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,194

    Re: Idea to represent a sort of "Dark mode" in VB.NET

    I have gone the route of writing my WinForm applications such that the UI is written in a web language and the logic lives in the WinForm application. When the form loads, I load the web UI into a WebView2 and then communicate back and forth between the WebView2 and the WinForm application.

    This isn't ideal for every situation, but I have been pleasantly surprised with how nice everything works.

    In this situation, based on the CSS framework, it's pretty easy to toggle between a light and dark mode because the components are typically written such that the CSS supports it. For example, in Ionic it is simply a matter of adding/removing the .dark class to the body.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Addicted Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    149

    Re: Idea to represent a sort of "Dark mode" in VB.NET

    Quote Originally Posted by dday9 View Post
    For example, in Ionic it is simply a matter of adding/removing the .dark class to the body.
    Can you add a graphical/actual example from what you achieved or it will be removed since it is VB.NET not-related content?
    𝕬𝖒𝖎𝖗 𝕽. 𝕻𝖔𝖚𝖗𝖐𝖆𝖘𝖈𝖍𝖊𝖋𝖋

  7. #7
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    11,194

    Re: Idea to represent a sort of "Dark mode" in VB.NET

    I'm not sure what you're asking for.
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width