CreateParams 클래스

정의

컨트롤을 만들 때 필요한 정보를 캡슐화합니다.

public ref class CreateParams
public class CreateParams
type CreateParams = class
Public Class CreateParams
상속
CreateParams

예제

다음 코드 예제에서는 한 Button 라는 클래스를 파생 MyIconButton 이미지 대신 아이콘을 표시 하려면 단추에 대해 필요한 구현을 제공 합니다. CreateParams 속성을 확장 및에 값을 추가 합니다 Style 표시할 단추를 발생 시킨 속성입니다는 Icon 아닌 Image합니다.

#include <windows.h>

#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>

using namespace System;
using namespace System::Drawing;
using namespace System::Windows::Forms;
using namespace System::Runtime::InteropServices;
using namespace System::Diagnostics;
using namespace System::IO;

public ref class MyIconButton: public Button
{
private:
   Icon^ icon;

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

   MyIconButton( Icon^ ButtonIcon )
   {
      
      // Set the button's FlatStyle property.
      FlatStyle = ::FlatStyle::System;
      
      // Assign the icon to the private field.
      this->icon = ButtonIcon;
      
      // Size the button to 4 pixels larger than the icon.
      this->Height = icon->Height + 4;
      this->Width = icon->Width + 4;
   }


protected:

   property System::Windows::Forms::CreateParams^ CreateParams 
   {

      virtual System::Windows::Forms::CreateParams^ get() override
      {
         
         // Extend the CreateParams property of the Button class.
         System::Windows::Forms::CreateParams^ cp = __super::CreateParams;

         // Update the button Style.
         cp->Style |= 0x00000040; // BS_ICON value
         return cp;
      }
   }

public:
   property System::Drawing::Icon^ Icon
   {
      System::Drawing::Icon^ get()
      {
         return icon;
      }
      void set(System::Drawing::Icon^ value)
      {
         icon = value;
         UpdateIcon();
         this->Height = icon->Height + 4;
         this->Width = icon->Width + 4;
      }
   }

protected:
   virtual void OnHandleCreated( EventArgs^ e ) override
   {
      Button::OnHandleCreated( e );
      
      // Update the icon on the button if there is currently an icon assigned to the icon field.
      if ( icon != nullptr )
      {
         UpdateIcon();
      }
   }


private:
   void UpdateIcon()
   {
      IntPtr iconHandle = IntPtr::Zero;
      
      // Get the icon's handle.
      if ( icon != nullptr )
      {
         iconHandle = icon->Handle;
      }

      
      // Send Windows the message to update the button.
      SendMessage( (HWND)Handle.ToPointer(), 0x00F7, 1, (int)iconHandle );
      
      /*BM_SETIMAGE value*/
      /*IMAGE_ICON value*/
   }

   public:
    [DllImport("user32.dll")]
    static LRESULT SendMessage(HWND hWnd, int msg, int wParam, int lParam);

};
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;

public class MyIconButton : Button
{
    private Icon icon;

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

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

        // Size the button to 4 pixels larger than the icon.
        this.Height = icon.Height + 4;
        this.Width = icon.Width + 4;
    }

    protected override CreateParams CreateParams
    {
        get
        {
            // Extend the CreateParams property of the Button class.
            CreateParams cp = base.CreateParams;
            // Update the button Style.
            cp.Style |= 0x00000040; // BS_ICON value

            return cp;
        }
    }

    public Icon Icon
    {
        get
        {
            return icon;
        }

        set
        {
            icon = value;
            UpdateIcon();
            // Size the button to 4 pixels larger than the icon.
            this.Height = icon.Height + 4;
            this.Width = icon.Width + 4;
        }
    }

    protected override void OnHandleCreated(EventArgs e)
    {
        base.OnHandleCreated(e);

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

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

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

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

    // Import the SendMessage method of the User32 DLL.   
    [DllImport("user32.dll", CharSet = CharSet.Auto)]
    public static extern IntPtr SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);
}
Imports System.Windows.Forms
Imports System.Drawing
Imports System.IO
Imports System.Security.Permissions

