小编Lio*_*fel的帖子

C#:更改按钮BackColor无效

我在Windows窗体中遇到C#按钮问题.

我以编程方式创建了许多按钮,然后将它们添加到表单中.

有趣的是,除了修改之外,对这些按钮(位置和大小)的每次修改BackColor都很容易执行.只有按钮的颜色保持不变.

代码看起来像这样:

public class SimpleSortAlgDisplayer : ISortAlgDisplayer
{

    #region ISortAlgDisplayer Member

    void ISortAlgDisplayer.Init(int[] Data)
    {
        this.DataLength = Data.Length;
        this.DispWin = new CurrentSortStateWin();
        this.DispWin.Show();
        this.DispWin.Size = new Size(60 + (10 * this.DataLength), 120);

        this.myArrayElements = new Button[this.DataLength];
        for (int i = 0; i < this.DataLength; i++)
        {
            this.myArrayElements[i] = new Button();
            //begin of series of invoked actions

            this.myArrayElements[i].Size=new Size(5,(int)(((80)*(double)Data[i])/1000));
            this.myArrayElements[i].Location = new Point(30 + (i * 10), 90-(this.myArrayElements[i].Size.Height));
            this.myArrayElements[i].Enabled = true;
            this.myArrayElements[i].BackColor = Color.MidnightBlue;
            this.myArrayElements[i].UseVisualStyleBackColor = true; …
Run Code Online (Sandbox Code Playgroud)

c# button backcolor winforms

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

backcolor ×1

button ×1

c# ×1

winforms ×1