2014-10-29 2 views
1

인쇄 할 사용자 정의 컨트롤이 있습니다. 양식은 단지 기본 양식입니다. 컨트롤은 모두 이름이 지정된 스택 패널에 배치되고 인쇄용 버튼은 스택 패널 외부에 있으므로 버튼이 인쇄되지 않습니다. 사용자 정의 컨트롤을 A4 페이지 중앙에 인쇄

<UserControl x:Class="*****.PrintInitiateRequestFormView" 
     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:WpfToolkit="http://schemas.microsoft.com/wpf/2008/toolkit" 
     mc:Ignorable="d" 
     Style="{StaticResource TransitionAnimation}"> 
<ScrollViewer> 
    <Border Style="{StaticResource PanelWindowBackground}"> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="Auto" /> 
      </Grid.ColumnDefinitions> 
      <Grid.RowDefinitions> 
       <RowDefinition Height="Auto" /> 
       <RowDefinition Height="Auto" /> 
      </Grid.RowDefinitions> 
      <StackPanel x:Name="PrntFrm" 
         Grid.Row="0"> 
       <Border Grid.Row="1" 
         Grid.Column="1" 
         Margin="3,3,3,0" 
         VerticalAlignment="Stretch" 
         HorizontalAlignment="Stretch" 
         Style="{StaticResource PanelWindowBackground}"> 
        <Grid> 
         <Grid.RowDefinitions> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
          <RowDefinition Height="Auto" /> 
         </Grid.RowDefinitions> 
         <Grid.ColumnDefinitions> 
          <ColumnDefinition Width="Auto" /> 
          <ColumnDefinition Width="200" /> 
          <ColumnDefinition Width="200" /> 
          <ColumnDefinition Width="200" /> 
          <ColumnDefinition /> 
         </Grid.ColumnDefinitions> 
         <Image Source="/Lamacs_8;component/Resources/Images/NMBM_Logo.jpg" 
           Stretch="Fill" 
           Grid.ColumnSpan="2" 
           Margin="0,0,74,0" 
           Width="265"> 

         </Image> 
         <Label Grid.Row="1" 
           Grid.ColumnSpan="4" 
           HorizontalAlignment="Center" 
           Content="WORK REQUEST" 
           FontSize="20" /> 

         <Label Grid.Row="2" 
           Grid.ColumnSpan="2" 
           Content="Call Centre" 
           FontSize="20"> 

         </Label> 

         <Label Grid.Row="2" 
           Grid.Column="2" 
           FontSize="20" 
           Content="Reference Number:" /> 

         <Label Grid.Row="2" 
           Grid.Column="3" 
           FontSize="16" 
           Content="{Binding RefNo}" /> 

         <Label Grid.Row="3" 
           Grid.Column="2" 
           FontSize="16" 
           Content="Date &amp; Time Logged:" /> 

         <Label Grid.Column="3" 
           Grid.Row="3" 
           FontSize="16" 
           Content="{Binding CaptureDate}" /> 

         <Label Grid.Row="4" 
           Grid.Column="0" 
           Content="Building:" 
           FontSize="16" /> 

         <Label Grid.Row="4" 
           Grid.Column="1" 
           Content="{Binding LandObjectBuilding}" 
           FontSize="16" /> 

         <Label Grid.Row="5" 
           Grid.Column="0" 
           Content="Address:" 
           FontSize="16" /> 

         <Label Grid.Column="1" 
           Grid.Row="5" 
           FontSize="16" 
           Grid.ColumnSpan="2" 
           Content="{Binding LandObjectAddress}" /> 

         <Label Grid.Row="6" 
           Grid.Column="0" 
           Content="Caller:" 
           FontSize="16" /> 

         <Label Grid.Row="6" 
           Grid.Column="1" 
           Content="{Binding CallerName}" 
           FontSize="16" /> 

         <Label Grid.Row="6" 
           Grid.Column="2" 
           Content="Telephone:" 
           FontSize="16" /> 

         <Label Grid.Row="6" 
           Grid.Column="3" 
           Content="{Binding CallerTel}" 
           FontSize="16" /> 

         <Label Grid.Row="7" 
           Grid.Column="0" 
           Content="Problem Description:" 
           FontSize="16" /> 

         <TextBox Grid.Row="7" 
           Grid.Column="1" 
           Grid.ColumnSpan="3" 
           Height="50" 
           TextWrapping="Wrap" 
           Text="{Binding ProblemDesc}" 
           FontSize="16" 
           Background="Transparent" 
           BorderBrush="Transparent" /> 

         <Label Grid.Row="8" 
           Grid.Column="2" 
           Content="Person Responsible:" 
           FontSize="16" /> 

         <Label Grid.Row="8" 
           Grid.Column="3" 
           Content="{Binding Assistant}" 
           FontSize="16" /> 

         <Label Grid.Row="8" 
           Grid.Column="0" 
           Content="Sector" 
           FontSize="16" /> 

         <Label Grid.Row="8" 
           Grid.Column="1" 
           Content="{Binding Sector}" 
           FontSize="16" /> 

         <Label Grid.Row="9" 
           Grid.Column="0" 
           Content="Component" 
           FontSize="16" /> 

         <Label Grid.Row="9" 
           Grid.Column="1" 
           Content="{Binding Component}" 
           FontSize="16" /> 

         <Label Grid.Row="9" 
           Grid.Column="2" 
           Content="Element" 
           FontSize="16" /> 

         <Label Grid.Row="9" 
           Grid.Column="3" 
           Content="{Binding Element}" 
           FontSize="16" /> 

         <Separator Grid.Row="11" 
            Grid.ColumnSpan="4" /> 

         <Label Grid.Row="12" 
           Grid.Column="0" 
           Content="Official:" 
           FontSize="20" /> 

         <Label Grid.Row="13" 
           Grid.Column="0" 
           Content="Scope Of Work:" 
           FontSize="16" /> 

         <TextBox Grid.Row="13" 
           Grid.Column="1" 
           Grid.ColumnSpan="3" 
           FontSize="16" 
           TextWrapping="Wrap" 
           Text="{Binding ScopeOfWork}" 
           Background="Transparent" 
           BorderBrush="Transparent" /> 

         <Label Grid.Row="14" 
           Grid.Column="0" 
           Content="Cost Estimate:" 
           FontSize="16" /> 

         <Label Grid.Row="14" 
           Grid.Column="1" 
           FontSize="16" 
           Content="{Binding CostEstimate}" /> 

         <Label Grid.Row="14" 
           Grid.Column="2" 
           Content="Name:" 
           FontSize="16" /> 

         <Label Grid.Row="14" 
           Grid.Column="3" 
           FontSize="16" 
           Content="{Binding ReportName}" /> 

         <Label FontSize="16" 
           Grid.Row="15" 
           Grid.Column="0" 
           Content="Date:" /> 
         <Label Grid.Row="15" 
           Grid.Column="1" 
           Content="{Binding FormDate}" 
           FontSize="16" /> 

         <Label Grid.Row="16" 
           Grid.Column="0" 
           Grid.ColumnSpan="4" 
           Content="(Obtain Quotes if required)" 
           FontSize="16" 
           HorizontalAlignment="Center" /> 

         <Separator Grid.Row="17" 
            Grid.ColumnSpan="4" /> 

         <Label FontSize="20" 
           Content="Admin" 
           Grid.Column="0" 
           Grid.Row="18" /> 

         <Label FontSize="16" 
           Content="Funds Available:" 
           Grid.Column="0" 
           Grid.Row="19" /> 

         <Label FontSize="16" 
           Content="Yes" 
           Grid.Column="1" 
           Grid.Row="19" /> 

         <Label FontSize="16" 
           Content="No" 
           Grid.Column="1" 
           Grid.Row="19" 
           Margin="50,0,0,0" /> 

         <Label Grid.Column="2" 
           Grid.Row="19" 
           Content="Vote/ISO Number:" 
           FontSize="16" /> 

         <Label Grid.Row="19" 
           Grid.Column="3" 
           FontSize="16" 
           Content="{Binding VISONum}" /> 

         <Separator Grid.ColumnSpan="4" 
            Grid.Row="20" /> 

         <Label Grid.Row="21" 
           Grid.Column="0" 
           Content="Official:" 
           FontSize="20" /> 

         <Label Grid.Row="22" 
           Grid.Column="0" 
           Content="Contractor:" 
           FontSize="16" /> 

         <Label Grid.Row="22" 
           Grid.Column="1" 
           Grid.ColumnSpan="2" 
           FontSize="16" 
           Content="{Binding Contractor}" /> 

         <Label Grid.Row="23" 
           Grid.Column="0" 
           Content="Order No:" 
           FontSize="16" /> 

         <Label Grid.Row="23" 
           Grid.Column="1" 
           FontSize="16" 
           Content="{Binding OrderNo}" /> 

         <Label Grid.Row="23" 
           Grid.Column="2" 
           Content="Date Issued:" 
           FontSize="16" /> 

         <Label Grid.Row="23" 
           Grid.Column="3" 
           Content="{Binding DateIssued}" 
           FontSize="16" /> 

         <Label Grid.Column="0" 
           Grid.Row="24" 
           FontSize="16" 
           Content="Cost of Works:" /> 

         <Label Grid.Row="24" 
           Grid.Column="1" 
           FontSize="16" 
           Content="{Binding CostWorks}" /> 

         <Label Content="Variance:" 
           FontSize="16" 
           Grid.Row="24" 
           Grid.Column="2" /> 

         <Label Grid.Row="24" 
           Grid.Column="3" 
           FontSize="16" 
           Content="{Binding Variance}" /> 

         <Label Grid.Column="0" 
           Grid.Row="25" 
           FontSize="16" 
           Content="Reason:" /> 

         <Label Grid.Row="25" 
           Grid.Column="1" 
           Grid.ColumnSpan="3" 
           FontSize="16" 
           Content="{Binding Reason}" /> 

         <Separator Grid.ColumnSpan="4" 
            Grid.Row="26" /> 
         <Label Grid.Row="27" 
           Grid.Column="0" 
           Grid.ColumnSpan="3" 
           Content="I hereby declare that the cost of the works is fair and reasonable." 
           FontSize="16" /> 

         <Label Grid.Row="28" 
           Grid.Column="0" 
           Content="Name:" 
           FontSize="16" /> 

         <Label Grid.Row="28" 
           Grid.Column="1" 
           Grid.ColumnSpan="3" 
           VerticalContentAlignment="Bottom" 
           FontSize="16" 
           Height="40" 
           Content="......................................................................................................................" /> 

         <Label Grid.Row="29" 
           Grid.Column="0" 
           Content="Date:" 
           FontSize="16" /> 

         <Label Grid.Row="29" 
           Grid.Column="1" 
           Grid.ColumnSpan="3" 
           VerticalContentAlignment="Bottom" 
           FontSize="16" 
           Height="40" 
           Content="......................................................................................................................" /> 

         <Label Grid.Row="30" 
           Grid.Column="0" 
           Content="Signature:" 
           FontSize="16" /> 

         <Label Grid.Row="30" 
           Grid.Column="1" 
           Grid.ColumnSpan="3" 
           VerticalContentAlignment="Bottom" 
           FontSize="16" 
           Height="40" 
           Content="......................................................................................................................" /> 
        </Grid> 
       </Border> 
      </StackPanel> 
      <StackPanel Grid.Row="1" 
         Orientation="Horizontal"> 
       <Button Width="150" 
         Height="25" 
         Margin="4,0,0,5" 
         HorizontalAlignment="Left" 
         Template="{StaticResource PrintButtonTemplate}" 
         Click="Button_Click" /> 
       <Button Width="150" 
         Height="25" 
         Margin="4,0,0,5" 
         HorizontalAlignment="Left" 
         Template="{StaticResource CloseButtonTemplate}" 
         x:Name="CloseButton" 
         Click="CloseButton_Click" /> 
      </StackPanel> 
     </Grid> 
    </Border> 
