System.Windows.Forms


.NET Framework クラス ライブラリ
ColorDialog クラス

使用できる一連の色と、ユーザーがカスタム カラーを定義するために使用できるコントロールを表示するコモン ダイアログ ボックスを表します。

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

構文

Visual Basic (宣言)
Public Class ColorDialog
    Inherits CommonDialog
Visual Basic (使用法)
Dim instance As ColorDialog
C#
public class ColorDialog : CommonDialog
C++
public ref class ColorDialog : public CommonDialog
J#
public class ColorDialog extends CommonDialog
JScript
public class ColorDialog extends CommonDialog
解説

このコモン ダイアログ ボックスを作成するには、継承メンバ ShowDialog を呼び出す必要があります。HookProc をオーバーライドして、ダイアログ ボックスに対して特定のフック機能を実装することもできます。Color を使用して、ユーザーが選択した色を取得します。

ColorDialog のインスタンスを作成すると、一部の読み書き可能プロパティが初期値に設定されます。これらの初期値の一覧については、ColorDialog コンストラクタのトピックを参照してください。

使用例

新しい ColorDialog を作成する例を次に示します。この例では、TextBoxButton が配置されている既存のフォームからメソッドを呼び出す必要があります。

Visual Basic
Private Sub button1_Click(sender As Object, e As System.EventArgs)
    Dim MyDialog As New ColorDialog()
    ' Keeps the user from selecting a custom color.
    MyDialog.AllowFullOpen = False
    ' Allows the user to get help. (The default is false.)
    MyDialog.ShowHelp = True
    ' Sets the initial color select to the current text color,
    MyDialog.Color = textBox1.ForeColor

    ' Update the text box color if the user clicks OK 
    If (MyDialog.ShowDialog() = DialogResult.OK) Then
        textBox1.ForeColor =  MyDialog.Color
    End If

End Sub 'button1_Click
C#
private void button1_Click(object sender, System.EventArgs e)
 {
    ColorDialog MyDialog = new ColorDialog();
    // Keeps the user from selecting a custom color.
    MyDialog.AllowFullOpen = false ;
    // Allows the user to get help. (The default is false.)
    MyDialog.ShowHelp = true ;
    // Sets the initial color select to the current text color.
    MyDialog.Color = textBox1.ForeColor ;
    
    // Update the text box color if the user clicks OK 
    if (MyDialog.ShowDialog() == DialogResult.OK)
        textBox1.ForeColor =  MyDialog.Color;
 }
    
C++
private:
   void button1_Click( Object^ /*sender*/, System::EventArgs^ /*e*/ )
   {
      ColorDialog^ MyDialog = gcnew ColorDialog;
      // Keeps the user from selecting a custom color.
      MyDialog->AllowFullOpen = false;
      // Allows the user to get help. (The default is false.)
      MyDialog->ShowHelp = true;
      // Sets the initial color select to the current text color.
      MyDialog->Color = textBox1->ForeColor;
      
      // Update the text box color if the user clicks OK 
      if ( MyDialog->ShowDialog() == ::DialogResult::OK )
      {
         textBox1->ForeColor = MyDialog->Color;
      }
   }
J#
protected void button1_Click(Object sender, System.EventArgs e)
{
    ColorDialog myDialog = new ColorDialog();
    // Keeps the user from selecting a custom color.
    myDialog.set_AllowFullOpen(false);
    // Allows the user to get help. (The default is false.)
    myDialog.set_ShowHelp(true);
    // Sets the initial color select to the current text color.
    myDialog.set_Color(textBox1.get_ForeColor());
    // Update the text box color if the user clicks OK 
    if (myDialog.ShowDialog().Equals(get_DialogResult().OK)) {
        textBox1.set_ForeColor(myDialog.get_Color());
    }
} //button1_Click
継承階層

System.Object
   System.MarshalByRefObject
     System.ComponentModel.Component
       System.Windows.Forms.CommonDialog
        System.Windows.Forms.ColorDialog
スレッド セーフ

この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォーム

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 2.0、1.1、1.0
参照

タグ :


Page view tracker