Public Class MyIconButton
    Inherits Button

    Private ButtonIcon As Icon

    Public Sub New()
        MyBase.New()

        ' Set the button's FlatStyle property.
        Me.FlatStyle = System.Windows.Forms.FlatStyle.System
    End Sub

    Public Sub New(ByVal Icon As Icon)
        MyBase.New()

        ' Assign the icon to the private field.   
        Me.ButtonIcon = Icon

        ' Size the button to 4 pixels larger than the icon.
        Me.Height = ButtonIcon.Height + 4
        Me.Width = ButtonIcon.Width + 4
    End Sub


    Protected Overrides ReadOnly Property CreateParams() As System.Windows.Forms.CreateParams
        Get
            Dim SecPerm As New SecurityPermission(SecurityPermissionFlag.UnmanagedCode)
            SecPerm.Demand()

            ' Extend the CreateParams property of the Button class.
            Dim cp As System.Windows.Forms.CreateParams = MyBase.CreateParams
            ' Update the button Style.
            cp.Style = cp.Style Or &H40 ' BS_ICON value

            Return cp
        End Get
    End Property

    Public Property Icon() As Icon
        Get
            Return ButtonIcon
        End Get

        Set(ByVal Value As Icon)
            ButtonIcon = Value
            UpdateIcon()
            ' Size the button to 4 pixels larger than the icon.
            Me.Height = ButtonIcon.Height + 4
            Me.Width = ButtonIcon.Width + 4
        End Set
    End Property

    <SecurityPermission(SecurityAction.Demand, UnmanagedCode := True)> _
    Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
        MyBase.OnHandleCreated(e)

        ' Update the icon on the button if there is currently an icon assigned to the icon field.
        If Me.ButtonIcon IsNot Nothing Then
            UpdateIcon()
        End If
    End Sub

    Private Sub UpdateIcon()
        Dim IconHandle As IntPtr = IntPtr.Zero

        ' Get the icon's handle.
        If Me.Icon IsNot Nothing Then
            IconHandle = Icon.Handle
        End If

        ' Send Windows the message to update the button. 
        ' BM_SETIMAGE (second parameter) and IMAGE_ICON (third parameter).
        SendMessage(Handle, &HF7, &H1, IconHandle.ToInt32())
    End Sub

    ' Declare the SendMessage function.
    Declare Auto Function SendMessage Lib "user32" (ByVal hWnd As IntPtr, _
            ByVal msg As Integer, ByVal wParam As Integer, ByVal lParam As Integer) As IntPtr
End Class

다음 코드 예제에서는 표준의 인스턴스를 만듭니다 Button 컨트롤과 파생된 컨트롤의 인스턴스 MyIconButton위의 예제에서 생성 합니다. 이 예제에서는 있다는 것을 Icon Default.ico 애플리케이션과 동일한 위치에 라는 파일. 애플리케이션이 시작 되 면, Default 아이콘에 표시 되는 MyIconButton 단추입니다. 경우는 Default 아이콘이 있는 단추 표면의 비어 있습니다. 때 표준 Button 를 클릭 하면는 OpenFileDialog 상자에 표시할 새 아이콘을 선택할 수 있도록 나타납니다는 MyIconButton합니다.

public ref class MyApplication: public Form
{
private:
   MyIconButton^ myIconButton;
   Button^ stdButton;
   OpenFileDialog^ openDlg;

public:
   MyApplication()
   {
      try
      {
         
         // Create the button with the default icon.
         myIconButton = gcnew MyIconButton( gcnew System::Drawing::Icon( String::Concat( Application::StartupPath, "\\Default.ico" ) ) );
      }
      catch ( Exception^ ex ) 
      {
         
         // If the default icon does not exist, create the button without an icon.
         myIconButton = gcnew MyIconButton;
         #if defined(DEBUG)
         Debug::WriteLine( ex );
         #endif
      }
      finally
      {
         stdButton = gcnew Button;
         
         // Add the Click event handlers.
         myIconButton->Click += gcnew EventHandler( this, &MyApplication::myIconButton_Click );
         stdButton->Click += gcnew EventHandler( this, &MyApplication::stdButton_Click );
         
         // Set the location, text and width of the standard button.
         stdButton->Location = Point(myIconButton->Location.X,myIconButton->Location.Y + myIconButton->Height + 20);
         stdButton->Text = "Change Icon";
         stdButton->Width = 100;
         
         // Add the buttons to the Form.
         this->Controls->Add( stdButton );
         this->Controls->Add( myIconButton );
      }

   }


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

   void stdButton_Click( Object^ /*Sender*/, EventArgs^ /*e*/ )
   {
      
      // Use an OpenFileDialog to allow the user to assign a new image to the derived button.
      openDlg = gcnew OpenFileDialog;
      openDlg->InitialDirectory = Application::StartupPath;
      openDlg->Filter = "Icon files (*.ico)|*.ico";
      openDlg->Multiselect = false;
      openDlg->ShowDialog();
      if (  !openDlg->FileName->Equals( "" ) )
      {
         myIconButton->Icon = gcnew System::Drawing::Icon( openDlg->FileName );
      }
   }

};

int main()
{
   Application::Run( gcnew MyApplication );
}
public class MyApplication : Form
{
    private MyIconButton myIconButton;
    private Button stdButton;
    private OpenFileDialog openDlg;

    static void Main()
    {
        Application.Run(new MyApplication());
    }

