本文介绍了为什么不toolstriplabel的在设计时或运行时背景色属性的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在运行时一个工具条标签,其背部颜色变了,但无论我做什么。它只是不会改变它的背景色,即使他们给选项来改变它的背景色。这是为什么,你如何得到它的背景色属性在运行时或设计时改变吗?

I need to have a toolstrip label and its back color changed during runtime, but no matter what I do. It just won't change its backcolor, even though they give option to change its backcolor. Why is that and how do you get its backcolor property to change during runtime or design time?

在此先感谢,

推荐答案

这是受的ToolStrip的RenderMode设置。只有当你把它改为系统将背景色属性都有影响。其他渲染器使用的主题颜色。你可能不会喜欢系统非常多,但你可以有你的蛋糕,并通过实现自己的渲染吃蛋糕。使它看起来类似于这样:

This is affected by the ToolStrip's RenderMode setting. Only when you change it to System will the BackColor property have an effect. The other renderers use theme colors. You are probably not going to like System very much, but you can have you cake and eat it too by implementing your own renderer. Make it look similar to this:

public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
        this.toolStrip1.Renderer = new MyRenderer();
    }
    private class MyRenderer : ToolStripProfessionalRenderer {
        protected override void OnRenderLabelBackground(ToolStripItemRenderEventArgs e) {
            using (var brush = new SolidBrush(e.Item.BackColor)) {
                e.Graphics.FillRectangle(brush, new Rectangle(Point.Empty, e.Item.Size));
            }
        }
    }
}

这篇关于为什么不toolstriplabel的在设计时或运行时背景色属性的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 12:48