XAMLの全コード
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="401" Width="522">
<Grid>
<Grid Name="Grid1" Margin="0,25,0,0">
<Ellipse Height="50" HorizontalAlignment="Left" Margin="65,91,0,0" Name="Ellipse1" Stroke="Black" VerticalAlignment="Top" Width="93" Fill="BlueViolet" />
<Label Content="Label" Height="28" HorizontalAlignment="Left" Margin="225,167,0,0" Name="Label1" VerticalAlignment="Top" />
<Rectangle Height="56" HorizontalAlignment="Left" Margin="264,85,0,0" Name="Rectangle1" Stroke="Black" VerticalAlignment="Top" Width="101" Fill="Magenta" />
</Grid>
<StackPanel Height="25" HorizontalAlignment="Left" Name="StackPanel1" VerticalAlignment="Top">
<Button Content="印刷" Height="23" Name="Button1" Width="75" />
</StackPanel>
</Grid>
</Window>
Class MainWindowクラスの全コード
Imports System.Windows.Xps
Imports System.Printing
Class MainWindow
Public Sub New()
InitializeComponent()
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles Button1.Click
Dim page As New FixedPage
Dim content1 As New PageContent
Dim doc As New FixedDocument
page.Width = 120 * 96 / 25.4
page.Height = 70 * 96 / 25.4
Dim Ellipse2 As Ellipse = New Ellipse
CopyEllipse(Ellipse1, Ellipse2)
page.Children.Add(Ellipse2)
Dim Rectangle2 As Rectangle = New Rectangle
page.Children.Add(Rectangle2)
CopyRectangle(Rectangle1, Rectangle2)
Dim Label2 As Label = New Label
CopyLabel(Label1, Label2)
page.Children.Add(Label2)
CType(content1, Markup.IAddChild).AddChild(page)
doc.Pages.Add(content1)
Dim imgArea As PrintDocumentImageableArea = Nothing
Dim writer As XpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(imgArea)
If writer Is Nothing Then
Else
writer.Write(doc)
End If
End Sub
Sub CopyEllipse(Ellipse1 As Ellipse, Ellipse2 As Ellipse)
Ellipse2.Height = Ellipse1.Height
Ellipse2.HorizontalAlignment = Ellipse1.HorizontalAlignment
Ellipse2.Margin = Ellipse1.Margin
Ellipse2.Stroke = Ellipse1.Stroke
Ellipse2.VerticalAlignment = Ellipse1.VerticalAlignment
Ellipse2.Width = Ellipse1.Width
Ellipse2.Fill = Ellipse1.Fill
End Sub
Sub CopyRectangle(Rectangle1 As Rectangle, Rectangle2 As Rectangle)
Rectangle2.Height = Rectangle1.Height
Rectangle2.HorizontalAlignment = Rectangle1.HorizontalAlignment
Rectangle2.Margin = Rectangle1.Margin
Rectangle2.Stroke = Rectangle1.Stroke
Rectangle2.VerticalAlignment = Rectangle1.VerticalAlignment
Rectangle2.Width = Rectangle1.Width
Rectangle2.Fill = Rectangle1.Fill
End Sub
Sub CopyLabel(Label1 As Label, Label2 As Label)
Label2.Content = Label1.Content
Label2.Height = Label1.Height
Label2.HorizontalAlignment = Label1.HorizontalAlignment
Label2.Margin = Label1.Margin
Label2.VerticalAlignment = Label1.VerticalAlignment
End Sub
End Class