ProgressPanel、WaitForm、SplashScreenManager

介绍 DevExpress 提供的 ProgressPanel 和 WaitForm 控件,用于显示程序加载进度及耗时操作等待界面。通过设置 LookAndFeel 和 SplashFormManager 可自定义外观。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ProgressPanel Class

控件 指示进度条

Namespace: DevExpress.XtraWaitForm
Assembly: DevExpress.XtraEditors.vXX.dll
Syntax
VB
C#
public class ProgressPanel : BaseStyleControl, ITransparentBackgroundManager
Remarks

为一个进度条控件

每一个皮肤ProgressPanel包含自己的动画图片. 

许多方式可以选择皮肤。


LookAndFeel.UseDefaultLookAndFeel =true或者 UseDefaultLookAndFeel =false并设置LookAndFeel属性的SkinName属性

下面是皮肤示例。


如果需要在单独的窗体显示进度面板,使用WaitForm ,它由 SplashScreenManager 负责管理。

---------------------------------------------
WaitForm

Namespace:DevExpress.XtraWaitForm

Assembly: DevExpress.XtraEditors.
Syntax
VB
C#
public class WaitForm : SplashFormBase
备注

WaitForm 包含一个动画图像 (由当前皮肤获取) and 两个自定义标签(标题和描述) :

To create a Wait Form, drop a SplashScreenManager component onto your form, click the component's tag and then click the Add Wait Form link in the SplashScreenManager Tasks window that will open:

This generates a WaitForm's descendant that you can modify at design time.

A Wait Form 需要手动控制显示, 使用SplashScreenManager 提供的方法,主要控制方法为:

splashScreenManager.ShowWaitForm();

splashScreenManager.CloseWaitForm();

-------------------------------------------SplashScreenManager -----------------------------------


      splashScreenManager这个控件的主要作用就是显示程序集加载之前的进度条显示和进行耗时操作时候的等待界面。窗体加载完成后会自动消失。可以通过在

private void MainForm_Load(object sender, EventArgs e)
        {
            System.Threading.Thread.Sleep(5000);
        }

测试。

       1.新建一个Windows窗体,在工具栏Navigation和Layout中找到SplashScreenManager,把它拖放到Windows窗体中。

          

  2.找到这个控件,点击右上角的三角图标,出现如下显示的下拉菜单,点击“Add Splash Screen”然后打开解决方案资源管理器,你会发现多了一个名为“SplashScreen1.cs”的窗体,打开它,如下图所示:

3.两个图片、标签控件和一个进度条控件,可以根据自己的需要进行修改。

4.然后在程序入口出加上如下代码,就可以显示在程序加载之前显示进度条了(不添加下面的代码一样可以显示效果)

第二种方式:添加“正在加载"

       点击splashScreenManager1控件右上角的三角图标,出现如下显示的下拉菜单,点击“Add Wait Form”然后打开解决方案资源管理器,你会发现多了一个名为“WaitForm1.cs”的窗体,打开它,如下图所示:

      在按钮单击事件中加入如下代码:就可以实现“正在加载”的提示了。

 



