* 程序的版权和版本声明部分
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.
* Copyright (c) 2012, 烟台大学计算机学院学生
* All rights reserved.
* 作 者: 刘镇
* 完成日期: 2012 年 11 月 18 日
* 版 本 号: 3.025
* 对任务及求解方法的描述部分
* 问题描述:
创建一个如下的窗体,并在窗体上放置colorDialog控件。实现功能:1)程序运行时,单击打开颜色对话框按钮,可选择颜色,并以所选颜色作为窗体背景色。
*代码部分:
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 Win10_4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
colorDialog1.AllowFullOpen = true;
colorDialog1.FullOpen = true;
colorDialog1.ShowHelp = true;
colorDialog1.Color = Color.DarkBlue;
if (colorDialog1.ShowDialog() != DialogResult.Cancel)
{
this.BackColor = colorDialog1.Color;
}
}
private void button2_Click(object sender, EventArgs e)
{
colorDialog1.AllowFullOpen = true;
colorDialog1.FullOpen = true;
colorDialog1.ShowHelp = true;
colorDialog1.Color = Color.DarkBlue;
if (colorDialog1.ShowDialog() != DialogResult.Cancel)
{
this.button1.BackColor = colorDialog1.Color;
}
}
}
}
测试结果:

本文介绍如何在窗体中集成颜色对话框,实现用户选择颜色并应用于窗体背景的功能,包括代码实现与测试结果。
3715

被折叠的 条评论
为什么被折叠?



