4 Replies - 17482 Views - Last Post: 22 April 2013 - 05:13 AM Rate Topic: -----

#1 priya24dec  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-June 12

Open powerpoint presentation on window form using C#.net.

Posted 20 April 2013 - 05:55 AM

Hello all,
i have done one demo application.
it showing powerpoint presentation on form but at the same time it opening other instance of Powerpoint.but i dnt want this.i only want to open Power point on window form.not other instance.so please give me hint/suggestion .how to do that.


using System.Diagnostics;
using System.Runtime.InteropServices;
using ppt = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;       
        [DllImport("user32.dll", EntryPoint = "FindWindow", SetLastError = true)]
        static extern IntPtr FindWindow(IntPtr ZeroOnly, string lpWindowName);

        [DllImport("user32.dll", SetLastError = true)]
        static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);


        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern bool SetWindowText(IntPtr hwnd, String lpString);

        ppt.Presentation presentation;
        Microsoft.Office.Interop.PowerPoint.SlideShowView oSlideShowView;
        bool flag = false;

   public void open(string FileName)
        {
            try
            {
                ppt.Application application;

                // For Display in Panel
                IntPtr screenClasshWnd = (IntPtr)0;
                IntPtr x = (IntPtr)0;

                application = new ppt.Application();

                presentation = application.Presentations.Open(FileName, MsoTriState.msoTrue, MsoTriState.msoTrue, MsoTriState.msoFalse);



                panel1.Controls.Add(application as Control);
                ppt.SlideShowSettings sst1 = presentation.SlideShowSettings;


                sst1.LoopUntilStopped = Microsoft.Office.Core.MsoTriState.msoCTrue;

                ppt.Slides objSlides = presentation.Slides;



                sst1.LoopUntilStopped = MsoTriState.msoTrue;


                sst1.StartingSlide = 1;
                sst1.EndingSlide = objSlides.Count;



                panel1.Dock = DockStyle.Fill;



                sst1.ShowType = ppt.PpSlideShowType.ppShowTypeKiosk;



                ppt.SlideShowWindow sw = sst1.Run();


                oSlideShowView = presentation.SlideShowwindow.View;




                IntPtr pptptr = (IntPtr)sw.HWND;


                SetParent(pptptr, panel1.Handle);


            }
            catch (Exception)
            {

                throw;
            }

        }

This post has been edited by tlhIn`toq: 20 April 2013 - 07:35 AM
Reason for edit:: Code tags


Is This A Good Question/Topic? 0
  • +

Replies To: Open powerpoint presentation on window form using C#.net.

#2 no2pencil  Icon User is offline

  • Professor Snuggly Pants
  • member icon

Reputation: 6547
  • View blog
  • Posts: 30,673
  • Joined: 10-May 07

Re: Open powerpoint presentation on window form using C#.net.

Posted 20 April 2013 - 07:19 AM

** Moved to C# **

The sub forum "Site Questions & Support" is for questions about the site. Please post language specific questions in the correct sub forum.
Was This Post Helpful? 0
  • +
  • -

#3 tlhIn`toq  Icon User is offline

  • Xamarin Cert. Dev.
  • member icon

Reputation: 6507
  • View blog
  • Posts: 14,372
  • Joined: 02-June 10

Re: Open powerpoint presentation on window form using C#.net.

Posted 20 April 2013 - 07:38 AM

Let's teach rather than just give you the answer...

When you debug, and put a breakpoint on the first like of the method... Then walk through the execution line by line... Which line opens up the second instance that you don't want? Find that line and comment it out.

If you aren't familiar with debugging your own code or executing line by line, tutorials are listed below.



tlhIn`toq's FAQ list

Learning to debug one's own code is an essential skill. Sadly, one that apparently few college courses teach. Silly if you ask me.

Placing breakpoints and walking through the code line by line allows you to actually WATCH it execute.

Visualizing what your code does will let you see why it behaves the way it does.

It would be well worth your time to do the tutorials on FAQ 2. A couple hours learning this skill will save you hundreds of hours of confusion in one project alone.


TOP most asked:
What does this error message mean?
FAQ 2: How do I debug
FAQ 3: How do I make Class1/Form1 talk to Class2/Form2


FAQ (Frequently Asked Questions - Updated Apr 2013
Spoiler



Was This Post Helpful? 0
  • +
  • -

#4 priya24dec  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 9
  • Joined: 13-June 12

Re: Open powerpoint presentation on window form using C#.net.

Posted 22 April 2013 - 04:20 AM

Yes.i have allready tried this.put breakpoint and dubug line by line..but yet its not solved.Anyways thanQ for reply.
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 5885
  • View blog
  • Posts: 20,092
  • Joined: 05-May 12

Re: Open powerpoint presentation on window form using C#.net.

Posted 22 April 2013 - 05:13 AM

You didn't answer the question. So you stepped through the code line by line... did you discover which line is causing PowerPoint to display? Did you try commenting out that line (recompiling and running again)?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1