Dmitrij Solov

Dmitrij Solov

  • NA
  • 43
  • 6.6k

multiple classes

Feb 22 2017 1:48 PM
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:
  1. Form1.Designer.cs  
  2.   
  3. namespace WindowsFormsApplication1  
  4. {  
  5.     partial class Form1  
  6.     {  
  7.         ///   
  8.         /// Erforderliche Designervariable.  
  9.         ///   
  10.         private System.ComponentModel.IContainer components = null;  
  11.   
  12.         private void InitializeComponent()  
  13.         {  
  14.             this.pictureBox1 = new System.Windows.Forms.PictureBox();  
  15.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();  
  16.             this.SuspendLayout();  
  17.             //   
  18.             // pictureBox1  
  19.             //   
  20.             this.pictureBox1.Location = new System.Drawing.Point(12, 25);  
  21.             this.pictureBox1.Name = "pictureBox1";  
  22.             this.pictureBox1.Size = new System.Drawing.Size(268, 229);  
  23.             this.pictureBox1.TabIndex = 0;  
  24.             this.pictureBox1.TabStop = false;  
  25.             //   
  26.             // Form1  
  27.             //   
  28.             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);  
  29.             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;  
  30.             this.ClientSize = new System.Drawing.Size(292, 266);  
  31.             this.Controls.Add(this.pictureBox1);  
  32.             this.Name = "Form1";  
  33.             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();  
  34.             this.ResumeLayout(false);  
  35.         }  
  36.         public System.Windows.Forms.PictureBox pictureBox1;  
  37.     }  
  38. }  
  39.   
  40.   
  41. Form1.cs  
  42.   
  43. using System;  
  44. using System.Drawing;  
  45. using System.Windows.Forms;  
  46.   
  47. namespace WindowsFormsApplication1  
  48. {  
  49.     public partial class Form1 : Form  
  50.     {  
  51.         Form2 itsme;  
  52.         public Form1()  
  53.         {  
  54.             InitializeComponent();  
  55.             itsme = new Form2();  
  56.         }  
  57.     }  
  58. }  
  59.   
  60.   
  61. Form2.cs  
  62.   
  63. using System;  
  64. using System.Drawing;  
  65. using System.Windows.Forms;  
  66.   
  67. namespace WindowsFormsApplication1  
  68. {  
  69.     class Form2 : Control  
  70.     {  
  71.         Form1 itsme2;  
  72.         public Form2()  
  73.         {  
  74.             itsme2 = new Form1();  
  75.             itsme2.pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.OnPaint);  
  76.         }  
  77.         private void OnPaint(object sender, PaintEventArgs e)  
  78.         {  
  79.             MessageBox.Show("Hi");  
  80.         }  
  81.     }  

 If you can help me, many thanks.

Answers (1)