</ScrollViewer> 

당신은 모든 MVVM 로딩을 마음 수

, 즉 sepratly 이루어집니다. 어쨌든, 뒤에 코드를 사용하여, 나는 기본적으로 내 버튼 클릭이 추가 :

PrintDialog prnt = new PrintDialog(); 

prnt.PrintVisual(PrntFrm, "Initiate Work Request"); 

이 내 양식 (StackPanel을)를 출력합니다,하지만 정확히 페이지의 중앙에 있지 않습니다. 왼쪽 상단에 위치하며 텍스트의 일부는 왼쪽에서 잘립니다.

PrintDialog 방법을 사용하면 인쇄 할 페이지의 크기를 설정하거나 인쇄 가능한 양식의 가운데를 어떻게 배치합니까? 또한 페이지 방향을 PrintDialog에서 어떻게 설정할 수 있습니까? PrintableAreaHeight/Width을 설정해야하나요? 어떻게해야합니까?

답변

2

알겠습니다.

PrintDialog prnt = new PrintDialog(); 
     if (prnt.ShowDialog() == true) 
     { 
      Size pageSize = new Size(prnt.PrintableAreaWidth - 30, prnt.PrintableAreaHeight - 30); 
      PrntFrm.Measure(pageSize); 
      PrntFrm.Arrange(new Rect(15, 15, pageSize.Width, pageSize.Height)); 
      prnt.PrintVisual(PrntFrm, "Work Request"); 
     } 

은 화면 용 화면입니다. 크기는

PrintDialog prnt = new PrintDialog(); 
     if (prnt.ShowDialog() == true) 
     { 
      prnt.PrintTicket.PageOrientation = System.Printing.PageOrientation.Landscape; 
      Size pageSize = new Size(prnt.PrintableAreaWidth + 30, prnt.PrintableAreaHeight + 300); 
      PrntFrm.Measure(pageSize); 
      PrntFrm.Arrange(new Rect(15, 15, pageSize.Height, pageSize.Width)); 
      prnt.PrintVisual(PrntFrm, "Job Card"); 
     } 

가로을위한 인쇄하는 데 필요한 양에 따라 변경 될 수 있습니다. 다시 필요할 때 크기가 변경됩니다.

관련 문제