开发者

How do you implement a Styling for Windows forms Application C#?

开发者 https://www.devze.com 2023-02-23 18:48 出处:网络
I am looking for a implementation for my Windows Application, where i can apply similar style to all similar controls (li开发者_C百科ke same style for all the Buttons).

I am looking for a implementation for my Windows Application, where i can apply similar style to all similar controls (li开发者_C百科ke same style for all the Buttons).

This implementation should be only in Windows Form ( not WPF). And no third party libraries/ controls.

Something like a custom control for button, and all the Buttons will inherit from the custom control.

Thanks!


Drag a rectangle around the controls so they all get selected. Ctrl+Left Click to adjust the selection. Change the property. Or create your own 'styled' button control by using class inheritance. Derive your own class from the Button class, change the properties in the constructor:

using System;
using System.Windows.Forms;

internal class MyButton : Button {
    public MyButton() {
        this.FlatStyle = FlatStyle.Flat;
        // etc..
    }
}

Override methods to alter behavior and appearance. After you compile, the new control is available at the top of the toolbox.


You want to create your own component and you want to use this component in everywhere.If I understood correct you can survey: here and here


foreach (Control ctr in this.Controls) {
    ctr.Color = Colors.Red;
    .
    .
    .
}

etc

You can have this kind of code in a separate style-class and pass your forms to it, thus making the style-class alter the components of the forms the way you wish.

0

精彩评论

暂无评论...
验证码 换一张
取 消