質問

I'm building a program on which I'm hoping to have a black background and white text.


I've tried setting the background color to black, the forecolor/font color to white, but during highlight I want two different colors and another two during while clicked. I can't find the proper way to manipulate the properties. Has anyone else ever tried this?

Thank you.

役に立ちましたか?

解決

I've figured out how to do this using the link attached at the top of this one. However, the resources I had to dig out around it lead me to believe this deserves to stand as its own question.

What I did

I went onto my MainForm and inserted the following code (as per the suggested solution):

public MainForm()
    {
        InitializeComponent();
        menuStripMain.Renderer = new MyRenderer();
    }

    private class MyRenderer : ToolStripProfessionalRenderer
    {
        public MyRenderer() : base(new MyColors()) { }
    }

    private class MyColors : ProfessionalColorTable
    {
        public override Color MenuItemSelected
        {
            get { return Color.White; }
        }
        public override Color MenuItemSelectedGradientBegin
        {
            get { return Color.Black; }
        }
        public override Color MenuItemSelectedGradientEnd
        {
            get { return Color.SlateGray; }
        }
        public override Color MenuItemBorder
        {
            get { return Color.Yellow; }
        }
    }

However, as you can see, there are properties that are not included in the solution. The parts that you want to manipulate here can be made to work for any object on your form, not just the menu strip, the reference names for which you can access here. In addition, there is a large collection of colors with odd names that can be addressed, the list for which is right here. I don't think you can use hex color codes.

This way you can completely customize the colors of any object in your form!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top