IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

C# Discussion :

afficher un powerpoint dans une form


Sujet :

C#

  1. #1
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut afficher un powerpoint dans une form
    Bonjour,

    J'ai besoin d'afficher (d'une manière ou d'une autre) des diaporamas dans un composant de mon form que je peux redimensionner. Je ne veux devoir modifier le format du fichier (convertir en vidéo en html ...). J'avoue que mon niveau en C# et en Anglais me bloque alors si vous avez une solution merci d'avance de penser à moi

    J'ai trouvé 2 solutions pour afficher mon powerpoint dans mon form mais ça fonctionne pas comme je veux

    Solution 1
    https://support.microsoft.com/fr-fr/...ts-in-visual-c

    1. à cette ligne
      Code : Sélectionner tout - Visualiser dans une fenêtre à part
      axWebBrowser1.Navigate(strFileName, ref refmissing, ref refmissing, ref refmissing, ref refmissing);
      une boite de dialogue s'ouvre pour me demander si j'ouvre ou enregistre le fichier
    2. Le document s'ouvre mais dans powerpoint et non dans ma form


    Si vous avez une solution ...

    Solution 2
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Runtime.InteropServices;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Microsoft.Office.Interop.PowerPoint;
    using ppt = Microsoft.Office.Interop.PowerPoint;
    using Microsoft.Office.Core;
     
    namespace WindowsFormsApplication2
    {
        public partial class Form1 : Form
        {
            [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);
            Presentation presentation;
     
            SlideShowView oSlideShowView;
            int slideEnCours = 0;
            int totalSlides = 0;
     
            public Form1()
            {
                InitializeComponent();
            }
     
            private void Form1_Load(object sender, EventArgs e)
            {
                string FileName = @"C:\Users\...\Documents\Visual Studio 2015\Projects\VisualisationDynamique\Présentation1.pptx";
                open(FileName);
            }
     
            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);
                    SlideShowSettings sst1 = presentation.SlideShowSettings;
                    sst1.LoopUntilStopped = MsoTriState.msoFalse;
                    Slides objSlides = presentation.Slides;
                    sst1.LoopUntilStopped = MsoTriState.msoTrue;
                    sst1.StartingSlide = 1;
                    sst1.EndingSlide = objSlides.Count;
                    totalSlides = objSlides.Count;
     
                    sst1.ShowType = PpSlideShowType.ppShowTypeKiosk;
                    SlideShowWindow sw = sst1.Run();
     
                    presentation.SlideShowSettings.ShowWithAnimation = Microsoft.Office.Core.MsoTriState.msoTrue;
                    presentation.SlideShowWindow.Width = panel1.Width-100;
                    presentation.SlideShowWindow.Height = panel1.Height-100;
     
                    oSlideShowView = presentation.SlideShowWindow.View;
                    IntPtr pptptr = (IntPtr)sw.HWND;
                    SetParent(pptptr, panel1.Handle);
                }
                catch (Exception)
                {
                    throw;
                }
            }
     
            private void timer1_Tick_1(object sender, EventArgs e)
            {
                oSlideShowView.Next();
                slideEnCours += 1;
                if (slideEnCours >= totalSlides)
                {
                    timer1.Enabled = false;
                    slideEnCours = 0;
                    panel1.Visible = false;
                }
                this.Refresh();
            }
    1. Ca marche pas mal mais je n'arrive pas à charger une nouvelle présentation
    2. Le powerpoint n'utilise pas le timer prés réalisé



    Si vous avez une idée


    Par avance merci pour votre aide

  2. #2
    Expert confirmé
    Avatar de wallace1
    Homme Profil pro
    Administrateur systèmes
    Inscrit en
    Octobre 2008
    Messages
    1 966
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Puy de Dôme (Auvergne)

    Informations professionnelles :
    Activité : Administrateur systèmes
    Secteur : Aéronautique - Marine - Espace - Armement

    Informations forums :
    Inscription : Octobre 2008
    Messages : 1 966
    Points : 4 005
    Points
    4 005
    Billets dans le blog
    7
    Par défaut
    Bonsoir,

    Dans le 1 de ta solution 2 il serait logique de disposer les ressources de ton objet "application" et aussi de fermer ta "presentation" au prealable avant de vouloir rouvrir un autre fichier .ppt.........

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
     
    GC.Collect();
    GC.WaitForPendingFinalizers();
     
    Marshal.ReleaseComObject(objslides)
    Marshal.ReleaseComObject(sst1)
     
    presentation.close
    Marshal.ReleaseComObject(presentation)
     
    application.Quit
    Marshal.ReleaseComObject(application)

  3. #3
    Membre actif Avatar de Speed41
    Homme Profil pro
    Inscrit en
    Novembre 2002
    Messages
    718
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 56
    Localisation : France

    Informations forums :
    Inscription : Novembre 2002
    Messages : 718
    Points : 210
    Points
    210
    Par défaut
    Ok merci, ça fonctionne.
    Le problème de timing c'est en fonction de l’extension car y en a qui fonctionnent bien.

Discussions similaires

  1. Afficher un PowerPoint dans une page Jsp
    Par goprok dans le forum Servlets/JSP
    Réponses: 3
    Dernier message: 11/03/2014, 21h47
  2. [OLE] powerpoint dans une form
    Par makele dans le forum C++Builder
    Réponses: 6
    Dernier message: 16/02/2011, 11h33
  3. [Débutant] comment afficher un text dans une form
    Par frederic_lh dans le forum VB.NET
    Réponses: 2
    Dernier message: 04/03/2010, 20h10
  4. Afficher un Powerpoint dans une application silverlight
    Par Wasrack dans le forum Silverlight
    Réponses: 5
    Dernier message: 04/11/2008, 13h05
  5. afficher du powerpoint dans une zone définie
    Par Into7 dans le forum VB.NET
    Réponses: 1
    Dernier message: 25/07/2007, 14h33

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo