Drawing in panel in ASP.net Web Application RRS feed

  • Question

  • User-1084487072 posted

    had a Graph library I was creating in C#. I want to be able to draw lines in the panel. Here is what I was using to create the x and y axis for my library. public class Axis { private PointF _pnt1; private Control _control; public Axis(Control control, PointF pnt1, PointF pnt2) { _control = control; _pnt1 = pnt1; _control.Paint += new PaintEventHandler(this.control_Paint); } private void control_Paint(object sender, PaintEventArgs e) { // Create a graphics object for the _panel. Graphics _g = e.Graphics; Pen pen = new Pen(Color.Black); _g.DrawRectangle(pen, _pnt1,40,40); } } Basicly I was just passing a control(Panel) and drawing a rectangle at give point or any line or polygon. I was wondering if I can create a paint handler for the panel like I did with my classes I created or something simular.

    Thursday, December 18, 2008 4:22 AM


  • User-1136466523 posted


    Generally, you can overwrite the OnPaint event in your custom server control that inherits from Panel class.

    public partial class MyPanel : Panel

        //....... Other codes.

        protected override void OnPaint(PaintEventArgs e)
            // Your logic here.
        // ...... Other codes.


    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, December 22, 2008 10:24 PM