Построение графика y = ax^3+b - C#
Формулировка задачи:
программа которая при нажатии на кнопку выводила бы график y = ax^3+b
Решение задачи: «Построение графика y = ax^3+b»
textual
Листинг программы
class proga : Form
{
public MyForm()
{
this.Text = "....";
this.Size = new Size(1000, 800);
this.Location = new Point(40, 40);
this.BackColor = Color.White;
// 1-я кнопка
Button button1 = new Button();
button1.Text = "Рисовать лицо";
button1.Location = new Point(0, 0);
button1.Size = new Size(200, 30);
button1.BackColor = Color.LightGray;
button1.Click += new System.EventHandler(buttonClick1);
this.Controls.Add(button1);
// 2-я кнопка
Button button2 = new Button();
button2.Text = "Рисовать дом";
button2.Location = new Point(205, 0);
button2.Size = new Size(200, 30);
button2.BackColor = Color.LightGray;
button2.Click += new System.EventHandler(buttonClick2);
this.Controls.Add(button2);
}
void buttonClick1(object o, System.EventArgs e)
{
this.iButton = 1;
this.Invalidate();
}
void buttonClick2(object o, System.EventArgs e)
{
this.iButton = 2;
this.Invalidate();
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
Pen redPen = new Pen(Color.Red, 3);
Pen bluePen = new Pen(Color.Blue, 3);
Brush grayBrush = new SolidBrush(Color.Gray);
Brush blueBrush = new SolidBrush(Color.Blue);
Brush greenBrush = new SolidBrush(Color.Green);
Graphics g = this.CreateGraphics();
if (iButton == 1)
{
g.DrawEllipse(redPen, 150, 90, 200, 200);
g.DrawEllipse(bluePen, 190, 120, 20, 20);
g.DrawEllipse(bluePen, 290, 120, 20, 20);
g.DrawLine(redPen,200, 100, 150, 400);
g.DrawRectangle(bluePen, 200, 200, 60, 60);
//g.FillRectangle(blueBrush, 200, 200, 80, 70);
g.Dispose();
}
if (iButton == 2)
{
//function
g.Dispose();
}
}
[STAThread]
static void Main()
{
MyForm form = new progs();
Application.Run(form);
}
}