テキストファイルの読み書き

Readボタンを押すと、テキストファイルを読んでListBoxに表示します。また、ピクチャボックスにも表示します。Writeボタンを押すと、ListBoxの内容を、テキストファイルへ出力します。 フォーム1 Public … “テキストファイルの読み書き” の続きを読む

Readボタンを押すと、テキストファイルを読んでListBoxに表示します。また、ピクチャボックスにも表示します。
Writeボタンを押すと、ListBoxの内容を、テキストファイルへ出力します。

フォーム1

Public Class Form1

ボタン1


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

’ファイルIO用の変数等の宣言

Dim fname As String
Dim ret As DialogResult
Dim TextFile As IO.StreamReader
Dim Line As String
Dim cnt As Integer

’PictureBox1のGraphicsオブジェクトを取得

Dim g As Graphics = PictureBox1.CreateGraphics()
Dim ystr As Integer

‘ダイアログボックスの初期設定

With Me.OpenFileDialog1
 .Title = “ファイルを開く”
 .CheckFileExists = True
  .RestoreDirectory = True
 .Filter = “テキストファイル|.txt;.dat”
 .FileName = “test.txt”
End With

‘ダイアログボックスの表示

ret = Me.OpenFileDialog1.ShowDialog()
If ret = Windows.Forms.DialogResult.OK Then
 fname = Me.OpenFileDialog1.FileName
Else
 fname = “”
End If
If IO.File.Exists(fname) = False Then
 MessageBox.Show(“ファイルが見つかりません。”, “通知”)
 Exit Sub
End If

‘フォントオブジェクトの作成

Dim fnt As New Font(“MS UI Gothic”, 12)
Me.ListBox1.Items.Clear()
TextFile = New IO.StreamReader(fname, System.Text.Encoding.Default)

cnt = 0
Do While True
 Line = TextFile.ReadLine()
 If Line = Nothing Then
  Exit Do
 End If
 Me.ListBox1.Items.Add(Line)
 cnt = cnt + 1

‘文字列を位置(0,0)、青色で表示

 g.DrawString(Line, fnt, Brushes.Blue, 0, ystr)
 ystr = ystr + 20
Loop
TextFile.Close()

‘リソースを開放する

fnt.Dispose()
g.Dispose()
Label2.Text = cnt.ToString


End Sub

ボタン2

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim ret As DialogResult
Dim textfile As IO.StreamWriter
Dim i As Integer
Dim cnt As Integer

 cnt = Integer.Parse(Label2.Text)

‘ダイアログボックスの初期設定

With Me.SaveFileDialog1
 .RestoreDirectory = True
  .OverwritePrompt = True
 .Filter = “すべてのファイル(.)|.|” & “テキストファイル(.txt)|.txt”
 .FileName = “ts.txt”
End With

‘ダイアログボックスの表示

ret = Me.SaveFileDialog1.ShowDialog
If ret = Windows.Forms.DialogResult.OK Then
 Me.Label1.Text =   Me.SaveFileDialog1.FileName

‘現在のファイルのエンコーディングで出力

‘textfile = New IO.StreamWriter(Me.Label1.Text, False, System.Text.Encoding.Default)

‘エンコーディングをShift-JISに指定する

textfile = New IO.StreamWriter(Me.Label1.Text, False, System.Text.Encoding.GetEncoding(\”Shift-JIS\”))

For i = 1 To ListBox1.Items.Count
 ‘Me.ListBox1.s = i – 1
 textfile.WriteLine(Me.ListBox1.Items(i – 1))
Next

textfile.Close()

End If

End Sub

End Class

初秋の山陰線 – The Sunin Line of the early fall

初秋の山陰線 - キハ40 2123 山陰本線長門栗野駅付近、栗野川橋梁。 The cherfull yellow triain of Sunin line has just left at Nagato Kurino … “初秋の山陰線 – The Sunin Line of the early fall” の続きを読む

初秋の山陰線 - キハ40 2123
山陰本線長門栗野駅付近、栗野川橋梁。
The cherfull yellow triain of Sunin line has just left at Nagato Kurino Station.
At Kurino River bridge. Type KIHA40 2123

