Главная страница | назад

Article #17773: Writing to StatusBar Panels.

 Question and Answer Database

FAQ2773C.txt   Writing to StatusBar Panels.
Category   :VCL
Platform    :Win95/NT
Product    :   C++Builder1.0   C++Builder3.x

How do I write to a panel on a status Bar?

You need to access the text feild in the Items array like this: 
StatusBar1->Panels->Items[0]->Text = "Hello";

Here is quick example showing how.
1. Drop a TStatusBar (From the Win32 component Palette) onto a form.  Bring up the Panels 
   Editor by double clicking on the StatusBar. 

2. Click on the Add button twice to give you two panels on the StatusBar. (You can 
   change the properties of the individual panels in the panels editor by highlighting the 
   panel in the editor and using the object inspector: For example the width property) 
   Close the Panels Editor.

3. Got to the Object Inspector, select the TForm component (Form1), go to the Events Tab,
   and double-click in the OnKeyUp. Insert the following code.

    if (GetKeyState(VK_CAPITAL))
        StatusBar1->Panels->Items[0]->Text = "CapsLock";   // Caps lock on
        StatusBar1->Panels->Items[0]->Text = "";           // CapsLock off

    if (GetKeyState(VK_INSERT))                            // Insert on
        StatusBar1->Panels->Items[1]->Text = "Insert";
        StatusBar1->Panels->Items[1]->Text = "Overwrite";  // Insert off
   You may want to add the code to the constructor or OnCreate of your form to indicate the
correct state of the controls when the application starts up. Any other control that can get
focus should also call this event handler in thier OnKeyUp.

Now when you activate Caps Lock, the first panel will read "CapsLock".  And when 
it is toggled off, the panel will be blank.  The second panel will read either "Insert" or 
"Overwrite" depending if the key is toggled on or off.

Note: The GetKeyState function returns the state of the key (Toggled on/off).  For 
more information, see the online Win32 reference help.

7/15/98 12:06:34 PM

Last Modified: 01-SEP-99