News | Articles | Libraries | Developer Tools | Books | Forum Links | Search   
Sections:
 

QA: How to hide the OK button in the dialog in .Net Compact Framework application?

By Andrey Lebedev, November 06, 2003.
Print version

Question

Some dialogs like wizards should contain neither OK nor X button. How can I the OK or X button in the dialog in .Net Compact Framework application?

Answer

A. We have to import three functions from aygshell coredll DLLs:

class WinAPI { ... [DllImport("aygshell.dll")] private static extern bool SHDoneButton( IntPtr hWnd, UInt32 dwState); [DllImport("coredll.dll")] public static extern UInt32 SetWindowLong( IntPtr hWnd, int nIndex, UInt32 dwNewLong); [DllImport("coredll.dll")] public static extern UInt32 GetWindowLong( IntPtr hWnd, int nIndex); ... }

B. Then we write 2 functions (HideDoneButton and HideXButton) and add several constants:

class WinAPI { ... public const UInt32 SHDB_SHOW = 0x0001; public const UInt32 SHDB_HIDE = 0x0002; public const int GWL_STYLE = -16; public const UInt32 WS_NONAVDONEBUTTON = 0x00010000; public static void HideDoneButton(IntPtr hWnd) { SHDoneButton(hWnd, SHDB_HIDE); } public static void HideXButton(IntPtr hWnd) { UInt32 dwStyle = GetWindowLong(hWnd, GWL_STYLE); if ((dwStyle & WS_NONAVDONEBUTTON) == 0) SetWindowLong(hWnd, GWL_STYLE, dwStyle | WS_NONAVDONEBUTTON); } ... }

C. To hide the done (OK) button in the dialog you should add Paint event handler to the dialog and call HideDoneButton and HideXButton functions from there:

public class MyForm : System.Windows.Forms.Form { private void MyForm_Paint(object sender, System.Windows.Forms.PaintEventArgs e) { WinAPI.HideDoneButton(); WinAPI.HideXButton(); } }

If the Paint handler is not called then you should call there functions yourself from somewhere between the dialog creation and its destruction - one of the ideas is to create a timer and to call the functions from its handler.

Done!

Related resources:

Discuss

Discuss this article. Here you can write your comments and read comments of other developers.
Rate this article:     Poor Excellent    
 12345 
© 2001-2005 Pocket PC Developer Network, a division of Spb Software House