Setting GUI Control Default Properties by Style
조회 수: 1 (최근 30일)
이전 댓글 표시
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')
댓글 수: 0
채택된 답변
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!
댓글 수: 0
추가 답변 (1개)
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?
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!