İngilizce dilinde oku

Aracılığıyla paylaş


CreateParams Sınıf

Tanım

Denetim oluştururken gereken bilgileri kapsüller.

C#
public class CreateParams
Devralma
CreateParams

Örnekler

Aşağıdaki kod örneği adlı MyIconButton türetilmiş bir Button sınıf oluşturur ve düğmenin Görüntü yerine Simge görüntülemesi için gereken uygulamayı sağlar. CreateParams özelliği genişletilir ve özelliğineStyle, düğmenin yerine bir Icon görüntülemesine neden olan bir Imagedeğer eklenir.

C#
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);
}

Aşağıdaki kod örneği, standart Button denetimin bir örneğini ve yukarıdaki örnekte oluşturulan türetilmiş denetimin MyIconButtonbir örneğini oluşturur. Bu örnek, uygulamayla aynı konumda Default.ico adlı bir Icon dosya olmasını gerektirir. Uygulama başlatıldığında, Default düğme üzerinde MyIconButton simge görüntülenir. Default Simge yoksa düğmenin yüzü boş olur. Standart Button tıklandığında, üzerinde MyIconButtongörüntülemek üzere yeni bir Simge seçebilmeniz için bir OpenFileDialog kutu görüntülenir.

C#
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);
        }
    }
}

Açıklamalar

içindeki CreateParams bilgiler, bir denetimin ilk durumu ve görünümü hakkında bilgi geçirmek için kullanılabilir. Türetilmiş denetimlerin CreateParams çoğuControl, uygun değerleri geçirmek veya içinde ek bilgiler CreateParamseklemek için özelliğini geçersiz kılar.

Denetim parametreleri oluşturma hakkında daha fazla bilgi için bkz. CreateWindow makro, CreateWindowEx işlevi ve CREATESTRUCT yapısı.

Not

, ExStyleve ClassStyle özelliklerini ayarlamak Styleiçin kullanılan sabitler Winuser.h üst bilgi dosyasında tanımlanır. Bu dosya Platform SDK'sı veya Visual Studio tarafından yüklenir.

Oluşturucular

CreateParams()

CreateParams sınıfının yeni bir örneğini başlatır.

Özellikler

Caption

Denetimin ilk metnini alır veya ayarlar.

ClassName

Denetimi türetmek için Windows sınıfının adını alır veya ayarlar.

ClassStyle

Sınıf stili değerlerinin bit düzeyinde bir bileşimini alır veya ayarlar.

ExStyle

Genişletilmiş pencere stili değerlerinin bit düzeyinde bir bileşimini alır veya ayarlar.

Height

Denetimin ilk yüksekliğini alır veya ayarlar.

Param

Denetimi oluşturmak için gereken ek parametre bilgilerini alır veya ayarlar.

Parent

Denetimin üst öğesini alır veya ayarlar.

Style

Pencere stili değerlerinin bit düzeyinde bir bileşimini alır veya ayarlar.

Width

Denetimin ilk genişliğini alır veya ayarlar.

X

Denetimin ilk sol konumunu alır veya ayarlar.

Y

Denetimin ilk konumunun üst konumunu alır veya ayarlar.

Yöntemler

Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

Şunlara uygulanır

Ürün Sürümler
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8
Windows Desktop 3.0, 3.1, 5, 6, 7

Ayrıca bkz.