H
Hany Metry
Guest
Private Sub PictureBox1_Paint(sender As Object, e As PaintEventArgs) Handles PictureBox1.Paint
If Form1.IrregularEqualSpacing.Checked = True Or Form1.IrregularEqualSpacingToolStripMenuItem.Checked = True Then
NumBarcoor = ListView1.Items.Count
For q = 0 To NumBarcoor - 1
ABco(q) = ListView1.Items(q)
Ser13(q) = CDbl(ListView1.Items(q).Text)
Dia(q) = CDbl(ABco(q).SubItems(1).Text)
coorx1(q) = CDbl(ABco(q).SubItems(2).Text)
coory1(q) = CDbl(ABco(q).SubItems(3).Text)
Next q
Dim vv As Integer
Dim YY As Integer
b = Xmax - Xmin
t = Ymax - Ymin
If (Ymax - Ymin) / (Xmax - Xmin) <= Convert.ToDouble(PictureBox1.Height / PictureBox1.Width) Then
For vv = 0 To Numcoor - 1
Xcoor11(vv) = CInt(PictureBox1.Width * 0.075 + ((Math.Abs(Xmin) + Xcoor(vv)) / Convert.ToDouble(b)) * 0.85 * PictureBox1.Width)
Ycoor11(vv) = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax - Ycoor(vv)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
Next
X3a = CInt(PictureBox1.Width * 0.075 + Math.Abs(Xmin) * 0.85 * PictureBox1.Width / Convert.ToDouble(b) - 0.085 * PictureBox1.Width)
X4a = CInt(PictureBox1.Width * 0.075 + Math.Abs(Xmin) * 0.85 * PictureBox1.Width / Convert.ToDouble(b) + 0.085 * PictureBox1.Width)
Y3a = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax - 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
Y4a = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax + 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
Y5a = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
X5a = CInt(PictureBox1.Width * 0.075 + Math.Abs(Xmin) * 0.85 * PictureBox1.Width / Convert.ToDouble(b))
Else
For vv = 0 To Numcoor - 1
Xcoor11(vv) = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) + Xcoor(vv)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
Ycoor11(vv) = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax - Ycoor(vv)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
Next
X3a = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) - 0.1 * Convert.ToDouble(b)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
X4a = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) + 0.1 * Convert.ToDouble(b)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
Y3a = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax - 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
Y4a = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax + 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
X5a = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
Y5a = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
End If
Dim points1(Numcoor - 1) As Point
For vv = 0 To points1.Length - 1
points1(vv).X = CInt(Xcoor11(vv))
points1(vv).Y = CInt(Ycoor11(vv))
Next
'e.Graphics.DrawPolygon(mpen3, points1)
'e.Graphics.FillPolygon(mbrush1, points)
e.Graphics.DrawLine(mpen, X3a, Y5a, X4a, Y5a)
e.Graphics.DrawLine(mpen, X5a, Y3a, X5a, Y4a)
e.Graphics.DrawString(Str3, DrawFont, Brush2, CInt(X4a + 5), CInt(Y5a - 8))
e.Graphics.DrawString(Str4, DrawFont, Brush2, CInt(X5a - 6), CInt(Y3a - 18))
Dim Str As String = CInt(b) & " x " & CInt(t) & " mm"
Dim Brush As New SolidBrush(Color.Black)
Dim textSize7 As SizeF
textSize7 = G.MeasureString(Str, DrawFont)
XQQ17 = CInt((PictureBox1.Width - CInt(textSize7.Width)) / 2)
e.Graphics.DrawString(Str, DrawFont, Brush, XQQ17, CInt(0.87 * PictureBox1.Height))
If (Ymax - Ymin) / (Xmax - Xmin) <= Convert.ToDouble(PictureBox1.Height / PictureBox1.Width) Then
For YY = 0 To NumBarcoor - 1
Diaf1(YY) = Convert.ToInt32(Dia(YY) * PictureBox1.Width * 0.85 / Convert.ToSingle(b))
coorXf1(YY) = CInt(PictureBox1.Width * 0.075 + ((Math.Abs(Xmin) + coorx1(YY)) / Convert.ToDouble(b)) * 0.85 * PictureBox1.Width) - Diaf1(YY) / 2
coorYf1(YY) = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax - coory1(YY)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b))) - Diaf1(YY) / 2
e.Graphics.FillEllipse(mbrush, CInt(coorXf1(YY)), CInt(coorYf1(YY)), CInt(Diaf1(YY)), CInt(Diaf1(YY)))
e.Graphics.DrawString(CStr(YY + 1), DrawFont6, Brush, CInt(coorXf1(YY) + Diaf1(YY) + 4), CInt(coorYf1(YY) - 10))
Next
Else
For YY = 0 To NumBarcoor - 1
Diaf1(YY) = Convert.ToInt32(Dia(YY) * PictureBox1.Height * 0.85 / Convert.ToSingle(t))
coorXf1(YY) = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) + coorx1(YY)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height) - Diaf1(YY) / 2
coorYf1(YY) = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax - coory1(YY)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t)) - Diaf1(YY) / 2
e.Graphics.FillEllipse(mbrush, CInt(coorXf1(YY)), CInt(coorYf1(YY)), CInt(Diaf1(YY)), CInt(Diaf1(YY)))
e.Graphics.DrawString(CStr(YY + 1), DrawFont6, Brush, CInt(coorXf1(YY) + Diaf1(YY) + 4), CInt(coorYf1(YY) - 10))
Next
End If
Dim Str1 As String = Pr & "% reinf"
Dim textSize1 As SizeF
textSize1 = G.MeasureString(Str1, DrawFont)
XQQ11 = CInt((PictureBox1.Width - textSize1.Width) / 2)
e.Graphics.DrawString(Str1, DrawFont, Brush, XQQ11, CInt(0.92 * PictureBox1.Height))
End If
End Sub
Hi,
The above code does not able to draw in picturebox1_paint and appear cross lines in red color
I have not mistake and the drawings is within the size of picture box1
The drawing with large scale. Is large scale drawing make a problem?
Knowing that Listview1 is in the same form but it is filled from previous form.
I marked the code below as note to see if that code have a problem or not but it is part of the code.
Any how after mark it as note, still I have a problem with any code with e.graphics.
'e.Graphics.DrawPolygon(mpen3, points1)
'e.Graphics.FillPolygon(mbrush1, points)
Kind Regards,
Hany Metry
Continue reading...
If Form1.IrregularEqualSpacing.Checked = True Or Form1.IrregularEqualSpacingToolStripMenuItem.Checked = True Then
NumBarcoor = ListView1.Items.Count
For q = 0 To NumBarcoor - 1
ABco(q) = ListView1.Items(q)
Ser13(q) = CDbl(ListView1.Items(q).Text)
Dia(q) = CDbl(ABco(q).SubItems(1).Text)
coorx1(q) = CDbl(ABco(q).SubItems(2).Text)
coory1(q) = CDbl(ABco(q).SubItems(3).Text)
Next q
Dim vv As Integer
Dim YY As Integer
b = Xmax - Xmin
t = Ymax - Ymin
If (Ymax - Ymin) / (Xmax - Xmin) <= Convert.ToDouble(PictureBox1.Height / PictureBox1.Width) Then
For vv = 0 To Numcoor - 1
Xcoor11(vv) = CInt(PictureBox1.Width * 0.075 + ((Math.Abs(Xmin) + Xcoor(vv)) / Convert.ToDouble(b)) * 0.85 * PictureBox1.Width)
Ycoor11(vv) = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax - Ycoor(vv)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
Next
X3a = CInt(PictureBox1.Width * 0.075 + Math.Abs(Xmin) * 0.85 * PictureBox1.Width / Convert.ToDouble(b) - 0.085 * PictureBox1.Width)
X4a = CInt(PictureBox1.Width * 0.075 + Math.Abs(Xmin) * 0.85 * PictureBox1.Width / Convert.ToDouble(b) + 0.085 * PictureBox1.Width)
Y3a = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax - 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
Y4a = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax + 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
Y5a = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b)))
X5a = CInt(PictureBox1.Width * 0.075 + Math.Abs(Xmin) * 0.85 * PictureBox1.Width / Convert.ToDouble(b))
Else
For vv = 0 To Numcoor - 1
Xcoor11(vv) = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) + Xcoor(vv)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
Ycoor11(vv) = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax - Ycoor(vv)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
Next
X3a = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) - 0.1 * Convert.ToDouble(b)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
X4a = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) + 0.1 * Convert.ToDouble(b)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
Y3a = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax - 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
Y4a = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax + 0.1 * Convert.ToDouble(t)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
X5a = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height)
Y5a = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax) * 0.85 * PictureBox1.Height / Convert.ToDouble(t))
End If
Dim points1(Numcoor - 1) As Point
For vv = 0 To points1.Length - 1
points1(vv).X = CInt(Xcoor11(vv))
points1(vv).Y = CInt(Ycoor11(vv))
Next
'e.Graphics.DrawPolygon(mpen3, points1)
'e.Graphics.FillPolygon(mbrush1, points)
e.Graphics.DrawLine(mpen, X3a, Y5a, X4a, Y5a)
e.Graphics.DrawLine(mpen, X5a, Y3a, X5a, Y4a)
e.Graphics.DrawString(Str3, DrawFont, Brush2, CInt(X4a + 5), CInt(Y5a - 8))
e.Graphics.DrawString(Str4, DrawFont, Brush2, CInt(X5a - 6), CInt(Y3a - 18))
Dim Str As String = CInt(b) & " x " & CInt(t) & " mm"
Dim Brush As New SolidBrush(Color.Black)
Dim textSize7 As SizeF
textSize7 = G.MeasureString(Str, DrawFont)
XQQ17 = CInt((PictureBox1.Width - CInt(textSize7.Width)) / 2)
e.Graphics.DrawString(Str, DrawFont, Brush, XQQ17, CInt(0.87 * PictureBox1.Height))
If (Ymax - Ymin) / (Xmax - Xmin) <= Convert.ToDouble(PictureBox1.Height / PictureBox1.Width) Then
For YY = 0 To NumBarcoor - 1
Diaf1(YY) = Convert.ToInt32(Dia(YY) * PictureBox1.Width * 0.85 / Convert.ToSingle(b))
coorXf1(YY) = CInt(PictureBox1.Width * 0.075 + ((Math.Abs(Xmin) + coorx1(YY)) / Convert.ToDouble(b)) * 0.85 * PictureBox1.Width) - Diaf1(YY) / 2
coorYf1(YY) = CInt(PictureBox1.Height * 0.44 - Convert.ToDouble(t) * 0.85 * PictureBox1.Width / (2 * Convert.ToDouble(b)) + (Ymax - coory1(YY)) * 0.85 * PictureBox1.Width / (Convert.ToDouble(b))) - Diaf1(YY) / 2
e.Graphics.FillEllipse(mbrush, CInt(coorXf1(YY)), CInt(coorYf1(YY)), CInt(Diaf1(YY)), CInt(Diaf1(YY)))
e.Graphics.DrawString(CStr(YY + 1), DrawFont6, Brush, CInt(coorXf1(YY) + Diaf1(YY) + 4), CInt(coorYf1(YY) - 10))
Next
Else
For YY = 0 To NumBarcoor - 1
Diaf1(YY) = Convert.ToInt32(Dia(YY) * PictureBox1.Height * 0.85 / Convert.ToSingle(t))
coorXf1(YY) = CInt(0.5 * PictureBox1.Width + ((-Convert.ToDouble(b) / 2 + Math.Abs(Xmin) + coorx1(YY)) / Convert.ToDouble(t)) * 0.85 * PictureBox1.Height) - Diaf1(YY) / 2
coorYf1(YY) = CInt(PictureBox1.Height * 0.44 + (-Convert.ToDouble(t) / 2 + Ymax - coory1(YY)) * 0.85 * PictureBox1.Height / Convert.ToDouble(t)) - Diaf1(YY) / 2
e.Graphics.FillEllipse(mbrush, CInt(coorXf1(YY)), CInt(coorYf1(YY)), CInt(Diaf1(YY)), CInt(Diaf1(YY)))
e.Graphics.DrawString(CStr(YY + 1), DrawFont6, Brush, CInt(coorXf1(YY) + Diaf1(YY) + 4), CInt(coorYf1(YY) - 10))
Next
End If
Dim Str1 As String = Pr & "% reinf"
Dim textSize1 As SizeF
textSize1 = G.MeasureString(Str1, DrawFont)
XQQ11 = CInt((PictureBox1.Width - textSize1.Width) / 2)
e.Graphics.DrawString(Str1, DrawFont, Brush, XQQ11, CInt(0.92 * PictureBox1.Height))
End If
End Sub
Hi,
The above code does not able to draw in picturebox1_paint and appear cross lines in red color
I have not mistake and the drawings is within the size of picture box1
The drawing with large scale. Is large scale drawing make a problem?
Knowing that Listview1 is in the same form but it is filled from previous form.
I marked the code below as note to see if that code have a problem or not but it is part of the code.
Any how after mark it as note, still I have a problem with any code with e.graphics.
'e.Graphics.DrawPolygon(mpen3, points1)
'e.Graphics.FillPolygon(mbrush1, points)
Kind Regards,
Hany Metry
Continue reading...