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.

관련자료

등록된 댓글이 없습니다.
프로그래밍
Today's proverb
누구나 잘못할 수는 있지만 누구나 솔직할 수 있는 것은 아닙니다. 그러나 진실한 사람의 아름다움은 무엇과도 바꿀 수 없습니다. 솔직함은 겸손이고 두려움 없는 용기입니다. 잘못으로 부서진 것을 솔직함으로 건설한다면 어떤 폭풍에도 견뎌낼 수 있는 강인함이 있습니다. 가장 연약한 사람이 솔직할 수 있으며 가장 여유로운 사람이 자신의 모습을 볼 수 있고 자신을 아는 사람만이 자신을 드러낼 수 있습니다.