# Change Control
> [HTML Version](changecontrol.htm)
_Rewritten February 2013_
CTLOP\_CHG (_opcode _2) can be used, in conjunction with various MBST\_xxx flags in the _cstate_ parameter, to change virtually any of the attributes of an existing control (such as the displayed text, state, command, etc.) For example, consider the following sample dialog:
_(./images/ashref_img93.png)_
The Connect button is disabled because the user hasn't entered enough information to even justify attempting a connection. Once they do so, we want to enable the Connect button, which we can do with something like the following:
xcall AUI, AUI\_CONTROL, CTLOP\_CHG, btnid, NUL\_CTEXT, MBST\_ENABLE
_(./images/ashref_img94.png)_
The key parameters here were the button identifier and the MBST\_ENABLE flag. We're not changing the button text, so we just supply NUL\_CTEXT (defined as "" in the [ashell.def](ashell_def.htm.md)) for the _ctext_ parameter, and none of the other parameters are required. If we wanted to know what the prior state of the control was, we could pass the _cstatus_ parameter (and those prior to it), but in most cases, we don't care about the prior state.
To take another example, let's say we want to change the label associated with the second field, depending on the Database Connector - for MySQL, "Host/Server" seems appropriate, but for ODBC, "Data Source" might be better. To accomplish that, we can use a slight variation of the CTLOP\_CHG operation:
xcall AUI, AUI\_CONTROL, CTLOP\_CHG, btnid, "Data Source", MBST\_CHANGE + MBST\_TEXTONLY
_(./images/ashref_img95.png)_
The combination of the MBST\_CHANGE and MBST\_TEXTONLY flags in the _cstate _parameter causes the operation to only affect the text of the control, for which we supplied the string "Data Source".
Depending on which MBST\_xxx flags are specified, you may need to specify more parameters, with the extreme case being MBST\_CHANGEX which replaces all of the attributes of the control (essentially deleting and recreating it). Virtually all of the MBST\_xxx _cstate_ flags can be used with CTLOP\_CHG, but the following ones apply uniquely to CTLOP\_CHG and are therefore worth noting:
| **Symbol** | **Description** |
|------|------|
| MBST\_CHANGE | Change ctext and cmd. |
| MBST\_TEXTONLY | Add to MBST\_CHANGE to limit the changes to the ctext |
| MBST\_STYLE | Change the style and alignment flags (ctype) |
| MBST\_POS | Change the position (coordinates) |
| MBST\_CHANGEX | Change everything |
| MBST\_NORMALIZE | Change a maximized dialog back to normal state |