WinForms application -- how best to apply a theme or style such as "dark mode" - winforms

I am working on a WinForms application and I want to have the ability to apply a style, more specifically to allow the user to chose "Light Mode" or "Dark Mode" for the application. There doesn't seem to be much support for that.
My plan was to write something that can be applied on the UserComponents and forms OnLoad, maybe in a base class -- walk the control tree and apply suitable colors, fonts etc. But it seems like a common requirement. So I was wondering if there is a prebaked solution that I can use.
I had a look around on google and here and didn't seem to find anything.

Related

Visual Studios Controls

Is there a way to download more controls or anything, because I have seen a few things in other programs I don't think I've seen in the toolbox. Can you download new ones, or did the company somehow custom make a control? If it was custom made, are there any tutorials I can take a look at that tell how to make your own?
Some companies make third party controls for Winforms - Telerik is one I know of.
Personally, I prefer to make my own controls based on the existing WinForms ones, as I have more control over them - this prevents my products from having bugs which just can't be fixed. I can also tweak the controls to do exactly what I need, rather than choosing a closest match. Building custom controls is relatively easy if you have the experience.
There is a basic tutorial on CodeProject which shows how to create a fancy Button. After that you should be able to figure out how to customize more complex controls.
Side-note:
While it's reasonably easy to develop custom controls in WinForms if you have the time to practice, WPF is a much better framework for building custom controls. WPF controls are designed specifically for customization, so there is a lot more flexibility.

Why do WPF apps look like web pages?

I apologize for my newbie question by why do WPF apps look like web pages?
I am new to gui and still shopping for a book to learn gui programming. The push seems to be in the direction of WPF but all the screenshots of WPF applications that I've seen look like cheap web pages. Frankly I'd be ashamed to sell an app that looked like a web page.
I realize that WPF is built on XML technology but can you not build normal looking WPF apps in Visual Studio (via button("widget")) drag-n-drop? In other words an app that does not look like a web page?
How can WPF be a replacement for WinForms or the like when it doesn't provide the same standard application look?
The default look of WPF applications is admittedly rather simple, but WPF allows unprecedented control over how your application looks.
Here are some examples, all of them WPF applications.
If you are to deveop an application under .net and are able to target .net 3.5 or above, you will want to use wpf. If you don't know much about ui technology and want to work with .net, understanding windows forms is useful but not necessary. You should learn wpf regardless.
2 perks that I have found while using the framework:
- it is very easy to inject branding and custom interactivity into your app. It is then very easy to change these when your sales guy decides the want it blue, not red.
- the way components are organized on screen is relational like a webpage, not coordinate based like windows forms. This is ideal for scenarios when translated strings will change length (English to German for example). Under usual circumstances the ui will resize itself automatically at runtime to make it all fit.
If you just throw in controls and don't change the style of anything, your first wpf applications will look almost identical to native win32 applications. It is very easy to change this, but you will achieve great results regardless of the "look" you choose. Microsoft also provide the tools to create new ui components that look like native buttons. There are a host of other features that will make you grin while learning!
This is not a technical note, but at the moment wpf is a highly sellable skill and looks great on a cv! Companies want great branding in their apps. Wpf helps that happen.
WPF does provide the same appication look wich is the default look. When you drag and drop your controls onto the design surface (just like in windows forms, MFC ...) the controls look as you would expect them to look under the current theme. Chances are that you have seen quite some WPF applications without noticing. Just because they look like any other app.
The reason you might see more WPF based applications that have some sort of custom look and feel to them is simple because it is so much easier to do what ever you like to your GUI than in any other GUI framework on any platform. This is both blessing and curse. While you being absolutely flexible it is easy to do absolutely horrible stuff.
user440267, I believe that the most application in WPF are built using normal Windows. But there is an option which we don't create a window, instead we create a page, which behave like you think.

Coded UI Test - get my custom object (WinForms)?

