印刷する必要があるユーザー コントロールがあります。フォームは、記入済みの基本的なフォームです。名前付きのスタックパネルにすべてのコントロールを配置し、印刷用のボタンはスタックパネルの外側にあるため、ボタンは印刷されません。
<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 & 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 の読み込みはすべて個別に行われます。とにかく、コードビハインドを使用して、基本的にこれをボタンクリックに追加します。
PrintDialog prnt = new PrintDialog();
prnt.PrintVisual(PrntFrm, "Initiate Work Request");
これにより、フォーム (stackpanel) が出力されますが、ページの中央に配置されていません。左上にあり、左側のテキストの一部が切り取られています。
メソッドを使用して、PrintDialog
印刷するページのサイズを設定する方法、または印刷可能なフォームのコンテンツを中央に配置する方法は? また、からページの向きを設定するにはどうすればよいPrintDialog
ですか? を設定するPrintableAreaHeight/Width
必要がありますか? また、その方法は?