目标:
在WPF中创建一个大小为pdf的收件人
问题:
不知道如何在文档中实现跨行。该文档将作为pdf文件创建。
我知道如何创建和实现应该在文档中应用的一些文本和图片,而不是一行。
此文本上方的图片在源代码中没有跨行。同样,我如何在行之间创建一条跨线?
// Fullmetalboy
namespace MediaStore.MenuCheckout
{
/// <summary>
/// Interaction logic for Reciept.xaml
/// </summary>
public partial class Reciept : UserControl
{
private Testt _Testt;
private ManagerCart _myManagerCart;
private ManagerProduct_SaleAndProductQuantity _myManagerProduct_SaleAndProductQuantity;
public Reciept(Testt pTestt, ManagerCart pManagerCart, ManagerProduct_SaleAndProductQuantity pManagerProduct_SaleAndProductQuantity)
{
InitializeComponent();
_Testt = pTestt;
_myManagerCart = pManagerCart;
_myManagerProduct_SaleAndProductQuantity = pManagerProduct_SaleAndProductQuantity;
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
_Testt.Close();
}
private int _header1 = 75;
private int _header2 = 200;
private int _header3 = 280;
private int _header4 = 480;
private int _header5 = 570;
private int _rowY = 60;
private void btnPrint_Click(object sender, RoutedEventArgs e)
{
PrintDialog myPrintDialog = new PrintDialog();
if (myPrintDialog.ShowDialog() == true)
{
// Create a myDrawingVisual for the page.
DrawingVisual myDrawingVisual = new DrawingVisual();
// Get the drawing context
using (DrawingContext myDrawingContext = myDrawingVisual.RenderOpen())
{
// Create headline
FormattedText headArticleNumber = new FormattedText("Article number", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText headQuantity = new FormattedText("Quantity", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText headName = new FormattedText("Name", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText headPriceQTY = new FormattedText("Price/QTY", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText headSum = new FormattedText("Sum", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
Point myPoint1 = new Point(_header1, _rowY);
Point myPoint2 = new Point(_header2, _rowY);
Point myPoint3 = new Point(_header3, _rowY);
Point myPoint4 = new Point(_header4, _rowY);
Point myPoint5 = new Point(_header5, _rowY);
// Draw the content.
myDrawingContext.DrawText(headArticleNumber, myPoint1);
myDrawingContext.DrawText(headQuantity, myPoint2);
myDrawingContext.DrawText(headName, myPoint3);
myDrawingContext.DrawText(headPriceQTY, myPoint4);
myDrawingContext.DrawText(headSum, myPoint5);
foreach(var a in _myManagerCart.GetAllProductFromCartList())
{
FormattedText articleNumber = new FormattedText(a._articleNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText name = new FormattedText(a._name, CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText price = new FormattedText(a._price.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText quantity = new FormattedText(a._quantity.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText sum = new FormattedText(a._sum.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
_rowY = _rowY + 60;
myPoint1 = new Point(_header1, _rowY);
myPoint2 = new Point(_header2, _rowY);
myPoint3 = new Point(_header3, _rowY);
myPoint4 = new Point(_header4, _rowY);
myPoint5 = new Point(_header5, _rowY);
myDrawingContext.DrawText(articleNumber, myPoint1);
myDrawingContext.DrawText(quantity, myPoint2);
myDrawingContext.DrawText(name, myPoint3);
myDrawingContext.DrawText(price, myPoint4);
myDrawingContext.DrawText(sum, myPoint5);
}
SalesTrans mySalesTrans = _myManagerProduct_SaleAndProductQuantity.RetrieveLatestReceiptInfo();
FormattedText totalCost = new FormattedText("Total cost: " + mySalesTrans._totalCost.ToString() + " dollar", CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 14, Brushes.Black);
totalCost.SetFontWeight(FontWeights.Bold);
FormattedText receiptNumber = new FormattedText("Reciept number: " + mySalesTrans._receiptNumber.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
FormattedText salesDate = new FormattedText("Date: " + mySalesTrans._salesDate.ToString(), CultureInfo.CurrentCulture, FlowDirection.LeftToRight,
new Typeface("Verdana"), 12, Brushes.Black);
Point myPoint = new Point(_header5, _rowY + 80);
myDrawingContext.DrawText(totalCost, myPoint);
myPoint = new Point(_header5, _rowY + 120);
myDrawingContext.DrawText(receiptNumber, myPoint);
myPoint = new Point(_header5, _rowY + 160);
myDrawingContext.DrawText(salesDate, myPoint);
int sdf = 23;
}
// Print the myDrawingVisual.
myPrintDialog.PrintVisual(myDrawingVisual, "Receipt");
}
}
}
}
答案 0 :(得分:4)
如果它只是一条水平线来分隔,那么使用
<Separator/>
否则,如果您需要更多控制,那么就有一个Line控件
<Line X1="0" X2="200" Y1="0" Y2="0" Stroke="Black" StrokeThickness="2" />
答案 1 :(得分:1)
这是WPF Overview
中的基本绘图