Как создать строку в WPF - PullRequest
       9

Как создать строку в WPF

0 голосов
/ 06 августа 2011

Цель:
Создать квитанцию ​​в формате p4 в формате WPF

проблема:
Не знаете, как реализовать сквозную строку в документе.Этот документ будет создан в виде файла PDF.

Я знаю, как создать и реализовать некоторый текст и изображение, которые должны применяться в документе, но не в виде строки.

enter image description here Это изображениевыше этого текста нет сквозной строки в исходном коде.Опять же, как мне создать поперечную линию между строками?

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


        }


    }
}

Ответы [ 2 ]

4 голосов
/ 06 августа 2011

Если это просто горизонтальная линия для разделения вещей, используйте

<Separator/>

В противном случае, если вам нужно больше контроля, тогда есть элемент управления Line

<Line X1="0" X2="200" Y1="0"  Y2="0" Stroke="Black" StrokeThickness="2" />
1 голос
/ 06 августа 2011

Вот базовый чертеж в WPF Обзор

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...