CreateParams クラスとは? わかりやすく解説

CreateParams クラス

コントロール作成時に必要な情報カプセル化ます。

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

public class CreateParams
public ref class CreateParams
public class CreateParams
public class CreateParams
解説解説
使用例使用例

Button から派生した MyIconButton という名前のクラス作成しボタンイメージではなくアイコン表示するために必要な実装提供するコード例を、次に示しますCreateParams プロパティ拡張されボタンImage ではなく Icon表示するための値が Style プロパティ追加されます。

import System.*;
import System.Drawing.*;
import System.Windows.Forms.*;
import System.Runtime.InteropServices.*;
import System.Diagnostics.*;
import System.IO.*;
import System.Security.Permissions.*;

/** @attribute SecurityPermission(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)
 */
public class MyIconButton extends Button
{
    private Icon icon;

    public MyIconButton()
    {
        // Set the button's FlatStyle property.
        set_FlatStyle(get_FlatStyle().System);
    } //MyIconButton

    public MyIconButton(Icon ButtonIcon)
    {
        // Assign the icon to the private field.   
        this.icon = ButtonIcon;

        // Size the button to 4 pixels larger than the icon.
        this.set_Height(icon.get_Height() + 4);
        this.set_Width(icon.get_Width() + 4);
    } //MyIconButton

    /** @property 
     */
    protected CreateParams get_CreateParams()
    {
        // Extend the CreateParams property of the Button class.
        CreateParams cp = super.get_CreateParams();

        // Update the button Style.
        cp.set_Style(cp.get_Style() | 0x40); // BS_ICON value
        return cp;
    } //get_CreateParams

    /** @property 
     */
    public Icon get_Icon()
    {
        return icon;
    } //get_Icon

    /** @property 
     */
    public void set_Icon(Icon value)
    {
        icon = value;
        UpdateIcon();

        // Size the button to 4 pixels larger than the icon.
        this.set_Height(icon.get_Height() + 4);
        this.set_Width(icon.get_Width() + 4);
    } //set_Icon

    protected void OnHandleCreated(EventArgs
 e)
    {
        super.OnHandleCreated(e);

        // Update the icon on the button if there is currently an icon
 assigned 
        // to the icon field.
        if (icon != null) {
            UpdateIcon();
        }
    } //OnHandleCreated

    private void UpdateIcon()
    {
        IntPtr iconHandle = IntPtr.Zero;

        // Get the icon's handle.
        if (icon != null) {
            iconHandle = icon.get_Handle();
        }

        // Send Windows the message to update the button. 
        SendMessage(get_Handle(), 0x00F7 /*BM_SETIMAGE value*/, 
            1 /*IMAGE_ICON value*/, (iconHandle.ToInt32())); 
        
    } //UpdateIcon

    // Import the SendMessage method of the User32 DLL.   
    /** @attribute DllImport("user32.dll", CharSet = CharSet.Auto)
     */
    public static native IntPtr SendMessage(IntPtr
 hWnd, int msg, 
        int wParam, int lParam);
} //MyIconButton

標準Button コントロールインスタンスと、上記の例で作成した派生コントロール MyIconButtonインスタンス作成するコード例を、次に示します。この例では、アプリケーションと同じ場所に、Default.ico という Icon ファイル格納されている必要がありますアプリケーション起動すると、Default アイコンMyIconButton ボタン上に表示されます。Default アイコン存在しない場合ボタン表面空白になります標準Buttonクリックすると、OpenFileDialog ボックス表示されMyIconButton 上に表示する新しアイコン選択できるようになります

public class MyApplication extends Form
{
    private MyIconButton myIconButton;
    private Button stdButton;
    private OpenFileDialog openDlg;

    public static void main(String[]
 args)
    {
        Application.Run(new MyApplication());
    } //main

    public MyApplication()
    {
        try {
            // Create the button with the default icon.
            myIconButton = new MyIconButton(new
 Icon(Application.
                get_StartupPath() + "\\Default.ico"));
        }
        catch (System.Exception ex) {
            // If the default icon does not exist, 
            // create the button without an icon.
            myIconButton = new MyIconButton();
            Debug.WriteLine(ex.ToString());
        }
        finally {
            stdButton = new Button();

            // Add the Click event handlers.
            myIconButton.add_Click(new EventHandler(this.myIconButton_Click));
            stdButton.add_Click(new EventHandler(this.stdButton_Click));

           // Set the location, text and width of the standard button.
           stdButton.set_Location(new Point(myIconButton.get_Location().
               get_X(), myIconButton.get_Location().get_Y() 
               + myIconButton.get_Height() + 20));
           stdButton.set_Text("Change Icon");
           stdButton.set_Width(100);

// Add the buttons to the Form.
this.get_Controls().Add(stdButton);
this.get_Controls().Add(myIconButton);
      }
    } //MyApplication

    private void myIconButton_Click(Object
 Sender, EventArgs e)
    {
        // Make sure MyIconButton works.
        MessageBox.Show("MyIconButton was clicked!");
    } //myIconButton_Click

    private void stdButton_Click(Object Sender,
 EventArgs e)
    {
        // Use an OpenFileDialog to allow the user to assign a new image
 to 
        // the derived button.
        openDlg = new OpenFileDialog();
        openDlg.set_InitialDirectory(Application.get_StartupPath());
        openDlg.set_Filter("Icon files (*.ico)|*.ico");
        openDlg.set_Multiselect(false);
        openDlg.ShowDialog();
        if (!(openDlg.get_FileName().Equals(""))) {
            myIconButton.set_Icon(new Icon(openDlg.get_FileName()));
        }
    } //stdButton_Click
} //MyApplication
継承階層継承階層
System.Object
  System.Windows.Forms.CreateParams
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「CreateParams クラス」の関連用語

CreateParams クラスのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



CreateParams クラスのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS