Hello,
I want to build a multiple class aplication containing a picturebox.
I want to call OnPaint-Event in this application.
During the debugging-execution I get the error-message "StackOverflowException was not managed"(Form1.Designer.cs; this.ResumeLayout(false)).
my code is the following:
- Form1.Designer.cs
-
- namespace WindowsFormsApplication1
- {
- partial class Form1
- {
-
-
-
- private System.ComponentModel.IContainer components = null;
-
- private void InitializeComponent()
- {
- this.pictureBox1 = new System.Windows.Forms.PictureBox();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
- this.SuspendLayout();
-
-
-
- this.pictureBox1.Location = new System.Drawing.Point(12, 25);
- this.pictureBox1.Name = "pictureBox1";
- this.pictureBox1.Size = new System.Drawing.Size(268, 229);
- this.pictureBox1.TabIndex = 0;
- this.pictureBox1.TabStop = false;
-
-
-
- this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(292, 266);
- this.Controls.Add(this.pictureBox1);
- this.Name = "Form1";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
- this.ResumeLayout(false);
- }
- public System.Windows.Forms.PictureBox pictureBox1;
- }
- }
-
-
- Form1.cs
-
- using System;
- using System.Drawing;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- Form2 itsme;
- public Form1()
- {
- InitializeComponent();
- itsme = new Form2();
- }
- }
- }
-
-
- Form2.cs
-
- using System;
- using System.Drawing;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- class Form2 : Control
- {
- Form1 itsme2;
- public Form2()
- {
- itsme2 = new Form1();
- itsme2.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);
- }
- private void OnPaint(object sender, PaintEventArgs e)
- {
- MessageBox.Show("Hi");
- }
- }
- }
If you can help me, many thanks.