Setting GUI Control Default Properties by Style

1 回表示 (過去 30 日間)
Andy
Andy 2011 年 5 月 11 日
When setting default values for GUI control properties, you can set default properties for all uicontrols:
f = figure;
set(f,'DefaultUicontrolString','Hello World');
uicontrol('parent',f,'style','text')
But can you set different sets of defaults for uicontrols with different styles? The following does NOT work, but makes my intent clear:
f = figure;
set(f,'DefaultTextBackgroundColor','gray')
set(f,'DefaultEditBackgroundColor','white')
uicontrol(f,'style','text','string','hello')
uicontrol(f,'style','edit','string','world')

採用された回答

Matt Fig
Matt Fig 2011 年 5 月 12 日
When I write GUIs I usually specify the minimum property descriptions necessary for each style, then at the end of my initialization code I call a custom function to set my standard defaults.
This function takes no arguments (except optionally a figure handle for limiting the search), but uses FINDALL to parse through each style of uicontrol and assign the defaults like fontsize, backgroundcolor, etc.
It sounds like you could benefit from writing such a function too!

その他の回答 (1 件)

Daniel Shub
Daniel Shub 2011 年 5 月 11 日
You cannot control the properties like you want. You could create a new function (or even class) that mimics uicontrols, but would allow you to specify default values. One problem with your example is if you create a text box control and then change it to an edit box control would the background color change?
  1 件のコメント
Andy
Andy 2011 年 5 月 12 日
What is the benefit of being able to turn uicontrols of one style into another? In any case, if you create a text box and change it to an edit box, I would expect it to keep the text box default properties. (Otherwise changing the style would be the same as destroying the control and creating a new one.)
Is it common in GUI toolkits for inherently different controls to be combined into one like this? (I don't think so, but I don't know many other GUI toolkits.) Why is this done in MATLAB?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by