    public MyApplication()
    {
        try
        {
            // Create the button with the default icon.
            myIconButton = new MyIconButton(new Icon(Application.StartupPath + "\\Default.ico"));
        }
        catch (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.Click += new EventHandler(this.myIconButton_Click);
            stdButton.Click += new EventHandler(this.stdButton_Click);

            // Set the location, text and width of the standard button.
            stdButton.Location = new Point(myIconButton.Location.X, myIconButton.Location.Y + myIconButton.Height + 20);
            stdButton.Text = "Change Icon";
            stdButton.Width = 100;

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

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

    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.InitialDirectory = Application.StartupPath;
        openDlg.Filter = "Icon files (*.ico)|*.ico";
        openDlg.Multiselect = false;
        openDlg.ShowDialog();

        if (openDlg.FileName != "")
        {
            myIconButton.Icon = new Icon(openDlg.FileName);
        }
    }
}
Public Class Form1
    Inherits System.Windows.Forms.Form

    Friend WithEvents MyStdButton As System.Windows.Forms.Button
    Friend WithEvents MyIconButton As MyIconButton
    Friend WithEvents OpenDlg As OpenFileDialog

    Public Sub New()
        MyBase.New()
        Try
            ' Create the button with the default icon.
            MyIconButton = New MyIconButton(New Icon(Application.StartupPath + "\Default.ico"))

        Catch ex As Exception
            ' If the default icon does not exist, create the button without an icon.
            MyIconButton = New MyIconButton()
            System.Diagnostics.Debug.WriteLine(ex.ToString())
        Finally
            MyStdButton = New Button()

            'Set the location, text and width of the standard button.
            MyStdButton.Location = New Point(MyIconButton.Location.X, _
                        MyIconButton.Location.Y + MyIconButton.Height + 20)
            MyStdButton.Text = "Change Icon"
            MyStdButton.Width = 100

            ' Add the buttons to the Form.
            Me.Controls.Add(MyStdButton)
            Me.Controls.Add(MyIconButton)
        End Try

    End Sub

    Public Shared Sub Main()
        Application.Run(New Form1())
    End Sub

    Private Sub MyStdButton_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles MyStdButton.Click
        ' Use an OpenFileDialog to allow the user to assign a new image to the derived button.
        OpenDlg = New OpenFileDialog()
        OpenDlg.InitialDirectory = Application.StartupPath
        OpenDlg.Filter = "Icon files (*.ico)|*.ico"
        OpenDlg.Multiselect = False
        OpenDlg.ShowDialog()

        If OpenDlg.FileName <> "" Then
            MyIconButton.Icon = New Icon(OpenDlg.FileName)
        End If
    End Sub

    Private Sub MyIconButton_Click(ByVal sender As System.Object, _
                ByVal e As System.EventArgs) Handles MyIconButton.Click
        ' Make sure MyIconButton works.
        MessageBox.Show("MyIconButton was clicked!")
    End Sub
End Class

설명

정보는 CreateParams 는 초기 상태와 컨트롤의 모양에 대 한 정보를 전달할 수 있습니다. 대부분의 Control 컨트롤 재정의 파생 합니다 CreateParams 적절 한 값을 전달 하거나에서 추가 정보를 포함 하는 속성을 CreateParams.

컨트롤 매개 변수를 만드는 방법에 대한 자세한 내용은 CreateWindow 매크로, CreateWindowEx 함수CREATESTRUCT 구조를 참조하세요.

참고

상수를 설정 하는 데 사용 합니다 Style, ExStyle, 및 ClassStyle Winuser.h 헤더 파일에 정의 된 속성입니다. 이 파일은 Platform SDK 또는 Visual Studio에서 설치 합니다.

생성자

CreateParams()

CreateParams 클래스의 새 인스턴스를 초기화합니다.

속성

Caption

컨트롤의 처음 텍스트를 가져오거나 설정합니다.

ClassName

컨트롤이 파생된 Windows 클래스의 이름을 가져오거나 설정합니다.

ClassStyle

클래스 스타일 값의 비트 조합을 가져오거나 설정합니다.

ExStyle

확장 창 스타일 값의 비트 조합을 가져오거나 설정합니다.

Height

컨트롤의 처음 높이를 가져오거나 설정합니다.

Param

컨트롤을 만드는 데 필요한 추가 매개 변수 정보를 가져오거나 설정합니다.

Parent

컨트롤의 부모를 가져오거나 설정합니다.

Style

창 스타일 값의 비트 조합을 가져오거나 설정합니다.

Width

컨트롤의 처음 너비를 가져오거나 설정합니다.

X

컨트롤의 처음 왼쪽 위치를 가져오거나 설정합니다.

Y

컨트롤의 처음 위쪽 위치를 가져오거나 설정합니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

적용 대상

추가 정보