事件处理函数忽略了一些函数

时间:2011-05-01 04:23:10

标签: c# winforms powerpoint

我正在使用来自代码项目的globalhook类来控制带有自定义键(windows窗体应用程序)的powerpoint幻灯片我希望在按下任意键时关闭powerpoint对象但事件处理程序忽略此函数并拒绝执行任何操作,除非它在主要表格的范围。这是我的代码:

public partial class Form1 : Form
{
    PowerPoint.Application objApp;
    PowerPoint.Presentations objPresSet;
    PowerPoint._Presentation objPres;
    PowerPoint.Slides objSlides;
    PowerPoint._Slide objSlide;

    public Form1()
    {
        InitializeComponent();
        UserActivityHook actHook;
        objApp = new PowerPoint.Application();
        actHook = new UserActivityHook(); // crate an instance with global hooks

        // hang on events

        actHook.KeyPress += new KeyPressEventHandler(MyKeyPress);
        objPresSet = objApp.Presentations;
        objPres = objPresSet.Add(MsoTriState.msoTrue);

        objSlides = objPres.Slides;
    }

    [STAThread]
    public static void Main(string[] args)
    {
        Application.Run(new Form1());
    }

    // UserActivityHook actHook;

    public void MyKeyPress(object sender, KeyPressEventArgs e)
    {
        Form2 Form2 = new Form2();

         button1.Hide(); //executes normally 
         Form2.Show(); //no action
         objApp.Quit(); // no action
    }

    private void button1_Click(object sender, EventArgs e)
    {
        Form2 Form2 = new Form2();
        Form2.Show();
    }   
}

1 个答案:

答案 0 :(得分:0)

尝试使用here中的HookManager类,它可以和我一起使用。