CreateParams.Style プロパティ
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

ウィンドウ スタイル値のビットごとの組み合わせ。

Style プロパティは、コントロールの外観とその初期状態を制御します。
コントロール パラメータの作成の詳細については、MSDN ライブラリにあるプラットフォーム SDK ドキュメントの CreateWindow 関数、CreateWindowEx 関数、CREATESTRUCT 構造体の各トピックを参照してください。
![]() |
---|
Style プロパティ、ExStyle プロパティ、および ClassStyle プロパティを設定するときに使用する定数は、Winuser.h ヘッダー ファイルの中に定義されています。このファイルは、プラットフォーム SDK または Visual Studio .NET によってインストールされます。 |

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

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


Weblioに収録されているすべての辞書からCreateParams.Style プロパティを検索する場合は、下記のリンクをクリックしてください。

- CreateParams.Style プロパティのページへのリンク