请大虾们指教:怎样在一个panel中连续的添加button

请大虾们指教:怎样在一个panel中连续的添加button,第1张

实现的方法有两个:

1使用动态填加控件的办法:controlsadd()

2直接放两个button到panel内,用代码来控制他们的显示和位置,以及显示的内容。

使用1方法必须在页面LOAD的时候进行,同时避免页面回发的时候出问题,你需要多测试几次。。

使用方法2就很简单了。。

用界面打开图像,并用鼠标左键动态取像素值,右键取消值,并用红色字体显示。哈哈

function varargout = imageaxe(varargin)

% IMAGEAXE M-file for imageaxefig

% IMAGEAXE, by itself, creates a new IMAGEAXE or raises the existing

% singleton

%

% H = IMAGEAXE returns the handle to a new IMAGEAXE or the handle to

% the existing singleton

%

% IMAGEAXE('CALLBACK',hObject,eventData,handles,) calls the local

% function named CALLBACK in IMAGEAXEM with the given input arguments

%

% IMAGEAXE('Property','Value',) creates a new IMAGEAXE or raises the

% existing singleton Starting from the left, property value pairs are

% applied to the GUI before imageaxe_OpeningFcn gets called An

% unrecognized property name or invalid value makes property application

% stop All inputs are passed to imageaxe_OpeningFcn via varargin

%

% See GUI Options on GUIDE's Tools menu Choose "GUI allows only one

% instance to run (singleton)"

%

% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help imageaxe

% Last Modified by GUIDE v25 25-Feb-2012 17:11:05

% Begin initialization code - DO NOT EDIT

gui_Singleton = 1;

gui_State = struct('gui_Name', mfilename,

'gui_Singleton', gui_Singleton,

'gui_OpeningFcn', @imageaxe_OpeningFcn,

'gui_OutputFcn', @imageaxe_OutputFcn,

'gui_LayoutFcn', [] ,

'gui_Callback', []);

if nargin && ischar(varargin{1})

gui_Stategui_Callback = str2func(varargin{1});

end

if nargout

[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});

else

gui_mainfcn(gui_State, varargin{:});

end

% End initialization code - DO NOT EDIT

% --- Executes just before imageaxe is made visible

function imageaxe_OpeningFcn(hObject, eventdata, handles, varargin)

% This function has no output args, see OutputFcn

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% varargin command line arguments to imageaxe (see VARARGIN)

% Choose default command line output for imageaxe

handlesoutput = hObject;

% Update handles structure

guidata(hObject, handles);

% UIWAIT makes imageaxe wait for user response (see UIRESUME)

% uiwait(handlesfigure1);

% --- Outputs from this function are returned to the command line

function varargout = imageaxe_OutputFcn(hObject, eventdata, handles)

% varargout cell array for returning output args (see VARARGOUT);

% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure

varargout{1} = handlesoutput;

varargout{2}=handles;

% --------------------------------------------------------------------

function image_pixel_Callback(hObject, eventdata, handles)

% hObject handle to image_pixel (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% --------------------------------------------------------------------

function m_file_open_Callback(hObject, eventdata, handles)

% hObject handle to m_file_open (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global I hText

[filename, pathname] = uigetfile(

{'bmp;jpg;png;jpeg', 'Image Files ';

'','All Files'}, 'test',

'D:\autostitch\images\test');

%用axes命令设定当前 *** 作的坐标轴是axes_src

I=[pathname,filename];%将文件名和目录名组合成一个完整的路径

F= imread(I);%用imread读入

axes(handlesaxes1_src);

imshow(F);

impixelinfo; % or you can use pixval;

[x y]=ginput(1); % when you clike mouse, [x y] respond its image coordination

global pointXY

pointXY=[];

set(gcf,'WindowButtonDownFcn',@WindowButtonDownFcn);

%set(gcf,'KeyPressFcn',@KeyPressFcn);

function WindowButtonDownFcn(hObject, eventdata, handles)

%if strcmp(get(hObject,'SelectionType'),'normal')

global pointXY

global hText

if strcmp(get(hObject,'SelectionType'),'normal')

pt = get(gca,'CurrentPoint'); % 如何限制鼠标获得图像的坐标,不要空白处坐标。

x = pt(1,1);

y = pt(1,2);

str = sprintf('x = %3f, y = %3f', x, y);

hText=text(x, y, str,'color',[1 0 0]);

pointXY=[pointXY;[x y]];

elseif strcmp(get(hObject,'SelectionType'),'alt')

if ishandle(hText)

delete(hText);

pointXY(end,:)=[];

end

end

%elseif strcmp(get(hObject,'SelectionType'),'alt')

% if ishandle(hText)

% delete(hText);

% pointXY(end,:)=[];

% end

%end

%function KeyPressFcn(hObject, eventdata, handles)

%global pointXY

%key=get(hObject,'currentkey');

%switch key

% case 'return'

%xlswrite('1xls',pointXY);

% msgbox('采集的点已经保存到1xls文件中!');

%end

% hText=text(x, y, 'string','color',[1 0 0]);

%ht=findobj(handlestext2,'tag',[x y]);

% set(handlestext2,'string', hText)

%ht = findobj(h,'tag',[mfilename '_text']);

%set(handlestext2,'string',strcat(num2str(x),',',num2str(y)))

%set(gcf,'WindowButtonDownFcn',@ButttonDownFcn);

% 回调函数

%function ButttonDownFcn(src,event)

%pt = get(gca,'CurrentPoint');

%x = pt(1,1);

%y = pt(1,2);

%pointXY=[];

%fprintf('x=%f,y=%f\n',x,y);

% pt = get(gca,'CurrentPoint');

% x = pt(1,1);

% y = pt(1,2);

% str = sprintf('x = %3f, y = %3f', x, y);

%set(handlestext2,'string', str);

% save

% --- Executes during object creation, after setting all properties

function axes1_src_CreateFcn(hObject, eventdata, handles)

% hObject handle to figure1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% --------------------------------------------------------------------

function m_file_quit_Callback(hObject, eventdata, handles)

% hObject handle to m_file_quit (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

close

function edit1_Callback(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of edit1 as text

% str2double(get(hObject,'String')) returns contents of edit1 as a double

% --- Executes during object creation, after setting all properties

function edit1_CreateFcn(hObject, eventdata, handles)

% hObject handle to edit1 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows

% See ISPC and COMPUTER

if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))

set(hObject,'BackgroundColor','white');

end

% --------------------------------------------------------------------

function m_file_save_Callback(hObject, eventdata, handles)

% hObject handle to m_file_save (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

[FileOutName,FileOutPath]=uiputfile('m','Save file name','C:\Documents and Settings\Administrator\桌面\matlab\第二周\mouse_axem');

%StrFileOut=strcat(FileOutPath,FileOutName)

%hgsave(gcf,' imageaxefig')

就是当Windows产生鼠标右键单击事件时,挂载这个函数。于是当你单击鼠标右键时,会产生Windows事件,在对应的回调函数会加载Matlab的这个函数,也就是根据当前鼠标位置执行后面的内容。

好好学习天天向上

在buttton的点击事件中,添加如下代码:

datagridviewRowsAdd(GuidNewGuid(),textboxtext,comboboxtext)

GuidNewGuid():用来生成ID

以上就是关于请大虾们指教:怎样在一个panel中连续的添加button全部的内容,包括:请大虾们指教:怎样在一个panel中连续的添加button、matlab中如何根据点的索引获得点的坐标、下面matlab程序中的ButttonDownFcn(src,event)是什么意思等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/9505513.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-29
下一篇 2023-04-29

发表评论

登录后才能评论

评论列表(0条)

保存