PowerPoint 加载项 在幻灯片放映中在幻灯片上书写
PowerPoint Add-in Write on Slide in Slideshow
在编写 PowerPoint 加载项时,我需要在屏幕上的幻灯片顶部绘制一些内容。
我可以画线条和图像,但它们几乎立即消失了。
示例代码:
private void Application_SlideShowBegin(PowerPoint.SlideShowWindow Wn)
{
using (var g = Graphics.FromHwnd((IntPtr)Wn.HWND))
{
g.DrawLine(new Pen(Color.Red, 10), new System.Drawing.Point(100, 100), new System.Drawing.Point(200, 300));
Image img = Properties.Resources.img;
g.DrawImageUnscaled(img, new Rectangle(250, 250, img.Width, img.Height));
}
}
知道如何将绘制的线条/图像保留在屏幕上吗?
我应该早点看到它 - 这是关于刷新的。代码需要运行晚一点,所以如果延迟绘制,绘图会停留在window上。
以下示例现在按预期运行:
private Timer _Ticker = new Timer();
private PowerPoint.SlideShowWindow _SlideshowWindow = null;
private void Application_SlideShowBegin(PowerPoint.SlideShowWindow Wn)
{
_SlideshowWindow = Wn;
_Ticker.Interval = 30;
_Ticker.AutoReset = true;
_Ticker.Elapsed += Ticker_Elapsed;
_Ticker.Enabled = true;
}
private void Ticker_Elapsed(object sender, ElapsedEventArgs e)
{
if (_Ticker.Enabled)
{
using (var g = Graphics.FromHwnd((IntPtr)_SlideshowWindow.HWND))
{
g.DrawLine(new Pen(Color.Red, 10), new System.Drawing.Point(100, 100), new System.Drawing.Point(200, 300));
Image img = Properties.Resources.img;
g.DrawImageUnscaled(img, new Rectangle(250, 250, img.Width, img.Height));
}
_Ticker.Enabled = false;
_Ticker.Elapsed -= Ticker_Elapsed;
}
}
在编写 PowerPoint 加载项时,我需要在屏幕上的幻灯片顶部绘制一些内容。 我可以画线条和图像,但它们几乎立即消失了。
示例代码:
private void Application_SlideShowBegin(PowerPoint.SlideShowWindow Wn)
{
using (var g = Graphics.FromHwnd((IntPtr)Wn.HWND))
{
g.DrawLine(new Pen(Color.Red, 10), new System.Drawing.Point(100, 100), new System.Drawing.Point(200, 300));
Image img = Properties.Resources.img;
g.DrawImageUnscaled(img, new Rectangle(250, 250, img.Width, img.Height));
}
}
知道如何将绘制的线条/图像保留在屏幕上吗?
我应该早点看到它 - 这是关于刷新的。代码需要运行晚一点,所以如果延迟绘制,绘图会停留在window上。 以下示例现在按预期运行:
private Timer _Ticker = new Timer();
private PowerPoint.SlideShowWindow _SlideshowWindow = null;
private void Application_SlideShowBegin(PowerPoint.SlideShowWindow Wn)
{
_SlideshowWindow = Wn;
_Ticker.Interval = 30;
_Ticker.AutoReset = true;
_Ticker.Elapsed += Ticker_Elapsed;
_Ticker.Enabled = true;
}
private void Ticker_Elapsed(object sender, ElapsedEventArgs e)
{
if (_Ticker.Enabled)
{
using (var g = Graphics.FromHwnd((IntPtr)_SlideshowWindow.HWND))
{
g.DrawLine(new Pen(Color.Red, 10), new System.Drawing.Point(100, 100), new System.Drawing.Point(200, 300));
Image img = Properties.Resources.img;
g.DrawImageUnscaled(img, new Rectangle(250, 250, img.Width, img.Height));
}
_Ticker.Enabled = false;
_Ticker.Elapsed -= Ticker_Elapsed;
}
}