Open text dialog with checkbox

7 次查看(过去 30 天)
Advait Valluri
Advait Valluri 2014-7-30
Hello Guys,
I am building a GUI with different functions in which I have an "Info" checkbox. When this box is checked, I programmed a uicontrol with some text in it which deems as information or help to the gui. When the checkbox is unchecked, the dialog box with the text is closed.
My question: How can I make this dialog box with the text to appear right next to the opened GUI, irrespective of where it is placed on the screen. It should always appear at the top right corner of the GUI (I have my checkbox also in this region). I tried to access the position of the GUI but the scaling seems to be different with different figures. Could someone please help me!!
Thanks, Advait

回答(2 个)

Robert Cumming
Robert Cumming 2014-7-30
编辑:Robert Cumming 2014-7-30
position and units are the 2 properties you want to look at.
Specific help wont be possible unless you give specific problem (i.e. code and example of when your dialog box position is not in the correct position.
Edit: based on your example code your problem is not the position but the fact the new dialog doesn't close when you uncheck the checkbox.
In the else section you need to delete (or set to invisible) the dialog you created. You need access to the figure handle to do that. Some ideas to get you going:
store the fig handle in handles data
store as a persistent variable in your callback.
store the handle in your user data of the checkbox
alternate your checkbox callback depending on the value

Advait Valluri
Advait Valluri 2014-7-30
编辑:Advait Valluri 2014-7-30
The function callback for the checkbox (with tag 'help') is as follows:
function help_Callback(hObject, eventdata, handles)
% hObject handle to help (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% fig_h = [];
if (get(hObject,'Value') == get(hObject,'Max'))
a = handles.pos_x + handles.width_x;
b = handles.pos_y;
help_text = info_box(a,b);
else
%%this region has to be filled
end
on checking the checkbox, the following function info_box is executed
function [S] = info_box(a,b)
% Creates a textbox.
S.fh = figure('units','pixels',...
'position',[a+20 b 200 300],...
'menubar','none',...
'resize','on',...
'numbertitle','off',...
'name','Information');
S.tx = uicontrol('style','text',...
'units','pix',...
'position',[10 10 190 290],...
'backgroundcolor','w',...
'HorizontalAlign','left',...
'min',0,'max',10,...
'enable','inactive');
help_text(1) = {'Welcome to the Wizard!'};
help_text(2) = {' '};
set(S.tx,'string',help_text)
I succeeded in putting the text box next to my gui but I am unable to close it when i uncheck the checkbox!
Could someone help me what i need to code in the "else" loop in the help_Callback function.

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by