开发者

How to create a line in WPF

开发者 https://www.devze.com 2023-03-26 13:07 出处:网络
Goal: Create a reciept in a4 size pdf in WPF problem: Don\'t know how to implement an across line in the document. That document will be created as a pdf file.

Goal:

Create a reciept in a4 size pdf in WPF

problem:

Don't know how to implement an across line in the document. That document will be created as a pdf file.

I know how to create and implement some text and picture that should be applied in the document but not a line.

How to create a line in WPF

This picture above this text do not have a across line in the sourcecode. Again, how do i create an across line between rows?

// 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);  

                        Formatted开发者_如何学JAVAText 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");
            }


        }


    }
}


If it is just a horizontal line to separate things then use

<Separator/>

Otherwise if you need more control then there is a Line control

<Line X1="0" X2="200" Y1="0"  Y2="0" Stroke="Black" StrokeThickness="2" />


Here's the Basic Drawing in WPF Overview

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号