C++Language FeatureLearn C++

What You Need To Know About Form Methods in C++ Applications

Do you want to know about the available form methods you can use in C++ applications? How can we use mouse events on Forms? How can we get key presses made by users on our Forms? Let’s learn all about Methods of Forms on VCL Applications in C++ Builder.

C++ Builder is the easiest and fastest C and C++ IDE for building everything from simple to full-on 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. C++ Builder comes with Rapid Application Development Studio, also known as RAD Studio, and C++ Builder is one of the most professional IDE’s that work under RAD Studio. It is the oldest IDE (it began as Borland TurboC in 1990 and was later renamed Borland C++ Builder). Under the Embarcadero brand it comes with new versions, features, updates and support. 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.

This image has an empty alt attribute; its file name is CBUIDER_STUDIO_FINAL_ICONS_64.png

You can download the free C++ Builder Community Edition here: https://www.embarcadero.com/products/cbuilder/starter.
Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. Please visit https://www.embarcadero.com/products/cbuilder.

What are the basics of Forms (TForm) in the VCL Framework?

TForm represents a standard application window form. When we create forms in the Form designer at design time, they are implemented as descendants of TForm. Forms can represent the application’s main window, or dialog boxes, or various preferences-related windows. A form can contain any other visual objects, such as TButtonTCheckBoxTComboBox objects, and so on. All the Properties of Forms in the VCL framework can be found here and Methods of Forms can be found here in official DocWiki.

We can use Hide() and Show() methods to hide and show our forms.

We can use SendToBack() and BringToFront() methods, to send our form to the back or to bring to front.

We can use Deactivate() or Activate() methods to activate or deactivate event dispatcher.

We can use Close() or CloseModal() to close forms and we can also delete all form properties with Free() method.

How do I use Events of Forms (TForm) in VCL?

One of the great feature of FireMonkey framework is events of components, these are methods that can be created by double clicking on the events of Object Inspector. Forms also has a lot of events.
To create and do something in a event of Form;

  1. Select Form
  2. Go to Object Inspector and Press Events Tab
  3. Double Click to value of event that you want to use, this will create this event in header file and method will be added in your cpp file automatically.
  4. Now you can add whatever you want to in that event

Here below screenshot example, we double click most of events of form and we added some codes in their procedures (methods).

What You Need To Know About Form Methods in C++ Applications Example of using events in VCL

Using Mouse Events of Forms (TForm) in VCL

How we can get mouse clicks, and coordinates? Here is the answer, We can use FormMouseDown(), FormMouseMove(), FormMouseUp() events to detect mouse button clicks with X and Y coordinates, and mouse wheel delta as below;

Using Keyboard Events of Forms (TForm) in VCL

How we can get key press on Forms ? The answer is, we can use FormKeyDown(), FormKeyUp() events as given example below,

Using Other Events of Forms (TForm) in VCL

Here is a full VCL example that has most of events tested. To create these events, just double click to form events and modify each inside as below,

These methods show how C++ Builder is capable to handle all of events of form windows. These methods may improve your applications, allows users to have better and faster user experience.

There are many methods and properties that we can use. All the Properties of VCL Forms can be found here and Methods of VCL Forms can be found here in official DocWiki.

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
C++C++11C++14C++17C++20Introduction to C++Learn C++

Learn Copy Constructors in C++ Classes

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

Learn How To Use Types Of Destructors In C++?

C++C++11C++14Learn C++Syntax

How To Convert u32string To A wstring In C++

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

How To Learn The Move Constructors In Modern C++?