2011-08-16 5 views
2

winformアプリケーションでは、「タイトルバー」にイメージとタイトルテキストを追加し、すべてのコントロールbuttionsを削除します(最小、最大&終了)。画像とタイトルのテキストを表示できましたが、[閉じる]ボタンを含むすべてのボタンを削除できませんでした。これらの回避策はありますか?Winform、画像とテキストはありますがコントロールボタンはないカスタムタイトルバー?

答えて

0

FormDesignerでFormBorderStyleをNoneに設定すると役立ちます。

0

残念ながら、PInvokeを使用してWindows API関数を呼び出す必要があります。

// Changes an attribute of the specified window.   
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] 
    public static extern int SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong); 
    // Retrieves information about the specified window.   
    [DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = false)] 
    public static extern int GetWindowLong(IntPtr hWnd, int nIndex); 
    public const int GWL_STYLE = (-16); 
    public const int WS_SYSMENU = 0x00080000; 
    public const int WS_MAXIMIZEBOX = 0x00010000; 


    public static void SetDialogStyle(Form window) 
    { 
     // We disable the control box functionality for the window 
     // i.e. remove the minimize, maximize and close button as 
     // well as the system menu. 

     int style = GetWindowLong(window.Handle, GWL_STYLE); 
     style &= ~(WS_SYSMENU | WS_MAXIMIZEBOX); 
     SetWindowLong(window.Handle, GWL_STYLE, style); 
    } 

あなたは、関数の引数としてこのを渡すOnLoadイベントで、この関数を呼び出すことができます。

+0


ControlBox=falseを設定することをお勧め? – Dhana

+0

答えを更新しました – Arseny

+0

WindowInteropHelper ??見つかりませんでしたか? – Dhana

1

フォームのControlBoxプロパティをFalseに設定すると、すべてのボタン(最小、最大、閉じるボタン)が簡単に削除され、タイトルとイメージを設定することもできます。FormBorderStyleを使用すると、タイトルバーを削除しても問題は解決しません。

だから私はあなたが私はfrom1.csでこのmenthodを呼んでくださいフォーム

関連する問題