Как отобразить в PictureBox линию по координатам
Пытался сделать вот так, но ничего не получилось
Код:
namespace Risovanie_1_
{
public partial class Form1 : Form
{
int[] m_p = new int[5];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Рисуем Линию";
button1.Text = "Рисовать";
}
private void button1_Click(object sender, EventArgs e)
{
m_p[1] = Convert.ToInt32(textBox1.Text);
m_p[2] = Convert.ToInt32(textBox2.Text);
m_p[3] = Convert.ToInt32(textBox3.Text);
m_p[4] = Convert.ToInt32(textBox4.Text);
pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// Рисуем линию
e.Graphics.DrawLine(System.Drawing.Pens.Green, m_p[1], m_p[2], m_p[3], m_p[4]);
}
}
}
{
public partial class Form1 : Form
{
int[] m_p = new int[5];
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Text = "Рисуем Линию";
button1.Text = "Рисовать";
}
private void button1_Click(object sender, EventArgs e)
{
m_p[1] = Convert.ToInt32(textBox1.Text);
m_p[2] = Convert.ToInt32(textBox2.Text);
m_p[3] = Convert.ToInt32(textBox3.Text);
m_p[4] = Convert.ToInt32(textBox4.Text);
pictureBox1.Refresh();
}
private void pictureBox1_Paint(object sender, PaintEventArgs e)
{
// Рисуем линию
e.Graphics.DrawLine(System.Drawing.Pens.Green, m_p[1], m_p[2], m_p[3], m_p[4]);
}
}
}
не получается вывести линию по нажатию кнопки
Код:
// Connect the Paint event of the PictureBox to the event handler method.
pictureBox1.Paint -= new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Paint -= new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
Код:
private void button1_Click(object sender, EventArgs e)
{
// Connect the Paint event of the PictureBox to the event handler method.
pictureBox1.Paint -= new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
m_p[1] = Convert.ToInt32(textBox1.Text);
m_p[2] = Convert.ToInt32(textBox2.Text);
m_p[3] = Convert.ToInt32(textBox3.Text);
m_p[4] = Convert.ToInt32(textBox4.Text);
pictureBox1.Refresh();
}
{
// Connect the Paint event of the PictureBox to the event handler method.
pictureBox1.Paint -= new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
pictureBox1.Paint += new System.Windows.Forms.PaintEventHandler(this.pictureBox1_Paint);
m_p[1] = Convert.ToInt32(textBox1.Text);
m_p[2] = Convert.ToInt32(textBox2.Text);
m_p[3] = Convert.ToInt32(textBox3.Text);
m_p[4] = Convert.ToInt32(textBox4.Text);
pictureBox1.Refresh();
}
Спасибо!