栗野川橋梁

秋の角島 – Autumn in Tsunoshima

久しぶりに山口県の角島に行ってみた。吹く風はもう涼しくて、秋の気配。しかし、海は相変わらず、エメラルドグリーンに輝いていた。 I went to Tsunoshima of Yamaguchi prefecture af … “秋の角島 – Autumn in Tsunoshima” の続きを読む

久しぶりに山口県の角島に行ってみた。吹く風はもう涼しくて、秋の気配。しかし、海は相変わらず、エメラルドグリーンに輝いていた。
I went to Tsunoshima of Yamaguchi prefecture after a long absence. The wind to blow is already cool.
nAn autumn sign.
However, the sea shined in emerald green as ever.

角島大橋に沈む夕日
The sunset in Tsunoshima Ohashi.

もう誰もいない砂浜。犬の足跡が残る。
Nobody is in the sandy beach. The footprint of the dog is here.

夏のなごり – parting words of summer

もう夏は過ぎたのだろうか。日陰の風はすずやか。 The summer already pass? The wind at the shade looks cool. なごりのひまわり sunflower. 紅葉はまだまだ … “夏のなごり – parting words of summer” の続きを読む

もう夏は過ぎたのだろうか。日陰の風はすずやか。
The summer already pass? The wind at the shade looks cool.
なごりのひまわり sunflower.

紅葉はまだまだ The colored leaves are not yet on.

日陰はすずしい風 The wind at the shade looks cool.

PhotoShopが欲しい

PhotoShopが欲しくなった。もう10年以上前PhotoShop3を購入してから、ずっと使ってきたが、最近アップグレードをしそこなってしまった。それから、最新のソフトは使えなくなったが、GIMPなどでやっていたが、P … “PhotoShopが欲しい” の続きを読む

PhotoShopが欲しくなった。もう10年以上前PhotoShop3を購入してから、ずっと使ってきたが、最近アップグレードをしそこなってしまった。それから、最新のソフトは使えなくなったが、GIMPなどでやっていたが、PhotoShopCS4の体験版を使ってみてやっぱり使いよい。長年使っているせいもあるし、直感的な操作がいい感じだ。アップグレード版が使えないので高くなってしまうが、欲しくなってしまった。

初秋の高原 – The plateau of the early fall

初秋の阿蘇北外輪山。ススキも出てきている。 The Aso north outer rim of a volcanic crater of the early fall. The Japanese pampas gras … “初秋の高原 – The plateau of the early fall” の続きを読む

初秋の阿蘇北外輪山。ススキも出てきている。
The Aso north outer rim of a volcanic crater of the early fall.
The Japanese pampas grass comes out, too.

放牧牛のお尻
The hip of the pasturage cow.

アナログ時計の元

まずは試しに昔もC言語などで作っていたアナログ時計を作り出した。 第一段階の秒針表示ができた。 でもこれだと、スクリーンセーバが起動しても秒針が表示されてしまう。 スクリーンセーバを超越した秒針だ。いいのか悪いのか... … “アナログ時計の元” の続きを読む

まずは試しに昔もC言語などで作っていたアナログ時計を作り出した。
第一段階の秒針表示ができた。
でもこれだと、スクリーンセーバが起動しても秒針が表示されてしまう。
スクリーンセーバを超越した秒針だ。いいのか悪いのか...。

ゆく夏 – Summer was over

最近涼しくなってきた。もう夏は終わりのようだ。暑い夏だが、いざ終わるとなるとなんだかさびしい気持ちにもなる。ゆく夏の最後の風景。 I feel the cool recently. It seems to be alre … “ゆく夏 – Summer was over” の続きを読む

最近涼しくなってきた。もう夏は終わりのようだ。暑い夏だが、いざ終わるとなるとなんだかさびしい気持ちにもなる。ゆく夏の最後の風景。
I feel the cool recently. It seems to be already the end in the summer. It is hot summer, but somewhat becomes a lonely feeling if the summer is over. The scenery of the last of the summer to go.

RSS
Follow by Email