Board index » cppbuilder » Disabled groupBox

Disabled groupBox

Hi,
I have a groupbox with some edit controls on.
In my code I want to disable/enable groupboxes. When disabling a groupbox, I
want the edit boxes (and buttons) to become grayed out. In code I have for
example

GroupBox->Enabled = false;

How do I make the editboxes placed on this groupbox to become greyed when
this occur?
Do I have to write code for each editbox?
/totte

 

Re:Disabled groupBox


By greyed out, do you mean to actually change the background color as
needed?  When you enable/disable the groupbox, it automatically
enables/disables its child controls for/from accepting user input already,
at least.

If you want to physically change the color of fields, with minimal code, you
can try doing something like this:

    void __fastcall TForm1::EnableDisableGroupBox(TGroupBox *GB, bool
bEnabled)
    {
        if(!GB) return;

        for(int x = 0; x < GB->ControlCount; x++)
        {
            TEdit *edit = dynamic_cast<TEdit*>(GB->Controls[x]);
            if(edit) edit->Color = (bEnabled) ? clWindow : GB->Color;
        }
        GB->Enabled = bEnabled;
    }

Then you can call it like this:

    EnableDisableGroupBox(GroupBox1, false);
    EnableDisableGroupBox(GroupBox2, true);

Gambit

Quote
"Totte Karlsson" <m...@u.washington.edu> wrote in message

news:3d28b24e$1_2@dnews...
Quote
> In my code I want to disable/enable groupboxes. When disabling
> a groupbox, I want the edit boxes (and buttons) to become grayed
> out. In code I have for example

> GroupBox->Enabled = false;

> How do I make the editboxes placed on this groupbox to
> become greyed when this occur?
> Do I have to write code for each editbox?

Re:Disabled groupBox


Hi,
Well, I only wanted the child controls to get its greyed color as when they
are disabled when the parent groupBox gets disabled.. but I guess I can use
your code
and write
             if(edit) edit->Enabled =  (bEnabled);
in the loop instead.

However, I also wants buttons to be disabled (look greyed) when the groupbox
become disabled..
maybe I can loop trough and cast controls to TControl and then set the
enabled property?
Is that the way to do it?
I'll try that

Thanks,

"Remy Lebeau [TeamB]" <gambi...@yahoo.com> wrote in message
news:3d28c005$1_2@dnews...

Quote
> By greyed out, do you mean to actually change the background color as
> needed?  When you enable/disable the groupbox, it automatically
> enables/disables its child controls for/from accepting user input already,
> at least.

> If you want to physically change the color of fields, with minimal code,
you
> can try doing something like this:

>     void __fastcall TForm1::EnableDisableGroupBox(TGroupBox *GB, bool
> bEnabled)
>     {
>         if(!GB) return;

>         for(int x = 0; x < GB->ControlCount; x++)
>         {
>             TEdit *edit = dynamic_cast<TEdit*>(GB->Controls[x]);
>             if(edit) edit->Color = (bEnabled) ? clWindow : GB->Color;
>         }
>         GB->Enabled = bEnabled;
>     }

> Then you can call it like this:

>     EnableDisableGroupBox(GroupBox1, false);
>     EnableDisableGroupBox(GroupBox2, true);

> Gambit

> "Totte Karlsson" <m...@u.washington.edu> wrote in message
> news:3d28b24e$1_2@dnews...

> > In my code I want to disable/enable groupboxes. When disabling
> > a groupbox, I want the edit boxes (and buttons) to become grayed
> > out. In code I have for example

> > GroupBox->Enabled = false;

> > How do I make the editboxes placed on this groupbox to
> > become greyed when this occur?
> > Do I have to write code for each editbox?

Re:Disabled groupBox


It seems that you have to handle the CM_ENABLEDCHANGED message. So, you
don't have to do it each time you modify the Enabled property. See my
question in the same newsgroup (subject = "Enabled property changed ?")
Hereafter is a function for disabling all children of a WinControl

Christophe

.h

template <class Function>
void ForAllChildren(TWinControl *parent, Function f)
{
    for (int i = 0; i < parent->ControlCount; ++i)
    {
        TControl *control = parent->Controls[i];
        TWinControl *child = dynamic_cast<TWinControl*>(control);
        if (child)
            ForAllChildren(child, f);
        f(control);
    }

Quote
}

void EnableChildren(TWinControl *control, bool enabled);

.cpp

struct EnableControl
{
    EnableControl(bool enabled) : Enabled(enabled) {}
    void operator()(TControl *control)
    {
        control->Enabled = Enabled;
    }
private:
    bool Enabled;

Quote
};

void EnableChildren(TWinControl *control, bool enabled)
{
    ForAllChildren(control, EnableControl(enabled));

Quote
}
"Totte Karlsson" <m...@u.washington.edu> wrote in message

news:3d28b24e$1_2@dnews...
Quote
> Hi,
> I have a groupbox with some edit controls on.
> In my code I want to disable/enable groupboxes. When disabling a groupbox,
I
> want the edit boxes (and buttons) to become grayed out. In code I have for
> example

> GroupBox->Enabled = false;

> How do I make the editboxes placed on this groupbox to become greyed when
> this occur?
> Do I have to write code for each editbox?
> /totte

Other Threads