2

I have a frame, with color clSkyBlue, which sits in an application with panels and various things with the color clSkyBlue. The program uses TStyleManager this sets the color to the current style. (ie windows10,windows10 dark etc). The problem is that everything has the correct color set from the stylemanager except for the frame which remains clSkyBlue.

How do I force the frame to follow the current style selected?

//in the main form code
void __fastcall TMainFormUnit::FormCreate(TObject *Sender)
{
...
  for (int i = 0; i < TStyleManager::StyleNames.Length; i++)
    cbxVclStyles->Items->Add(TStyleManager::StyleNames[i]);
    TStyleManager::TrySetStyle(TStyleManager::StyleNames[1]);
...
}

//---------------------------------------------------------------------------
void __fastcall TMainFormUnit::cbxVclStylesChange(TObject *Sender)
{
  TStyleManager::SetStyle(cbxVclStyles->Text);
}
iplayfast
  • 140
  • 10

1 Answers1

2

If you need your TFrame to change appearance as the parent component changes, set its properties accordingly:

ParentBackground = True
ParentColor = True

This will also set its Color back to clBtnFace.

I also recommend not using the FormCreate event in C++. Use the constructor:

__fastcall TMainFormUnit::TMainFormUnit(TComponent* Owner)
    : TForm(Owner)
{
    cbxVclStyles->Items->AddStrings(TStyleManager::StyleNames);
}
//---------------------------------------------------------------------------
void __fastcall TMainFormUnit::cbxVclStylesChange(TObject *Sender)
{
    TStyleManager::TrySetStyle(static_cast<TComboBox*>(Sender)->Text);
}
Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • Thanks that got the color problem fixed. Is there a reason to use constructor over form create. I had thought that form create is called from the constructor. – iplayfast Oct 26 '21 at 17:55
  • @iplayfast Great, you're welcome! There is a note regarding `OnCreate` in the doc: "_Use of the OnCreate event is discouraged in C++ code because it can interact badly with the form's constructor (see OldCreateOrder). It is recommended that you override the form constructor instead._" – Ted Lyngmo Oct 26 '21 at 18:06
  • So the color problem is solved, however there are artifacts being left over from other forms. I assumed it was due to double buffering picking up wrong form, but I can' seem to make it consistently right. (Same frame code, only with constructor instead of form create) – iplayfast Oct 26 '21 at 19:39
  • @iplayfast Have you replaced all `OnCreate` handlers with constructors in the whole project? If you don't get that to work perhaps you need to create a new question describing this issue in detail. I don't get any strange artifacts myself. – Ted Lyngmo Oct 26 '21 at 19:47
  • There was only the one OnCreate, so that's not it. The project is based off the TSplitter demo, and it appears that the split info is showing on cards. – iplayfast Oct 26 '21 at 20:10
  • @iplayfast I see. I don't have any demo's myself so I can't check it out. Perhaps you can reproduce the problem in a smaller version where you create the app cleanly from scratch and make notes about the components you use and any properties you change in order for this to happen? – Ted Lyngmo Oct 26 '21 at 20:20
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/238578/discussion-between-iplayfast-and-ted-lyngmo). – iplayfast Oct 26 '21 at 21:49