Visual Basic, C & C++
C & C++ 분류

Using C++Builder to list all available VCL styles in a ComboBox and apply a selected style using the ComboBoxChange event

컨텐츠 정보

본문

The C++ Application User Interface

For the application user interface I have a TButton (has code to populate the ComboBox with selected application styles) and a TComboBox (to display and allow selection of a style).


 C++ code
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include <Vcl.Themes.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"

TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
    : TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
    // populate the ComboBox with VCL styles that are selected
    //    in Project | Options | Application | Appearance
    ComboBox1->Items->BeginUpdate();
    try
    {
        ComboBox1->Items->Clear();
        DynamicArray<String> styleNames = Vcl::Themes::TStyleManager::StyleNames;

        for(int i = 0; i < styleNames.Length; ++i) 
       {
            String styleName = styleNames[i];
            ComboBox1->Items->Add(styleName);
        }
    }
    __finally
    {
        ComboBox1->Items->EndUpdate();
    }
}
//---------------------------------------------------------------------------
void __fastcall TForm1::ComboBox1Change(TObject *Sender)
{
    // set the style for the selected combobox item
    Vcl::Themes::TStyleManager::TrySetStyle(ComboBox1->Items->Strings[ComboBox1->ItemIndex],false);
}
//--------------------------------------------------------------------------- 

The Application in Action


TComboBox populated with VCL styles selected Application Style Changed by TComboBox selection 

References

VCL Styles Overview

Project Options Application Appearance

VCL Styles Support for High-DPI Graphics

C++Builder Product Information

C Builder Product Page – Native Apps that Perform. Build Windows C++ Apps 10x Faster with Less Code
C Builder Product Editions – C++Builder is available in four editions – Professional, Enterprise, Architect and Community (free). C++Builder is also available as part of the RAD Studio development suite.

관련자료

댓글 0
등록된 댓글이 없습니다.
Today's proverb
지금이 바로 새 출발점. 인생이란 하루하루가 훈련이다. 우리 자신을 훈련하는 터전이다. 실패도 할 수 있는 훈련장이다. 살아있음이 흥겨운 훈련장이다. 지금 이 행복을 기뻐하지 않고 언제 어디서 행복해지랴. 이 기쁨을 발판삼아 온 힘으로 나아가자. 나의 미래는 지금 이 순간 이 곳에 있다. 지금 여기서 노력하지 않고, 언제 어디서 노력하랴. (오히라 미쓰요의 <그러니까 당신도 살아> 중에서)