DXライブラリの関数にGetColorを設定するものがありますが、いちいち書くのは面倒なのでC#で作ってみました。
► スポイラーを表示
CODE:
//Form1.Designer.cs
namespace ColotSelect
{
partial class Form1
{
///
/// 必要なデザイナー変数です。
///
private System.ComponentModel.IContainer components = null;
///
/// 使用中のリソースをすべてクリーンアップします。
///
/// マネージ リソースが破棄される場合 true、破棄されない場合は false です。
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows フォーム デザイナーで生成されたコード
///
/// デザイナー サポートに必要なメソッドです。このメソッドの内容を
/// コード エディターで変更しないでください。
///
private void InitializeComponent()
{
this.colorDialog1 = new System.Windows.Forms.ColorDialog();
this.pictureBox1 = new System.Windows.Forms.PictureBox();
this.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
this.SuspendLayout();
//
// pictureBox1
//
this.pictureBox1.Location = new System.Drawing.Point(12, 12);
this.pictureBox1.Name = "pictureBox1";
this.pictureBox1.Size = new System.Drawing.Size(100, 50);
this.pictureBox1.TabIndex = 0;
this.pictureBox1.TabStop = false;
//
// button1
//
this.button1.Location = new System.Drawing.Point(118, 39);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(94, 23);
this.button1.TabIndex = 1;
this.button1.Text = "色の選択...";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(12, 72);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(200, 19);
this.textBox1.TabIndex = 2;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(224, 103);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.button1);
this.Controls.Add(this.pictureBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "色の選択";
((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.ColorDialog colorDialog1;
private System.Windows.Forms.PictureBox pictureBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.TextBox textBox1;
}
}
CODE:
//Form1.cs
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 ColotSelect
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//カラーダイアログのOKが押されたら
if (colorDialog1.ShowDialog() == DialogResult.OK)
{
//ピクチャーボックスに選択された色を設定
pictureBox1.BackColor = colorDialog1.Color;
textBox1.Text = string.Format("GetColor({0}, {1}, {2})", colorDialog1.Color.R.ToString(), colorDialog1.Color.G.ToString(), colorDialog1.Color.B.ToString());
}
}
}
}