0

recently i tried draw a rectangle on win from and this is the code

namespace GDI1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            //i want do the below lines for specific tab page :)

            this.DoubleBuffered = true;
            this.Paint += new PaintEventHandler(Form1_Paint);
        }

        private void Form1_Paint(object sender , System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.FillRectangle(Brushes.Green, new Rectangle(50, 50, 530, 40));

        }
    }
}

now i want do the same thing but on specific tag page .... how can i set the codes for tabcontrol.

what i tried what i want

Rouzbeh Zarandi
  • 1,047
  • 2
  • 16
  • 34
  • Use the paint event for TabPage2. – LarsTech Jun 27 '17 at 17:42
  • private void tabPage2_Click(object sender, EventArgs e) { this.DoubleBuffered = true; this.Paint += new PaintEventHandler( tabPage2_Paint); } ...here i get problem ..... like this? – Rouzbeh Zarandi Jun 27 '17 at 17:44
  • 2
    Not in the click event. In your code above, change `this.Paint += new PaintEventHandler(Form1_Paint);` to `tabPage2.Paint += tabPage2_Paint;` Copy your Form1_Paint method and change it to tabPage2_Paint. – LarsTech Jun 27 '17 at 17:46
  • 2
    ... and move those lines of code from the load event to the constructor. Load event is only used when the dimension of the form is important to know. – LarsTech Jun 27 '17 at 17:52
  • thank you.... good tip for me <3 – Rouzbeh Zarandi Jun 27 '17 at 17:53

0 Answers0