以下是一个简单的音乐播放器的Java代码示例,实现了播放、暂停、停止等功能,并且插入了已有的图片作为播放器界面的背景: ```java import javax.sound.sampled.*; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; public class MusicPlayer extends JFrame implements ActionListener { private JButton playBtn, pauseBtn, stopBtn; private JLabel timeLabel, durationLabel; private JSlider progressSlider; private Clip clip; private Timer timer; private long clipTime; public MusicPlayer() { super("Music Player"); // 设置播放器界面背景 ImageIcon bgImage = new ImageIcon("music_bg.jpg"); JLabel bgLabel = new JLabel(bgImage); bgLabel.setBounds(0, 0, bgImage.getIconWidth(), bgImage.getIconHeight()); this.getLayeredPane().add(bgLabel, new Integer(Integer.MIN_VALUE)); // 创建控制按钮 playBtn = new JButton("Play"); playBtn.addActionListener(this); pauseBtn = new JButton("Pause"); pauseBtn.addActionListener(this); stopBtn = new JButton("Stop"); stopBtn.addActionListener(this); // 创建时间和进度条显示标签 timeLabel = new JLabel("00:00"); durationLabel = new JLabel("00:00"); progressSlider = new JSlider(0, 0, 0); // 创建播放器布局 JPanel controlPanel = new JPanel(new GridLayout(1, 3, 10, 0)); controlPanel.add(playBtn); controlPanel.add(pauseBtn); controlPanel.add(stopBtn); JPanel progressPanel = new JPanel(new BorderLayout()); progressPanel.add(timeLabel, BorderLayout.WEST); progressPanel.add(progressSlider, BorderLayout.CENTER); progressPanel.add(durationLabel, BorderLayout.EAST); JPanel playerPanel = new JPanel(new BorderLayout()); playerPanel.add(controlPanel, BorderLayout.NORTH); playerPanel.add(progressPanel, BorderLayout.CENTER); this.getContentPane().add(playerPanel); this.setSize(bgImage.getIconWidth(), bgImage.getIconHeight()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { MusicPlayer player = new MusicPlayer(); } @Override public void actionPerformed(ActionEvent e) { if (e.getSource() == playBtn) { if (clip == null) { try { File file = new File("music.mp3"); AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(file); AudioFormat format = audioInputStream.getFormat(); DataLine.Info info = new DataLine.Info(Clip.class, format); clip = (Clip) AudioSystem.getLine(info); clip.open(audioInputStream); clipTime = clip.getMicrosecondPosition(); progressSlider.setMaximum((int) clip.getMicrosecondLength() / 1000000); durationLabel.setText(formatTime(clip.getMicrosecondLength() / 1000)); } catch (UnsupportedAudioFileException ex) { ex.printStackTrace(); } catch (LineUnavailableException ex) { ex.printStackTrace(); } catch (IOException ex) { ex.printStackTrace(); } } if (!clip.isActive()) { clip.setMicrosecondPosition(clipTime); } clip.start(); // 启动定时器,更新进度条和时间显示标签 timer = new Timer(500, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (clip != null) { long currentTime = clip.getMicrosecondPosition(); clipTime = currentTime; progressSlider.setValue((int) currentTime / 1000000); timeLabel.setText(formatTime(currentTime / 1000)); } } }); timer.start(); } else if (e.getSource() == pauseBtn) { if (clip != null) { clipTime = clip.getMicrosecondPosition(); clip.stop(); timer.stop(); } } else if (e.getSource() == stopBtn) { if (clip != null) { clip.stop(); clipTime = 0; clip.setMicrosecondPosition(clipTime); progressSlider.setValue(0); timeLabel.setText("00:00"); timer.stop(); } } } // 将毫秒数格式化为00:00的形式 private String formatTime(long milliseconds) { long seconds = milliseconds / 1000; long minutes = seconds / 60; seconds = seconds % 60; return String.format("%02d:%02d", minutes, seconds); } } ``` 在上述代码中,我们使用了JFrame和Swing组件来创建了一个音乐播放器的界面,并且插入了已有的图片作为背景。我们使用了JavaSound API中的Clip类来实现音乐的播放功能,并且使用了JSlider和JLabel等组件来显示播放进度和时间。 在播放按钮被点击时,我们首先读取音频文件并使用Clip类来播放音频数据。同时,我们启动一个定时器来定时更新进度条和时间显示标签的值,实现了进度条的自动更新。在暂停和停止按钮被点击时,我们暂停或停止Clip对象的播放,并且停止定时器的运行。 需要注意的是,本示例代码只支持播放MP3格式的音频文件。如果需要支持其他格式的音频文件,需要针对不同的格式进行解码和转码。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值