How to move figure window to front of all programs?

82 ビュー (過去 30 日間)
Brandon
Brandon 2016 年 10 月 1 日
回答済み: DGM 2024 年 11 月 9 日
Is there a way to force a figure window to show in front of all other windows (not just Matlab ones, but other programs)?

採用された回答

Walter Roberson
Walter Roberson 2016 年 10 月 1 日
If you are using MS Windows you could experiment with using the 'topmost' command in Jan's File Exchange contribution https://www.mathworks.com/matlabcentral/fileexchange/31437-windowapi
  1 件のコメント
Brandon
Brandon 2016 年 10 月 1 日
Works perfectly! I was already using WindowAPI for some things so this is even better. Thank you.

サインインしてコメントする。

その他の回答 (3 件)

Raph
Raph 2022 年 12 月 29 日
編集済み: Raph 2022 年 12 月 29 日
This question is ambiguous, but I think what "most people" would be looking for searching for an answer to this question are the following:
How to bring to the front a specific figure handle?
h = figure;
h2 = figure;
% bring figure with handle h to the front
figure(h);
How to bring to the front a known figure with a given name?
figure('Name','A cool figure'); % create a figure and assign a unique name
allfigs = findall(0,'Type', 'figure'); % finds the handles of figures
desiredHandle = findall(allfigs, 'Name', 'A cool figure'); % finds the handles of figure with the unique name
if numel(desiredHandle)==1 % make sure its not deleted or actually is a valid handle
figure(desiredHandle(1)); % brings to front
end

Kamil Lipinski
Kamil Lipinski 2024 年 11 月 8 日
編集済み: Kamil Lipinski 2024 年 11 月 8 日
Try this, it takes all figures to the front BFF

DGM
DGM 2024 年 11 月 9 日
If you want the window to stay on top even if other windows are given focus, you can set that in the window manager.
% you have handle to a figure window
hfig = gcf;
inpict = imread('peppers.png');
imshow(inpict)
% bring it to the front and make it stay atop other windows
stickontop(hfig)
function stickontop(hfig)
% STICKONTOP(HFIG)
% Brings the specified figure window to the front and sets the
% 'always on top' flag. Relies on wmctrl and a linux environment.
% Docked figures are ignored.
% cache current title
oldtitle = get(hfig,'name');
oldntstate = get(hfig,'numbertitle');
% make the window externally identifiable
set(hfig,'name','windowtoberaised');
set(hfig,'numbertitle','off');
% configure properties in the window manager
pause(0.5) % wait for the WM
system('wmctrl -r "windowtoberaised" -b add,above');
% reset to old title
set(hfig,'name',oldtitle);
set(hfig,'numbertitle',oldntstate);
end
Of course, there are things that might cause the window to lose its "always on top" status again, so this might not be as persistent as one might hope.
A similar approach can be used to shade, minimize, or maximize windows, or move windows between workspaces, and it doesn't rely on version-dependent figure properties.

カテゴリ

Help Center および File ExchangeInteractive Control and Callbacks についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by