C builder update controls




















The most regular action the user performs on a button is to click it. Therefore, the default event on a button is the OnClick. To initiate the OnClick event on a button, double-click it. One of the most regular actions you will assign to a button is to close its parent form when the user clicks the button. There are different reasons you would want to close a form.

If the form that hosts the button displays an intermediary message to the user, you should provide all the necessary code to follow up after the user has clicked the button; this is the case of property sheets or wizard pages, among others. When studying message boxes, we will review other situations of dismissing a dialog box by clicking a button.

There are various ways you can close a dialog box from a button. The simplest way is to call the TCustomForm::Close method; this dismisses the form. This function takes one argument which is an integer. The Button cannot boast a lot of methods to customize its behavior. This is because a button does not need more than what you would expect from it: point and click.

Probably the only method you would use from a button is the constructor used to dynamically create a button. Most of the other methods used on a button are derived from member variables of the TButton class.

A dynamic button is one you create at runtime. This happens when you could not or would not create a button at design time. To create a dynamic button, use the TButton constructor. Declare a pointer to a TButton object and use the new operator to assign the constructor. There are two important pieces of information you need to provide. The instance of the object and the container of the control. If you decide to create a button locally, in a function or an event, declare an instance of the control and specify its parent.

The problem with a locally created object is that it is available only in the function or event in which it is created. You cannot access it outside the function or event. The alternative is to create the object globally in the header file of its host. Once you have the object initialized, to display it, set its parent and the desired properties:.

A bitmap button is a command button that displays a bitmap and possibly a caption on top. A bitmap button is based on the TBitBtn class. The two primary pieces of information you should provide to a bitmap button is the bitmap it displays and its caption. To use one of these, after adding a BitBtn control to the form, on the Object Inspector, click Kind and select one of the types of buttons. The buttons you create using one of the Kind types have already been configured to properly respond to the dialog box or form on which they are used.

This works only if the form or dialog box is added to an existing form. If one of the Kind combinations is not satisfying to you, you can use a bitmap and a caption of your choice.

The bitmap is specified using the Glyph property of the Object Inspector. The SpeedButton control provides the ability to create command buttons that behave either like check boxes or radio buttons.

Like check boxes, you can create a group of speed buttons so that, out of the group, the selected one would display and keep a clicked state. To implement a radio button effect, you can create speed buttons in a group so that only one in the group would display a clicked state when chosen.

A border is a line that sets the visual limits of an object. Most objects, including a form, have four borders: left, top, right, and bottom.

This is also the main property that specifies whether you are creating a regular form or a dialog box. To control the appearance of the borders of your form, on the Object Inspector, if you click BorderStyle , you would see that it is a combo box property. The BorderStyle property is an enumerator and you can choose one of its values needed for your form.

By default, a form is designed to be resizable using the bsSizeable value. In this case the user can change its width and its height by dragging one of its borders or corners. If you set the BorderStyle property to bsDialog , the user will not be able to resize the dialog. This is the default and the mostly used characteristics for a dialog window. You should always use it if you want the window to be a dialog box. If you set the BorderStyle property to bsDialog and have a Help file you want to use on the dialog box, you can set the biHelp of the BorderIcons property to true.

This would display a Whats This button on the title bar. A BorderStyle set with bsSingle looks like one set with the bsSizeable. The difference is that the user cannot resize it. A floating window is a form used to let the user move it around while she is working on the main form or dialog. This form is usually modeless, which means the user does not have to close it to continue working. The window has a short title bar and it can be resized.

Like the sizable tool window, a form with bsToolWindow has a short title bar and is also a prime candidate for a floating window. A Form whose BorderStyle is set to bsNone has neither a title bar nor borders. To change a property programmatically, assign one of the above values to the BorderStyle variable. This ability is controlled by the WindowState property. The default value of this property is wsNormal , which means the form would appear in a normal fashion.

If you want the form to be minimized or maximized at startup, in the Object Inspector, select the desired value for the WindowState property. As the main container of Windows controls, a form provides some particular properties to the controls it hosts. The client area of a form is represented by the ClientRect property. This property can be used to get the dimensions of the body of the form. Like the TControl::ClientRect property, the TForm::ClientRect property provides the width and the eight of the client area, omitting the location left and top which is set to the client origin 0, 0 located on the top-left corner of the body of the form.

Alternatively, to get the width of the client area of the form, you can call the ClientWidth property. To get the height of the client area, use the ClientHeight. The client aspects can be illustrated as follows:. Overall, you will hardly be concerned with the dimensions of the client area, unless you want to draw or render an image.

If you are working under Windows or later running on a Pentium or equivalent, you can make your form transparent. To create a transparent form, set the AlphaBlend Boolean property to true from its default false value.

Once this property is set to true, you can use the AlphaBlendValue property to set the degree of transparency. The value must be a BYTE integer between 0 and At 0, you would not see the form at all. The only presence of the form would be on the taskbar. At , the form would appear as if the property were not applied. Like every other control, the form is equipped with a constructor that allows you to dynamically create it.

Form Closure When the user has finished using a form, he or she must be able to close it. Closing a form is made possible by a simple call to the Close method. Its syntax is:. Although this method can be used to close any form of an application, if it is called by the main form, it also closes the application. Forms Messages and Events Form Creation When an application made of a form is launched, the form must be created to display to the user.

At the form gets created, it initialize its controls. This is done before the form can display to the screen. At this time the OnCreate event fires. This is a TNotifyEvent event, which means that it does not take any argument other than the Sender, which is a TObject type.

OnCreate is the default event of a form. This means that if you double-click the form, the code of this event would be created and made ready for you. If the application contains more than one form, you can display it. VCL UI controls are simply not thread-safe and cannot be accessed from outside the context of the main thread.

A worker thread must delegate to the main thread to access the UI safely. Either use the static TThread::Synchronize method, or use AllocateHWnd to create a helper window that you can send custom messages to using SendMessage.

RemyLebeau - Thx for the correction, I was not aware of this limitation — Attila. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name.

Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Related 0. Hot Network Questions. Question feed. Stack Overflow works best with JavaScript enabled.



0コメント

  • 1000 / 1000