Jump to content

GuiCtrlSetStyle does not work


is8591
 Share

Recommended Posts

Simple test GUI has 2 combo boxes. Box 1 gets Style set by GuiCtrlSetStyle, Box 2 style is set in control create command.

Since the style value is identical both Combos should perform identically. But for some reason Combo 1 does not hold value after selection and allows type in, while Combo 2 operates perfectly.

Anybody can explain.

#include <GuiConstants.au3>
$str = "Select Item|Item1|Item2|Item3"

GuiCreate("Test", 140, 140) 
$Combo_1 = GuiCtrlCreateCombo("", 10, 25, 120, 80)
$Combo_2 = GuiCtrlCreateCombo("", 10, 65, 120, 80, BitOR($CBS_DROPDOWNLIST,$WS_VSCROLL))            
GUICtrlSetData($Combo_1, $str,"Select Item")
GUICtrlSetData($Combo_2, $str,"Select Item")
GUICtrlSetStyle($Combo_1,BitOR($CBS_DROPDOWNLIST,$WS_VSCROLL))          

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop

    Case Else
    ;;;
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

Since the style value is identical both Combos should perform identically.

What makes you think this? You are creating one control with the styles, you are post-creation applying the styles in the other. That is not the same and the results are not going to be the same in some cases (Including this one). Specify styles at creation time, Windows, and AutoIt, make no guarantee that all styles can be changed later on. Changing styles after creation is a sign of either bad code or advanced code. In this case, it's a sign of bad code.
Link to comment
Share on other sites

What makes you think this? You are creating one control with the styles, you are post-creation applying the styles in the other. That is not the same and the results are not going to be the same in some cases (Including this one). Specify styles at creation time, Windows, and AutoIt, make no guarantee that all styles can be changed later on. Changing styles after creation is a sign of either bad code or advanced code. In this case, it's a sign of bad code.

Why do you say "post-creation applying the styles in the other." I applied the style in Combo1 in postcreation. Combo2 was just to illustrate the difference

I thought that style can be changed dynamically.

As far as this being a "sign of bad code" - you may be right.

Here is what I am trying to do - could you please give me good code.

I have 2 combos and several edit boxes.

There are 2 modes of operation: view and edit.

In view mode combo boxes only provide dropdown for user to select INI section and key

In edit mode user can modify the info in combo boxes.

Edit boxes are always used for key values.

In order to give this functionality I have to set style of combo to

BitOR($CBS_DROPDOWNLIST,$WS_VSCROLL) not to have info edited.

And remove the style when combo editable.

Thanks

Edited by is8591
Link to comment
Share on other sites

I thought that style can be changed dynamically.

You thought wrong. Some styles can, but not all. There may be a special message the combo control accepts to change the style but if not, some styles will not change once the control is created.
Link to comment
Share on other sites

You thought wrong. Some styles can, but not all. There may be a special message the combo control accepts to change the style but if not, some styles will not change once the control is created.

Thanks.

Could you recomend a more elegant solution than setting up 2 controls in same space?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...