CreateParams.Style Özellik

Tanım

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

C#
public int Style { get; set; }

Özellik Değeri

Int32

Pencere stili değerlerinin bit düzeyinde birleşimi.

Ö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çıklamalar

özelliği, Style denetimin görünümünü ve ilk durumunu denetler.

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.

Ş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.