I want to create an automated UI test that will test my syncfusion grid. My problem is that the recorder can't recognize this control (or any syncfusion control). I've searched a lot in the internet but I couldn't find any extension so the recorder will recognize my controls (I'm using WinForms, not WPF!), or at least a way to extend the recorder abilities so syncfusion's controls will be recognized somehow.
Is there any easy way to extend the recorder? Or is there any extension available?
Or maybe can I get the grid object from the WinClient that the recorder generates?
Thanks!
Start your program. Run the Spy++ utility. Type Ctrl+F to start the finder tool and drag the bulls-eye onto your form. Ok, Synchronize and have a look-see at the windows that are visible in the tree. If you see regular Windows Forms controls, like a Button or a Label, but not any of the SyncFusion controls then you've probably found the source of the problem.
Component vendors that try to improve .NET controls typically do so by creating 'window-less' controls. They are not really controls, they don't derive from the Control class and don't have a Handle property. They use the surface of the parent to draw themselves, making them look just like controls. The .NET ToolStripItem classes do this. And this is also the approach WPF uses.
The big advantage is that they render quickly and support all kinds of effects that regular controls can't support, like transparency, rotation and anti-aliased window edges. The big disadvantage is that the kind of tool that you are using suddenly gets noddy and can't find the control back. Because they work by finding the Windows window back on your form, there is no window for them.
This is a hard problem to solve, the 'control' exists only in memory and there's no good way for a tool to find it back. Using Accessibility is about the only other way for such a tool to find a control that I can think of. Which would have to be implemented by the control vendor first, a somewhat obscure feature that gets easily overlooked. You really do need the help of the vendor to find a workaround for this. Shouldn't be a problem, that's why you paid them the big money.
This is Rajadurai from Syncfusion. Thank you for your interest in Syncfusion Products. To make UI Test Automation recognize Syncfusion grids(WinForms), some internal support need to be provided in grid whose implementation is in progress and about to be completed. Please submit an incident through Direct-Trac for any further related inquiries in the following link.
http://www.syncfusion.com/Account/Logon?ReturnUrl=%2fsupport%2fdirecttrac
You can also contact us through support#syncfusion.com. We are happy to assist you.
Regards,
Rajadurai

User input custom control (text editor)

I am developing a CAD like application. This application is cross platform in the sense that I have a main window which is native to the platform it is running on (Linux, Windows and Apple). Within this window I have an OpenGL context and there I do all my rendering. The application in question does not really rely on common controls (radio buttons, check-boxes, labels etc), however there is the need for the user to be able to enter/edit some text. This text could be a few lines long but not more than one hundred.
How would I go about implementing such a control, I don't want to go as deep as developing my own text editor but it would be nice if it had some basic editor controls (cursor movement, delete, insert etc). I also don't want to use the native systems common controls as my own none cross platform code at the moment is the main window.
Any ideas?
Edit: This is informative
OPENGL User Interface Programming
Thank you
I think you are taking a longer approach here.
Rather than providing an interface through OpenGL and writing my own controls, I would go for a cross-platform GUI toolkit such as wxWindows, and use the GLCanvas provided to do my rendering. You'll have all the might and flexibility of common controls, you'll still be able to OpenGLize whatever you want, and the look of your application will be more standard, thus friendlier.

WPF ControlTemplate How to

I am very new to WPF, about 4 hours new. I am coming from ASP.net and Masterpages.
I was looking at examples of Control Template that can used to template a window so all windows look the same.
Other post
Can some direct me to an example of how it is accomplished or sample code from start to finish?
Second part:
Is the ControlTemplate the best way to go about building WPF windows client applications? What is best practices in architecting WPF windows applications.
Thanks
There really isn't a "best" way to architect WPF UIs. It all depends on the user experience your application will have.
If you want a very web-like experience you are probably better of using the pages constructs. Otherwise if you have windows, but want a common header, you may just want to make a control template for that. Maybe you need separate windows or maybe you just need to have a sub part of a grid panel change content depending on state... There are different ways to do things that are more or less suited to the type of client experience you want.
Although there are some best practices in relation to using MVC/MVVM design patterns, there isn't a "best" way to style and theme your controls. I don't consider WPF as friendly to newcomers as WinForms were, but at the same time it seems a lot more powerful in the long run. What might help you out are some basic levels of theming:
Styles: these are mainly aesthetic changes to the look and feel of basic controls and elements with some very basic support for triggering things like mouse cursor roll over. They are similar to CSS on webpages.
Control Templates: these are the more heavyweight versions of styles where you actually reconstitute a control so that, say a button can have a textbox inside of it. Where styles work on a logical level where something like a button is the most atomic element, control templates can drill down further into controls so that the border, background, text, etc of a button are seen as separate elements instead of one atomic part.
Data Templates: A more focused version of control templates meant to customize how data items in lists are drawn. If you have a bunch of pictures you don't want the file name to show up in the listbox, you'd rather have the image itself. A data template lets you accomplish this kind of thing.
So you have to ask yourself when you say, "Make all windows look the same," do you mean changes are merely aesthetic/looks (styles), customizing how a collection of items are displayed (data/item templates) or altogether changing how a standard control looks and behaves or making sure the layout of controls on a page are the same across multiple windows/pages (control templates)?
Finally, the "end to end" of the other post you linked to is pretty simple. You take the control template there, and under your tag you simply add Template={StaticResource MyTemplateName} and the template is applied. This article on MSDN is a decent intro to control templating.

Resources