(winform)PDF文档或视频文件在线阅读或观看工具

使用COM控件

1,使用Windows Media Player播放视频。
效果
在这里插入图片描述
如果VS工具箱中没有这个控件,那么右击工具箱,添加选项卡,命名为COM,然后再COM选项栏,右击选择“选择项”,打开的对话框中选择“COM组件”,找到Windows Media Player,勾选之后,点击确定就添加到工具箱了。 然后直接从工具箱拉到窗体上就可以使用了。
如下图
在这里插入图片描述
下图窗体中,放了ToolStrip,ToolStrip选择了一个Button命名为“浏览”,一个TextBox,显示选择的文件完全名。然后还放了Windows Media Player。
在这里插入图片描述
代码如下:

//======================================================================
//        《31天学会CRM项目开发》机械工业出版社 版权所有 (C) 2015-2016
//        文件名:Form1.cs
//        随书附赠源代码,若转发需保留版权信息。
//        社区支持:http://www.huiyaosoft.com/
//======================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace MediaPlayerDemo
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string appPath = System.Windows.Forms.Application.StartupPath + "\\";

            //设置视频链接,可以是网络,也可以是本地
            //网络视频链接
            this.axWindowsMediaPlayer1.URL = @"http://2449.vod.myqcloud.com/2449_43b6f696980311e59ed467f22794e792.f20.mp4";
            //本地视频链接
            //this.axWindowsMediaPlayer1.URL = appPath +  "";           
        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            //设置对话框标题
            dlg.Title = "选择媒体文件";
            //按照扩展名过滤文件
            dlg.Filter = "所有文件|*.*|媒体文件|*.mp4*;*.avi;*.wmv";
            //是否支持多选
            dlg.Multiselect = false;
            //弹出对话框判断用户是否选择了文件
            if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                //重新选定播放文件路径
                this.axWindowsMediaPlayer1.URL = this.tstbMediaFile.Text = dlg.FileName;
        }
    }
}

2,使用Adobe PDF Reader阅读PDF文件
在这里插入图片描述
添加这个组件步骤参照上面的。
下图,放了Adobe PDF Reader,和ToolStrip。
在这里插入图片描述
代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AdobePDFReader2019
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            string appPath = Application.StartupPath + "\\";
            //使用webBrowser1阅读PDF
            //this.webBrowser1.Navigate(appPath + "31天学会CRM项目开发.pdf");

            axAcroPDF1.LoadFile(appPath + "31天学会CRM项目开发.pdf");
            #region 不显示工具栏
            //axAcroPDF1.setPageMode("thumbs");
            axAcroPDF1.setPageMode("none");
            #endregion
        }
        /// <summary>
        /// 选择PDF文档路径
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog();
            //设置对话框标题
            dlg.Title = "选择pdf文件";
            //按照扩展名过滤文件
            dlg.Filter = "所有文件|*.*|PDF文件|*.pdf*";
            //是否支持多选
            dlg.Multiselect = false;
            //弹出对话框判断用户是否选择了文件
            if (dlg.ShowDialog() == DialogResult.OK)
            {
                tstbPdfDir.Text = dlg.FileName;
                axAcroPDF1.LoadFile(dlg.FileName);
                #region 不显示工具栏
                //axAcroPDF1.setPageMode("thumbs");
                axAcroPDF1.setPageMode("none");
                #endregion
            }
        }
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值