Results 1 to 11 of 11

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

  1. #1

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    Resolved [RESOLVED] 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
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    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
    557

    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
    557

    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,715

    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 is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  6. #6

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

    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,715

    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 is bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

  8. #8

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

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

    I'm trying this.
    Last edited by pourkascheff; Jun 3rd, 2023 at 12:23 PM.

  9. #9
    Angel of Code Niya's Avatar
    Join Date
    Nov 2011
    Posts
    8,598

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

    Quote Originally Posted by pourkascheff View Post
    I'm trying this.
    This has WPF written all over it. Not that WinForms can't do, it might be just a tad bit more difficult.
    Treeview with NodeAdded/NodesRemoved events | BlinkLabel control | Calculate Permutations | Object Enums | ComboBox with centered items | .Net Internals article(not mine) | Wizard Control | Understanding Multi-Threading | Simple file compression | Demon Arena

    Copy/move files using Windows Shell | I'm not wanted

    C++ programmers will dismiss you as a cretinous simpleton for your inability to keep track of pointers chained 6 levels deep and Java programmers will pillory you for buying into the evils of Microsoft. Meanwhile C# programmers will get paid just a little bit more than you for writing exactly the same code and VB6 programmers will continue to whitter on about "footprints". - FunkyDexter

    There's just no reason to use garbage like InputBox. - jmcilhinney

    The threads I start are Niya and Olaf free zones. No arguing about the benefits of VB6 over .NET here please. Happiness must reign. - yereverluvinuncleber

  10. #10

    Thread Starter
    Hyperactive Member pourkascheff's Avatar
    Join Date
    Apr 2020
    Location
    LocalHost
    Posts
    354

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

    Oh thanks for following up! Niya, the code detective. I built it once, Referenced the output *.dll file in another project, and woala, a good looking meanwhile simple and maybe the FASTEST way to achieve a set of WinForm darkmode controls. I linked it for possible other's cases but for professional uses, DevExpress bundle might be my final chose since their skins are beautifully done and all (including dark ones) containing up to 4 grades of color accents (Consider 42,42,42 next to 68,68,68 then 91,91,91 and 170,170,170).

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

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

    Quote Originally Posted by pourkascheff View Post
    and woala
    For the record, the word is "voila". It is French for "there it is".

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