C++C++11C++14C++17ComponentsIntroduction to C++Language FeatureLearn C++

How To Change The Background Color Of A Memo In An FMX C++ App

How To Change The Background Color Of A Memo In An FMX C++ App

C++ Builder is the easiest and fastest C++ IDE for building professional applications with powerful GUI components like Memo, Edit, ListBox, StringGrid and many more. Each component can be skinned with Styles to change their visual appearance. Styles are very powerful and because of this it can sometimes take a little to get used to how they work. In this post, we explain how to change background color of a Memo (TMemo), one of the most frequently asked questions about using styles. These methods below, can be applied to other components too.

How to change the background color of a Memo in C++ Builder by using Styles?

Styles are sets of graphical details that define the look and feel of an application. They are one of most beautiful and useful UI features of RAD Studio that can really add some extra professionalism to your apps. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps (not wrapped in some kind of runtime interpretation layer) and the powerful FireMonkey (FMX) framework for cross-platform UIs. Both VCL and FMX apps support Styles.

There are many Styles in C++ Builder, RAD Studio. More details about Styles can be found here. You can also find Premium Styles here. If you want to learn how you can modernize your components with styles this post has some great details;

What are the steps to change the background color of a Memo in C++ Builder by using Styles?

1. Right-click on the Memo and select 'Edit Custom Style...'

How To Change The Background Color Of A Memo In An FMX C++ App Selecting custom style

2. Expand Memo1Style: you’ll see the background node. Click on background to select it. Then add a TRectangle via the Palette. The IDE should expand the background node and show a new Rectangle1Style tied to the TRectangle,

How To Change The Background Color Of A Memo In An FMX C++ App choosing the Rectangle1Style

3. Via the Object Inspector change the Color of TRectangle as below

How To Change The Background Color Of A Memo In An FMX C++ App Changing the colors in the object inspector

4. Click on the Apply Style button in the 'Style Designer', Save All.

How To Change The Background Color Of A Memo In An FMX C++ App the style designer

5. Compile and run your application

If you still have problems setting the color, this DocWiki article can help you: https://blogs.embarcadero.com/edit-custom-style-to-change-the-background-color-of-a-fmx-tedit/

How to change the background color of a Memo in C++ Builder code?

If you want to change the background color of a Memo component (TMemo) in C++ Builder, first you should set the StyleLookup to “Memostyle” as shown below:

If you look at the Custom Style of Memo,

How To Change The Background Color Of A Memo In An FMX C++ App Editing the Memostyle background color

There is a “background” property, so we should find this resource by using FindStyleResource() method of Memo as given in the example below:

If this resource object we can create a rectangle (TRectangle) as a background:

Here we used unique_ptr which more modern to create this rectangle. Now we can set properties of our Rectangle, including its color.

Now, at last we need to add this object by using the .get() method of unique_ptr. And the final trick here is you must release this unique_ptr by using .release() otherwise it doesn’t have any effect.

Is there a full example of how to change the background color of a Memo in C++ Builder code?

Here is a full C++ Builder FMX example that changes the color of 3 TMemo components that has Memo1, Memo2, Memo3 names. To do this we create a ChangeMemoColor() function that uses the Memo name and your color. Don’t forget to drag them into your application form, before you run this code.

How To Change The Background Color Of A Memo In An FMX C++ App C++ Builder logo

C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.

There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise version.

Oh hi there 👋
It’s nice to meet you.

Sign up to receive awesome C++ content in your inbox, every day.

We don’t spam! Read our privacy policy for more info.


Reduce development time and get to market faster with RAD Studio, Delphi, or C++Builder.
Design. Code. Compile. Deploy.
Start Free Trial

Free C++Builder Community Edition

About author

Dr. Yilmaz Yoru has 35+ years of coding with more than 30+ programming languages, mostly C++ on Windows, Android, Mac-OS, iOS, Linux, and some other operating systems. He graduated and received his MSc and PhD degrees from the Department of Mechanical Engineering of Eskisehir Osmangazi University. He is the founder and CEO of ESENJA LLC Company. His interests are Programming, Thermodynamics, Fluid Mechanics, Artificial Intelligence, 2D & 3D Designs, and high-end innovations.
Related posts
Artificial Intelligence TechC++C++11C++14C++17Language FeatureLearn C++

Learn How To Read The WAV Waveform Audio File Format In C++

C++C++11Learn C++

What Is Assignment Operator Overloading?

C++C++11Introduction to C++Learn C++Syntax

Full List Of Features In C++ 11

C++C++11C++14C++17C++20Introduction to C++Learn C++Syntax

How To Use Basic Methods Of Strings In C++?