91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

WPF:WPF顯示PDF文檔

發布時間:2020-06-22 00:25:09 來源:網絡 閱讀:2201 作者:006玩命 欄目:編程語言

簡述

??軟件的幫助文檔可借助第三方軟件如PDF Reader、Adobe PDF等顯示,但客戶機上需安裝此類軟件。WPF開發的軟件可借助第三方庫 MoonPdf 將PDF文檔加載顯示到軟件窗口中(Dll下載地址,GitHub源碼地址)。

MoonPdf庫使用方式:

  1. 將MoonPdfLib.dll、libmupdf.dll、MouseKeyboardActivityMonitor.dll放置于WPF工程Bin文件下;
  2. 在項目工程中“引用”右鍵添加新引用:MoonPdfLib.dll;
  3. 在.xmal及.cs文件中添加相關引用,詳見代碼。

代碼

PDFViewer.xaml

<UserControl x:Class="NovelRPS.PdfViewer"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:mpp="clr-namespace:MoonPdfLib;assembly=MoonPdfLib"
             mc:Ignorable="d" 
             >
    <Grid>
        <!-- ContextMenu -->
        <Grid.ContextMenu>
            <ContextMenu>
                <MenuItem x:Name="ZoomToOrigin" Header="100%" Click="ZoomToOrigin_Click"></MenuItem>
                <MenuItem x:Name="SinglePage" Header="單頁" Click="SinglePage_Click"></MenuItem>
                <MenuItem x:Name="DoublePage" Header="雙頁" Click="DoublePage_Click"></MenuItem>
            </ContextMenu>
        </Grid.ContextMenu>

        <Border>
            <!-- 參考:https://www.cnblogs.com/yang-fei/p/4885570.html -->
            <mpp:MoonPdfPanel x:Name="pdfViewer" MaxZoomFactor="2.5" ViewType="SinglePage" PageRowDisplay="ContinuousPageRows" PageMargin="0,2,4,2" AllowDrop="True"></mpp:MoonPdfPanel>
        </Border>
    </Grid>
</UserControl>

PDFViewer.cs

using MoonPdfLib; //記得引用此命名空間

public partial class PdfViewer : UserControl
    {
        private bool m_bLoaded = false;

        public PdfViewer()
        {
            InitializeComponent();
        }

        public bool LoadPdfDoc( string strPdfPath )
        {
            try
            {
                this.pdfViewer.OpenFile( strPdfPath );
                this.pdfViewer.Zoom( 1.0 );
                m_bLoaded = true;
            }
            catch
            {
                m_bLoaded = false;
            }

            return m_bLoaded;
        }

        private void ZoomToOrigin_Click( object sender, RoutedEventArgs e )
        {
            if ( !m_bLoaded )
                return;
            this.pdfViewer.Zoom( 1.0 );
        }

        private void SinglePage_Click( object sender, RoutedEventArgs e )
        {
            if ( !m_bLoaded )
                return;
            this.pdfViewer.ViewType = ViewType.SinglePage;
        }

        private void DoublePage_Click( object sender, RoutedEventArgs e )
        {
            if ( !m_bLoaded )
                return;
            this.pdfViewer.ViewType = ViewType.Facing;
        }
    }

調用PdfViewer,及HelpWin窗口類:HelpWin.xaml

<Window x:Class="NovelRPS.HelpWin"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:NovelRPS"
        Title="HelpWin" Background="#FF212121" WindowState="Maximized" Topmost="True" WindowStyle="None" ResizeMode="NoResize">    
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="66"></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>

        <!-- Title -->
        <Label x:Name="Title" Grid.Row="0" Background="#FF414141" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Padding="0">
            <DockPanel>
                <Image DockPanel.Dock="Left" Source="Images/SubPageLogo.png"></Image>
                <Image x:Name="ImgClose" DockPanel.Dock="Right" Source="Images/Close.png" MouseDown="ImgClose_MouseDown"></Image>
                <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
                    <Image Source="Images/Setting/Help.png" Width="30"></Image>
                    <Label Content="幫助" FontSize="26"  FontWeight="Bold"></Label>
                </StackPanel>
            </DockPanel>
        </Label>

        <!-- Content -->
        <Label Grid.Row="1" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch">
            <local:PdfViewer x:Name="PDFView" Loaded="PDFView_Loaded"/>
        </Label>

    </Grid>
</Window>

HelpWin.cs

public partial class HelpWin : Window
    {
        private string m_strPdfPath = AppDomain.CurrentDomain.BaseDirectory + "help.pdf"; 

        public HelpWin()
        {
            InitializeComponent();
        }

        private void ImgClose_MouseDown( object sender, MouseButtonEventArgs e )
        {
            this.Close();
        }

        private void PDFView_Loaded( object sender, RoutedEventArgs e )
        {
            if ( !this.PDFView.LoadPdfDoc( m_strPdfPath ) )
            {
                MessageBox.Show( "打開幫助文檔失敗,請重試!" );
            }
        }
    }

效果

WPF:WPF顯示PDF文檔

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

安达市| 犍为县| 平和县| 铜陵市| 合江县| 佛坪县| 柳州市| 来凤县| 内黄县| 罗山县| 临邑县| 都安| 蚌埠市| 辽宁省| 额济纳旗| 德化县| 郧西县| 青岛市| 炎陵县| 酉阳| 黄大仙区| 义乌市| 宜丰县| 菏泽市| 寿宁县| 醴陵市| 阳谷县| 庆城县| 体育| 常熟市| 抚远县| 舟山市| 玉田县| 新密市| 昂仁县| 汽车| 金山区| 泰州市| 屏山县| 宣城市| 连平县|