更新日期:2018/07/13
網路上有一個基本操作的版本流傳,這邊附上自己實測可用的方式。
基本操作的CS檔在這=>請點我
宣告
public ppt.Presentation ObjPrs { get; private set; }
public ppt.SlideShowView OSlideShowView { get; private set; }
public ppt.Application ObjApp { get; private set; }
[DllImport("user32.dll")]
private static extern IntPtr SetParent(IntPtr childIntPtr, IntPtr parentIntPtr);
IntPtr hWnd;
string path = @"D:\news_2017.pptx"; //PPT路徑
int time = 1; //播放間隔
初始化內新建
public Form2()
{
InitializeComponent();
hWnd = this.panel1.Handle;
//opPPT.PPTAuto(path, time);
//防止連續打開多個PPT進程.
if (ObjApp != null) { return; }
ObjApp = new ppt.Application();
}
畫面啟動時播放
private void Form2_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
PlayPpt(OpenPpt(path),time);
}
操作相關函式
/// <summary>
/// 打開PPT
/// </summary>
/// <param name="url"></param>
/// <returns></returns>
public ppt.Presentation OpenPpt(string url)
{
var objPresSet = ObjApp.Presentations;
var objPrs = objPresSet.Open(url, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
return objPrs;
}
/// <summary>
/// 下一頁
/// </summary>
/// <returns></returns>
public int Next()
{
OSlideShowView.Next();
var index = OSlideShowView.Slide.SlideIndex - 1;
return index;
}
/// <summary>
/// 上一頁
/// </summary>
/// <returns></returns>
public int Previous()
{
OSlideShowView.Previous();
var index = OSlideShowView.Slide.SlideIndex - 1;
return index;
}
/// <summary>
/// 跳到制定頁
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
public int GoToSlide(int index)
{
OSlideShowView.GotoSlide(index);
return index;
}
/// <summary>
/// 播放ppt
/// </summary>
/// <param name="objPrs"></param>
/// <param name="time"></param>
ppt.SlideRange objSldRng;
ppt.SlideShowTransition objSST;
public void PlayPpt(ppt.Presentation objPrs,int time)
{
ObjPrs = objPrs;
//進入播放模式
var objSlides = objPrs.Slides;
var objSss = objPrs.SlideShowSettings;
objSss.LoopUntilStopped = MsoTriState.msoCTrue;
objSss.StartingSlide = 1;
objSss.EndingSlide = objSlides.Count;
objSss.ShowType = ppt.PpSlideShowType.ppShowTypeKiosk;
int Slides = objPrs.Slides.Count;
int[] SlideIdx = new int[Slides];
for (int i = 0; i < Slides; i++) { SlideIdx[i] = i + 1; };
objSldRng = objPrs.Slides.Range(SlideIdx);
objSST = objSldRng.SlideShowTransition;
//翻頁時間.
objSST.AdvanceOnTime = OFFICECORE.MsoTriState.msoCTrue;
objSST.AdvanceTime = time;
//翻頁特效!
objSST.EntryEffect = ppt.PpEntryEffect.ppEffectCircleOut;
var sw = objSss.Run();
OSlideShowView = objPrs.SlideShowWindow.View;
var wn = (IntPtr)sw.HWND;
////嵌入窗體
SetParent(wn, hWnd);
opPPT.PPTClose();
}
private void PptPlayWindow_OnLoaded(object sender, EventArgs e)
{
Closed += OnClosed;
}
private void OnClosed(object sender, EventArgs eventArgs) //關閉
{
try
{
ObjPrs.Close();
ObjApp.Quit();
}
catch{}
}
0 意見:
張貼留言