index > Visual C# General > Change the BackGround Color of a Window or Control.

Change the BackGround Color of a Window or Control.

Is there a way with the API functions to change the background color of a Window (or control) having only its Handle?

Not only the background color behind the text, rather all the window or control, and without changing the original content.

Something as:

System.Windows.Forms.Control ctrl;

ctrl.BackColor = Color.Red;

But, With API Functions.

Thanks, Deza

Deza

im not sure but wondering why you would rather use a "handle" or even some API to do this when you can do this, as you have shown, using the .NET Way? if there already exists a .NET way, you should really be using it :-)




Need 2 be back @ MS - MS All the way! Follower since 1995 MS Super Evangelist| MSDN Forums Moderator
ahmedilyas

There is no API that works for all types of windows.

The standard Windows Controls (Edit, List Box etc..) send WM_CTRLCOLOR notification messages to it's parent. By handling these type of messages, you can specify how the control gets drawn.




Michael Koster [MVP Windows Embedded] -- Mark the best replies as answers!
Michael Koster

Because it is not my Application. I just have the Handle of the Window (Form) and the handle of a Control. I tried with

System.Windows.Form.Control ctrl;

ctrl.FromHandle(handle);

but It did not work.

Deza
reply 4

You can use google to search for other answers

 

More Articles

• IClonable deep vs shallow, best practise
• linkedConfiguration information not shown in ConfigurationManager
• Disabling network adapter from C#
• Find the right library at runtime
• Hexadecimal Question
• Retreive the Song information while playing the song?
• How to know the Language of the System(Windows)?
• Windows Service :: Why does my OnStart() code cause Service to sh...
• Culture ID 2155 (0x086B) is not a supported culture
• Sql Distinct
Bookmark and Share
Welcome to Bokebb   New Update  
 

New Articles

• Finding Correct IP Address of Client PC
• Preview mail before sending/ spell checker
• Clearing contents of multi line textbox
• ASP DataGrid event handling
• Creating Sites and Virtual Directories,
• Logging In a page
• Enable a button
• what is the best way to create a back up
• Using a class name as a property type
• problem with application.
• How can I prevent others using my assemb
• Processing a RichTextBox
• How Can I extract information from XML f
• SerialPinChage.Break event
• Command Line Paramters in Windows Applic

Hot Articles

• CodePage customization
• Creating a Table Similar to that of MS-W
• How to build an editor like DataSourceLi
• Problem w/ Creating a new MembershipUser
• GetCurrentMethod / reflection
• TreeNode Tag problem
• Serialization
• How to set a form run when project inclu
• Hit Detection on a Line
• TreeListViewItem Check
• Launching custom forms from Property Grid!
• Why C# doesn't support multiple inherita
• Save Combobox items to file (not .txt)
• What does the "+" operator do
• Developing C# with Generics

Recommend Articles

• How is this code (VBA6.0 with Excel Appl
• How to force writing to label.text and t
• How to change Application pool Identity
• Raise event at a certain time?
• .NET Application
• Problem retrieving objects from Active d
• How do I tell when all threads in a pool
• Operator overloading for int[]
• Form
• screenscrape outside client area
• namespace for ConfigurationManager
• Picture Boxes and Arrays.
• How to change the name of a file?
• Datagridviews inC#.net
• How to generate a TIff file?