0

I'm trying to make a receipt where I used panel paint for doing it. But when the content exceeds to the panel size it will need a scroll so the user will see that other text which is not seen. It seems that the panel cant detects even if the content is overflowing so that it does not show any scroll control.

private void panel1_Paint(object sender, PaintEventArgs e)
    {

        

        System.Drawing.Graphics g;
        g = e.Graphics;

        Font font = new Font("Courier New", 8);

        float fontHeight = font.GetHeight();

        int upperY = 20;



        g.DrawString("NCR Gravel and Sand Enteprise", new Font("Courier New", 10), new SolidBrush(Color.Black), 80, upperY);

        upperY = upperY + 15;

        g.DrawString("42 Felix Ave. Brgy San Isidro Cainta Rizal", font, new SolidBrush(Color.Black), 60, upperY);

        upperY = upperY + 15;

        g.DrawString("Cecil R. delas Armas Prop.", font, new SolidBrush(Color.Black), 110, upperY);
        upperY = upperY + 15;

        g.DrawString("Tel Nos: 647-8021/ 296-466/ 492-1773/ 341-7840", font, new SolidBrush(Color.Black), 40, upperY);
        upperY = upperY + 15;

        g.DrawString("Cell #: 0922-853-7840", font, new SolidBrush(Color.Black), 130, upperY);


        upperY = upperY + 15;

        g.DrawString("==============================================", font, new SolidBrush(Color.Black), 40, upperY);


        upperY = upperY + 15;

        string info = "Reference Number:" + Salesrecord_module.refnumber.PadRight(13);
        g.DrawString(info, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Date: " + Salesrecord_module.date, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Customer Name:" + Salesrecord_module.customer, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;


        g.DrawString("Customer Address:" + Salesrecord_module.address, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Cashier:" + Salesrecord_module.assist, font, new SolidBrush(Color.Black), 40, upperY);


        upperY = upperY + 15;




        g.DrawString("==============================================", font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        string top = "x".PadRight(5) + "".PadRight(5) + "Item Name".PadRight(30) + "Price";
        g.DrawString(top, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("----------------------------------------------", font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        for (int i = 0; i < Salesrecord_module.cartcount; i++)
        {
            string item = Salesrecord_module.quantitylist[i].PadRight(5) + Salesrecord_module.Unitlist[i].PadRight(5) + Salesrecord_module.productnamelist[i].PadRight(30) + Salesrecord_module.Pricelist[i];
            g.DrawString(item, font, new SolidBrush(Color.Black), 40, upperY);
            upperY = upperY + 20;
        }



        g.DrawString("----------------------------------------------", font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("SubTotal:".PadRight(40) + Salesrecord_module.sub, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Fee:".PadRight(40) + Salesrecord_module.fee, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Total:".PadRight(40) + Salesrecord_module.total, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("----------------------------------------------", font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Payment:".PadRight(40) + Salesrecord_module.amount, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Change:".PadRight(40) + Salesrecord_module.change, font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;


        g.DrawString("==============================================", font, new SolidBrush(Color.Black), 40, upperY);

        upperY = upperY + 15;

        g.DrawString("Thank you for purchasing", font, new SolidBrush(Color.Black), 120, upperY);
    }

enter image description here

  • You should remove most of your tags. Leave `C#` and add `winforms`. – Flydog57 Nov 16 '21 at 15:55
  • https://stackoverflow.com/questions/730376/how-do-you-add-a-scrollbar-to-a-panel-control-with-many-controls-in-windows-form. I'll admit that it would be much easier if the property was named `ScrollAuto` instead of `AutoScroll`. AutoScroll is not easy to find – Flydog57 Nov 16 '21 at 15:57
  • Does this answer your question? [How do you add a scrollbar to a Panel control with many controls in windows form application?](https://stackoverflow.com/questions/730376/how-do-you-add-a-scrollbar-to-a-panel-control-with-many-controls-in-windows-form) – Flydog57 Nov 16 '21 at 15:57

1 Answers1

0

Use AutoScroll property for the panel like

panel.AutoScroll;
Arun_Raja1
  • 207
  • 1
  • 1