If System.IO.File.Exists(TextBox1.Text) Then
Dim sr As System.IO.StreamReader
sr = New System.IO.StreamReader(TextBox1.Text)
Try
Dim s As String = sr.ReadLine()
Dim line As String()
Dim length As Integer
Dim place As Integer
Dim myImage As Image
myImage = New Bitmap(1000, 100)
Dim myGraphics As Graphics = Graphics.FromImage(myImage)
myGraphics.FillRectangle(Brushes.White, 0, 0, 1000, 100)
Dim p As New Pen(Color.Black)
Do While s <> ""
line = s.Split(",")
length = line(2)
place = CDbl(line(1)) * 900 + 50
Select Case length
Case 1
myGraphics.DrawLine(p, place, 45, place, 55)
Case 2
myGraphics.DrawLine(p, place, 40, place, 60)
Case 3
myGraphics.DrawLine(p, place, 35, place, 65)
Case Else
Throw New Exception("長さとして不適切な値が設定されました。" & vbNewLine & s)
End Select
s = sr.ReadLine()
Loop
myImage.Save(TextBox2.Text, System.Drawing.Imaging.ImageFormat.Gif)
MessageBox.Show("終了しました。")
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
sr.Close()
End Try
Else
MessageBox.Show(TextBox1.Text & "がありません。")
End If
Visual C# .NET
if (System.IO.File.Exists(textBox1.Text))
{
System.IO.StreamReader sr;
sr = new System.IO.StreamReader(textBox1.Text);
try
{
String s = sr.ReadLine();
String[] line;
int length;
int place;
Image myImage;
myImage = new Bitmap(1000,100);
Graphics myGraphics = Graphics.FromImage(myImage);
myGraphics.FillRectangle(Brushes.White,0,0,1000,100);
Pen p = new Pen(Color.Black);
while(s != null)
{
line = s.Split(',');
length = int.Parse(line[2]);
place = (int)(float.Parse(line[1]) * 900 + 50);
switch (length)
{
case 1:
{
myGraphics.DrawLine(p,place,45,place,55);
break;
}
case 2:
{
myGraphics.DrawLine(p,place,40,place,60);
break;
}
case 3:
{
myGraphics.DrawLine(p,place,35,place,65);
break;
}
default:
{
throw new Exception("長さとして不適切な値が設定されました。\n" + s);
}
}
s = sr.ReadLine();
}
myImage.Save(textBox2.Text,System.Drawing.Imaging.ImageFormat.Gif);
MessageBox.Show("終了しました。");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
sr.Close();
}
}
else
{
MessageBox.Show(textBox1.Text + "がありません。");
}
If System.IO.File.Exists(TextBox1.Text) Then
Dim sr As System.IO.StreamReader
sr = New System.IO.StreamReader(TextBox1.Text)
Dim s As String = sr.ReadLine()
Dim line As String()
line = s.Split(",")
sr.Close()
Else
MessageBox.Show(TextBox1.Text & "がありません。")
End If
Visual C# .NET
if (System.IO.File.Exists(textBox1.Text))
{
System.IO.StreamReader sr;
sr = new System.IO.StreamReader(textBox1.Text);
String s = sr.ReadLine();
String[] line;
line = s.Split(',');
sr.Close();
}
else
{
MessageBox.Show(textBox1.Text + "がありません。");
}
Dim myImage As Image
myImage = New Bitmap(1000, 100)
Dim myGraphics As Graphics = Graphics.FromImage(myImage)
myGraphics.FillRectangle(Brushes.White, 0, 0, 1000, 100)
Dim p As New Pen(Color.Black)
Visual C# .NET
Image myImage;
myImage = new Bitmap(1000,100);
Graphics myGraphics = Graphics.FromImage(myImage);
myGraphics.FillRectangle(Brushes.White,0,0,1000,100);
Pen p = new Pen(Color.Black);
Do While s <> ""
line = s.Split(",")
length = line(2)
place = CDbl(line(1)) * 900 + 50
Select Case length
Case 1
myGraphics.DrawLine(p, place, 45, place, 55)
Case 2
myGraphics.DrawLine(p, place, 40, place, 60)
Case 3
myGraphics.DrawLine(p, place, 35, place, 65)
Case Else
Throw New Exception("長さとして不適切な値が設定されました。" & vbNewLine & s)
End Select
s = sr.ReadLine()
Loop
Visual C# .NET
while(s != null)
{
line = s.Split(',');
length = int.Parse(line[2]);
place = (int)(float.Parse(line[1]) * 900 + 50);
switch (length)
{
case 1:
{
myGraphics.DrawLine(p,place,45,place,55);
break;
}
case 2:
{
myGraphics.DrawLine(p,place,40,place,60);
break;
}
case 3:
{
myGraphics.DrawLine(p,place,35,place,65);
break;
}
default:
{
throw new Exception("長さとして不適切な値が設定されました。\n" + s);
}
}
s = sr.ReadLine();
}