Changing the color of MainMenu - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Changing the color of MainMenu

AsAdiAsAdi Posts: 117Member
I would likt to change the color of MainMenu control in a MDI form using Windows API,so I derived a FMainMenu class from MainMenu and added one method named SetMenuBkColor.Here is my code

public class FMainMenu : System.Windows.Forms.MainMenu
{
[DllImport("GDI32.DLL")]
private static extern long SetBkColor(int hdc,long color);
[DllImport("USER32.DLL")]
private static extern int GetDC(int hwnd);

public void SetMenuBkColor(long ColorRef)
{
try
{
int hdc=GetDC((int)(this.CreateMenuHandle()));
SetBkColor(hdc,ColorRef);
}
catch(System.Exception e)
{
MessageBox.Show(e.Message); }
}
}
And I call this method later in my form load event like this:
myMenu.SetMenuBkColor(0xffffff);
to make the menu color white.But it doesn't work properly and the color doesn't change.I know there is a problem with calling API,maybe casting isn't correct or something else.

Any one can tell me what happens with this code and what's wrong with it?

Thanks alot
Reza
Sign In or Register to comment.