Effacer les filtres
Effacer les filtres

Setting right input mask without GUIDE for an edit uicontrol

1 vue (au cours des 30 derniers jours)
Csaba
Csaba le 8 Août 2011
Hello,
I try to control an industrial process through Matlab. That's why I'm creating a GUI (without using GUIDE).
My problem is that when I create an edit uicontrol, the user can give any kind of characters as input (even tab and/or enter/return). My goal is to jump to the next uicontrol (the next one should be defined in the EditUIControlFix.m file) when either one of the tab or enter/return keys are hit by the user.
Any idea how to implement this in my code?
Thank you in advance, Csaba
Here is the code :
function EditUIControlFix
%%Initialzation user interface main window
clc
clear all;
disp(' ');
disp(['Script started on ' datestr(now, 'dddd') ', the ' datestr(now, 'dd mmmm yyyy') ' at ' datestr(now, 'HH:MM:SS.FFF')]);
%%Creating main window
size_screen = get( 0,'ScreenSize');
UIWindowWidth = 1500;
UIWindowHeight = 844;
UIWindowColor = 'White';
UIWindowStandardSpacing = 20;
UILabelWidth = 150;
UILabelHeight = 15;
UIFieldWidth = 80;
UIFieldHeight = 23;
UIWindowMain = figure;
set(gcf,'NumberTitle','off');
set(gcf,'Name','Display control panel');
set(gcf,'MenuBar','none');
set(gcf,'DoubleBuffer','on');
set(gcf,'Position',[((size_screen(3)-UIWindowWidth)/2) min(((size_screen(3)-UIWindowHeight)/2),50) UIWindowWidth UIWindowHeight]);
set(gcf,'Color',UIWindowColor);
%%Creating process panel
UIPanelProcess = uipanel;
UIPanelProcessPanelNumber = 1;
UIPanelProcessControlsNumber = 2;
UIPanelProcessSpaceNumber = UIPanelProcessControlsNumber+1.5;
UIPanelProcessWidth = 3*UIWindowStandardSpacing+UILabelWidth+UIFieldWidth;
UIPanelProcessHeight = UIPanelProcessSpaceNumber*UIWindowStandardSpacing+UIPanelProcessControlsNumber*max(UILabelHeight,UIFieldHeight);
UIPanelProcessHorizontalPosition = UIWindowStandardSpacing;
UIPanelProcessVerticalPosition = UIWindowHeight-UIPanelProcessPanelNumber*UIWindowStandardSpacing-UIPanelProcessHeight;
set(UIPanelProcess,'Parent',UIWindowMain);
set(UIPanelProcess,'Tag','UIPanelProcess');
set(UIPanelProcess,'Units','Pixels');
set(UIPanelProcess,'Position',[UIPanelProcessHorizontalPosition UIPanelProcessVerticalPosition UIPanelProcessWidth UIPanelProcessHeight]);
set(UIPanelProcess,'BorderWidth',1);
set(UIPanelProcess,'BackgroundColor',UIWindowColor);
set(UIPanelProcess,'Visible','On');
set(UIPanelProcess,'FontSize',16);
set(UIPanelProcess,'TitlePosition','CenterTop');
set(UIPanelProcess,'Title','Process');
%%Creating parameter 1 label
UIParameterOneLabel = uicontrol;
UIParameterOneLabelControlNumber = 1;
UIParameterOneLabelWidth = UILabelWidth;
UIParameterOneLabelHeight = UILabelHeight;
UIParameterOneLabelHorizontalPosition = UIWindowStandardSpacing/2;
UIParameterOneLabelVerticalPosition = UIPanelProcessHeight-(UIParameterOneLabelControlNumber+1.5)*UIWindowStandardSpacing-...
(0.5+UIParameterOneLabelControlNumber-1)*UIParameterOneLabelHeight;
set(UIParameterOneLabel,'Parent',UIPanelProcess);
set(UIParameterOneLabel,'Tag','UIParameterOneLabel');
set(UIParameterOneLabel,'Style','Text');
set(UIParameterOneLabel,'Units','Pixels');
set(UIParameterOneLabel,'Position', [UIParameterOneLabelHorizontalPosition UIParameterOneLabelVerticalPosition ...
UIParameterOneLabelWidth UIParameterOneLabelHeight]);
set(UIParameterOneLabel,'HorizontalAlignment','Left');
set(UIParameterOneLabel,'ForegroundColor','Black');
set(UIParameterOneLabel,'BackgroundColor',UIWindowColor);
set(UIParameterOneLabel,'Visible','On');
set(UIParameterOneLabel,'FontSize',9);
set(UIParameterOneLabel,'String','Parameter 1 [V]');
%%Creating parameter 1 value
UIParameterOneValue = uicontrol;
UIParameterOneValueControlNumber = UIParameterOneLabelControlNumber;
ParameterOneValueDefault = 5.0;
ParameterOneMin = 0.0;
ParameterOneMax = 100.0;
UIParameterOneValueWidth = UIFieldWidth;
UIParameterOneValueHeight = UIFieldHeight;
UIParameterOneValueHorizontalPosition = UIPanelProcessWidth-UIParameterOneValueWidth-UIWindowStandardSpacing;
UIParameterOneValueVerticalPosition = UIPanelProcessHeight-(UIParameterOneValueControlNumber+1.5)*UIWindowStandardSpacing- ...
(UIParameterOneValueControlNumber-0.5)*UIParameterOneValueHeight+(UIParameterOneValueControlNumber-1)* ...
(UIWindowStandardSpacing-1.5*abs(UIParameterOneValueHeight-UIParameterOneLabelHeight));
set(UIParameterOneValue,'Parent',UIPanelProcess);
set(UIParameterOneValue,'Tag','UIParameterOneValue');
set(UIParameterOneValue,'Style','Edit');
set(UIParameterOneValue,'Callback',@SetParameterOne);
set(UIParameterOneValue,'Units','Pixels');
set(UIParameterOneValue,'Position',[UIParameterOneValueHorizontalPosition UIParameterOneValueVerticalPosition ...
UIParameterOneValueWidth UIParameterOneValueHeight]);
set(UIParameterOneValue,'HorizontalAlignment','Right');
set(UIParameterOneValue,'ForegroundColor','Black');
set(UIParameterOneValue,'BackgroundColor',UIWindowColor);
set(UIParameterOneValue,'Visible','On');
set(UIParameterOneValue,'FontSize',12);
set(UIParameterOneValue,'Min',ParameterOneMin);
set(UIParameterOneValue,'Max',ParameterOneMax);
set(UIParameterOneValue,'SliderStep',[0.1 0.01]);
set(UIParameterOneValue,'String',num2str(ParameterOneValueDefault));
%%Creating parameter 2 label
UIParameterTwoLabel = uicontrol;
UIParameterTwoLabelControlNumber = 2;
UIParameterTwoLabelWidth = UILabelWidth;
UIParameterTwoLabelHeight = UILabelHeight;
UIParameterTwoLabelHorizontalPosition = UIWindowStandardSpacing/2;
UIParameterTwoLabelVerticalPosition = UIPanelProcessHeight-(UIParameterTwoLabelControlNumber+1.5)*UIWindowStandardSpacing-...
(0.5+UIParameterTwoLabelControlNumber-1)*UIParameterTwoLabelHeight;
set(UIParameterTwoLabel,'Parent',UIPanelProcess);
set(UIParameterTwoLabel,'Tag','UIParameterTwoLabel');
set(UIParameterTwoLabel,'Style','Text');
set(UIParameterTwoLabel,'Units','Pixels');
set(UIParameterTwoLabel,'Position', [UIParameterTwoLabelHorizontalPosition UIParameterTwoLabelVerticalPosition ...
UIParameterTwoLabelWidth UIParameterTwoLabelHeight]);
set(UIParameterTwoLabel,'HorizontalAlignment','Left');
set(UIParameterTwoLabel,'ForegroundColor','Black');
set(UIParameterTwoLabel,'BackgroundColor',UIWindowColor);
set(UIParameterTwoLabel,'Visible','On');
set(UIParameterTwoLabel,'FontSize',9);
set(UIParameterTwoLabel,'String','Parameter 2 [V]');
%%Creating parameter 2 value
UIParameterTwoValue = uicontrol;
UIParameterTwoValueControlNumber = UIParameterTwoLabelControlNumber;
ParameterTwoValueDefault = 3.0;
ParameterTwoMin = 2.0;
ParameterTwoMax = 8.0;
UIParameterTwoValueWidth = UIFieldWidth;
UIParameterTwoValueHeight = UIFieldHeight;
UIParameterTwoValueHorizontalPosition = UIPanelProcessWidth-UIParameterTwoValueWidth-UIWindowStandardSpacing;
UIParameterTwoValueVerticalPosition = UIPanelProcessHeight-(UIParameterTwoValueControlNumber+1.5)*UIWindowStandardSpacing- ...
(UIParameterTwoValueControlNumber-0.5)*UIParameterTwoValueHeight+(UIParameterTwoValueControlNumber-1)* ...
(UIWindowStandardSpacing-1.5*abs(UIParameterTwoValueHeight-UIParameterTwoLabelHeight));
set(UIParameterTwoValue,'Parent',UIPanelProcess);
set(UIParameterTwoValue,'Tag','UIParameterTwoValue');
set(UIParameterTwoValue,'Style','Edit');
set(UIParameterTwoValue,'Callback',@SetParameterTwo);
set(UIParameterTwoValue,'Units','Pixels');
set(UIParameterTwoValue,'Position',[UIParameterTwoValueHorizontalPosition UIParameterTwoValueVerticalPosition ...
UIParameterTwoValueWidth UIParameterTwoValueHeight]);
set(UIParameterTwoValue,'HorizontalAlignment','Right');
set(UIParameterTwoValue,'ForegroundColor','Black');
set(UIParameterTwoValue,'BackgroundColor',UIWindowColor);
set(UIParameterTwoValue,'Visible','On');
set(UIParameterTwoValue,'FontSize',12);
set(UIParameterTwoValue,'Min',ParameterTwoMin);
set(UIParameterTwoValue,'Max',ParameterTwoMax);
set(UIParameterTwoValue,'SliderStep',[0.1 0.01]);
set(UIParameterTwoValue,'String',num2str(ParameterTwoValueDefault));
function SetParameterTwo(varargin)
%%Callback function to set the parameter one
ParameterTwo = get(UIParameterTwoValue,'String');
ParameterTwo = str2double(ParameterTwo);
if isnan(ParameterTwo)
set(UIParameterTwoValue, 'String', num2str(ParameterTwoValueDefault));
ParameterTwo = ParameterTwoValueDefault;
errordlg(' The input for the 1st parameter must be a number.','Error');
end
disp(['The parameter 2 is set to ' num2str(ParameterTwo) ' V.']);
end
function SetParameterOne(varargin)
%%Callback function to set the parameter one
ParameterOne = get(UIParameterOneValue,'String');
ParameterOne = str2double(ParameterOne);
if isnan(ParameterOne)
set(UIParameterOneValue, 'String', num2str(ParameterOneValueDefault));
ParameterOne = ParameterOneValueDefault;
errordlg(' The input for the 1st parameter must be a number.','Error');
end
disp(['The parameter 1 is set to ' num2str(ParameterOne) ' V.']);
end
end

Réponses (0)

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by