I'm newbie to C#. Trying to call method from inner class and got: An object reference is required for the non-static field, method, or property
. Looks like there is something wrong with panel1.Size = new System.Drawing.Size(100, 100);
?
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
public class MainForm : Form
{
public class SomeClass : PictureBox
{
public SomeClass()
{
this.MouseDown += new System.Windows.Forms.MouseEventHandler(this.mouseDown);
}
public void mouseDown(object sender, MouseEventArgs e)
{
resizePanel();
}
}
Panel panel1 = new Panel();
SomeClass someObject = new SomeClass();
public MainForm()
{
this.Controls.Add(this.panel1);
this.panel1.Size = new System.Drawing.Size(200, 200);
this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.draw);
this.panel1.Controls.Add(this.someObject);
this.someObject.Location = new System.Drawing.Point(0, 0);
}
static void resizePanel() {
panel1.Size = new System.Drawing.Size(100, 100);
}
public void draw(object sender, PaintEventArgs e)
{
e.Graphics.FillRectangle(Brushes.Red, 0, 0, 200, 200);
}
public static void Main()
{
Application.Run(new MainForm());
}
}