Advertisement
andrzejiwaniuk

[Napisz sam] Program do otwierania plików w formacie PDF

Jun 22nd, 2013
583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using Microsoft.Win32;
  16.  
  17. namespace AndrzejIwaniuk
  18. {
  19.     /// <summary>
  20.     /// Prosta aplikacja otwierająca plik *.PDF
  21.     /// </summary>
  22.     public partial class MainWindow : Window
  23.     {
  24.        
  25.         //zmienna statyczna przechowująca ścieżkę i nazwe do pliku *.PDF
  26.         static String nazwaPlikuPDF;
  27.        
  28.         //główna metoda uruchamiająca aplikację
  29.         public MainWindow()
  30.         {
  31.             InitializeComponent();
  32.         }
  33.        
  34.         void otworzPDF()
  35.         {
  36.             try
  37.             {
  38.                 System.Diagnostics.Process.Start(nazwaPlikuPDF);
  39.             }
  40.             //jeżeli błąd z otwarceim zgłość wyjątek
  41.             catch (Exception e)
  42.             {
  43.                 MessageBox.Show("Bład = " + e);
  44.             }
  45.  
  46.         }
  47.  
  48.         private void btnOpenPdf_Click(object sender, RoutedEventArgs e)
  49.         {
  50.             // Utwórz okno dialogowe do otwierania plików (OpenFileDialog)
  51.             OpenFileDialog dlg = new OpenFileDialog();
  52.  
  53.  
  54.             // otworz okno diaglowe OpenFileDialog przez wywołanie metody ShowDialog  
  55.             Nullable<bool> result = dlg.ShowDialog();
  56.  
  57.  
  58.             // Pobierz nazwę pliku i zapisz do zmienne statycznej nazwaPlikuPDF
  59.             if (result == true)
  60.             {
  61.                 // Open document
  62.                 string filename = dlg.FileName;
  63.                 nazwaPlikuPDF = filename;
  64.             }
  65.             //dla celów debugowania
  66.             MessageBox.Show(nazwaPlikuPDF);
  67.            
  68.             //wywołaj metode otwierającą plik *.PDF
  69.             otworzPDF();
  70.         }
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement