c# 设置控件的前景颜色和背景颜色

AutoSize:设置为false取消自动计算尺寸功能,控件的大小则按照设定的Size来呈现,设置为true自动计算大小this

TextAlign:设置对齐方式spa

//
// 摘要:
// 用默认的全部者运行通用对话框。
//
// 返回结果:

[TargetedPatchingOptOut("Performance critical to inline this type of method across NGen image boundaries")]
public DialogResult ShowDialog();    // System.Windows.Forms.DialogResult.OK 若是用户单击肯定在对话框中;不然为 System.Windows.Forms.DialogResult.Cancel。3d

 

一、建立一个这样的窗体code

二、加入ColorDialog控件orm

三、编写按键程序blog

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace 设置控件前景色和背景色
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnBackColor_Click(object sender, EventArgs e)
        {
            //调用ShowDialog方法显示用于选择颜色的窗口
            if (this.colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                //若是单击“确认键",showDialog方法返回DialogResult.OK
                this.label1.BackColor = this.colorDialog1.Color;//设置label1的背景颜色
            }

        }

        private void btnForeColor_Click(object sender, EventArgs e)
        {
            if (this.colorDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                this.label1.ForeColor = this.colorDialog1.Color;//设置label1的前景颜色
            }
        }
    }
}

四、效果展现get

相关文章
相关标签/搜索