Answer the question
In order to leave comments, you need to log in
How to make lines not overlap shapes (Windows Forms)?
I am making a graph editor, and I ran into one problem - when drawing graph edges, the lines overlap the vertex, since I draw a line from the center to the center of the circle:
Can I somehow make the lines not overlap the circles? Those. like this:
Code (C#):
//рисует вершину графа
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
// проверка флага нажатия
if (!crc_OK)
return;
if (step == 9)
button1.Enabled = false;
Point pointLocation = pictureBox1.PointToClient(Cursor.Position);
if (pictureBox1.Image == null) { pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height); }
var bmp = new Bitmap(pictureBox1.Image);
var g = Graphics.FromImage(bmp);
g.DrawString(step.ToString(), DefaultFont, Brushes.Black, e.X - 5, e.Y - 5);
g.DrawEllipse(Pens.Black, e.X - 10, e.Y - 10, 20, 20);
label1.Text = "Добавлена вершина " + Convert.ToString(step);
pictureBox1.Image = bmp;
masX[step] = e.X;
masY[step] = e.Y;
label3.Text = "X:" + Convert.ToString(masX[step]);
label2.Text = "Y:" + Convert.ToString(masY[step]);
step++;
crc_OK = false;
}
//рисует ребро
private void button2_Click(object sender, EventArgs e)
{
int first_toop = Convert.ToInt16(textBox1.Text);
int second_toop = Convert.ToInt16(textBox2.Text);
if (first_toop > 9 || second_toop > 9)
{
MessageBox.Show("Недопустимое значение.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
}
if (pictureBox1.Image == null) { pictureBox1.Image = new Bitmap(pictureBox1.Width, pictureBox1.Height); }
var bmp = new Bitmap(pictureBox1.Image);
var g = Graphics.FromImage(bmp);
g = Graphics.FromImage(pictureBox1.Image);
g.DrawLine(Pens.DarkGray, masX[first_toop], masY[first_toop], masX[second_toop], masY[second_toop]);
label1.Text = "Добавлено ребро " + Convert.ToString(first_toop) + " - " + Convert.ToString(second_toop);
pictureBox1.Refresh();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question