Click here to Skip to main content
15,881,882 members
Articles / Programming Languages / C#
Tip/Trick

Windows CE custom controls

Rate me:
Please Sign up or sign in to vote.
5.00/5 (3 votes)
5 Nov 2012Public Domain1 min read 17.2K   23   7   2
Messagebox, mainmenu and contextmenu controls for Windows CE

Introduction

I have developed a program (c#, .netcf) for some PNA devices shipped with Windows CE 6.0. The text on the mainmenu, contextmenu and messagebox controls were unreadable due to their font size. There is no way to change these control's font and some other major properties. So I decided to write my own classes to get full control over these controls. If you have the same problem feel free to use and/or modify the shared code.

Using the code

The usage of the controls are fairly straightforward. You can see some examples in the sample project.

Custom MessageBox class: Use it as the same way as .NET MessageBox. Custom messagebox has the same constructor with the same parameters as the normal messagebox. So you can use this in your exiting code without any change. The only thing you must to do is place the messagebox class to the same namespace with the code what which will use it. If you want to use it from more different namespaces, you will have to create a messagebox class for each namespaces and from their show() method you can call the custom messagbox class show() method, otherwise the codes exits in the other namespaces will use the system default messagebox class.

C++
MessageBox.Show("This is a custom messagebox","ATTENTION",MessageBoxButtons.AbortRetryIgnore,MessageBoxIcon.Asterisk,MessageBoxDefaultButton.Button1);

The newly created messagebox will looks like this:

Image 1

Context Menu class:
Simply create a new CustomContextMenu instance. You can attach the menu to any type of controls.

C++
CustomContextMenu contextMenu = new CustomContextMenu(this.dataGrid,new Font("Arial",13,FontStyle.Bold));

contextMenu.AddContextMenu("Context menu 1",menu_Click);

contextMenu.AddContextMenu("Context menu 2",menu_Click);

Image 2

Main Menu class:
Simply create a new CustomMainMenu instance. Add eventhandlers to the menu which has no submenu. Do not forget to create a main menu before you add a submenu to it. (see below)

C#
CustomMainMenu mainMenu = new CustomMainMenu(this,new Font("Arial",13,FontStyle.Bold));

mainMenu.AddMainMenu("MainMenu1","",menu_Click);

mainMenu.AddMainMenu("MainMenu2","",menu_Click);

mainMenu.AddMainMenu("MainMenu3","",null);

mainMenu.AddMainMenu("SubMainMenu1","MainMenu3",menu_Click);

mainMenu.AddMainMenu("SubMainMenu2","MainMenu3",menu_Click);

Image 3

Happy coding!

Points of Interest

C#, MSSQL, Mobile devices

History

...

License

This article, along with any associated source code and files, is licensed under A Public Domain dedication


Written By
Software Developer
Hungary Hungary
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionNo attachments Pin
Member 141748247-Mar-19 10:52
Member 141748247-Mar-19 10:52 
Questionattachments Pin
Trivalik14-Jun-18 2:31
Trivalik14-Jun-18 2:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.