?? contact_name_callback.m
字號:
function varargout = Contact_Name_Callback(h, eventdata, handles, varargin)
%在Contact Name和Phone編輯框眾獲取字符串
Current_Name = get(handles.Contact_Name,'string');
Current_Phone = get(handles.Contact_Phone,'string');
%如果為空則返回
if isempty(Current_Name)
return
end
%從句柄結構體中獲取當前地址列表
Addresses = handles.Addresses;
%搜索姓名列表,判斷是否與一個已有姓名相同
for i = 1:length(Addresses)
if strcmp(Addresses(i).Name,Current_Name)
set(handles.Contact_Name,'string',Addresses(i).Name)
set(handles.Contact_Phone,'string',Addresses(i).Phone)
handles.Index = i;
guidata(h,handles)
return
end
end
%如果是個新的姓名,請求創建一個新的條目
Answer=questdlg('Do you want to create a new entry?', ...
'Create New Entry', ...
'Yes','Cancel','Yes');
switch Answer
case 'Yes'
Addresses(end+1).Name = Current_Name; % Grow array by 1
Addresses(end).Phone = Current_Phone;
index = length(Addresses);
handles.Addresses = Addresses;
handles.Index = index;
guidata(h,handles)
return
case 'Cancel'
%恢復為初始數值
set(handles.Contact_Name,'string',Addresses(handles.Index).Name)
set(handles.Contact_Phone,'String',Addresses(handles.Index).Phone)
return
end
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -