teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

ソースを追加しました

2015/06/25 11:09

投稿

Mogami_Tsuchika
Mogami_Tsuchika

スコア47

title CHANGED
File without changes
body CHANGED
@@ -9,17 +9,74 @@
9
9
  Fnameはファイルのパス
10
10
  AzukiControl1はテキストボックスです。
11
11
  ```lang-<VB.net>
12
+ Public Class Form2
13
+ Dim Fname As String
14
+ Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
15
+ Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) 'マイドキュメントのパス
16
+ Dim sr As New System.IO.StreamReader(path + "\MyConStudio\AppDate\text.txt", _
17
+ System.Text.Encoding.GetEncoding("shift_jis"))
18
+ '内容をすべて読み込む
19
+ Fname = sr.ReadToEnd()
20
+ '閉じる
21
+ sr.Close()
22
+
23
+ Dim FL As New System.IO.StreamReader(Fname, _
24
+ System.Text.Encoding.GetEncoding("shift_jis"))
25
+ '内容をすべて読み込む
26
+ AzukiControl1.Text = FL.ReadToEnd()
27
+ '閉じる
28
+ FL.Close()
29
+ Me.Text = Fname
30
+ End Sub
31
+
32
+ Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
33
+ Me.Save()
34
+
35
+ End Sub
12
- Public Sub Save()
36
+ Public Sub Save()
13
37
  Dim sw As New System.IO.StreamWriter(Fname, _
14
38
  False, _
15
39
  System.Text.Encoding.GetEncoding("shift_jis"))
16
40
  'TextBox1.Textの内容を書き込む
17
- sw.Write(AzukiControl1.Text)
41
+ sw.Write(Me.AzukiControl1.Text)
18
42
  '閉じる
19
43
  sw.Close()
20
44
  End Sub
45
+ End Class
21
46
  ```
22
47
  MDI親フォーム(Form1)のコード
23
48
  ```lang-<VB.net>
24
49
  Form2.Save()
50
+ ```
51
+ MDI子フォームの呼び出し
52
+ ```lang-<VB.net>
53
+ 'main.mcs表示
54
+
55
+ Dim sw As New System.IO.StreamWriter(path + "\MyConStudio\AppDate\text.txt", _
56
+ False, _
57
+ System.Text.Encoding.GetEncoding("shift_jis"))
58
+
59
+ sw.Write(Pname + "main.mcs")
60
+ '閉じる
61
+ sw.Close()
62
+ Dim NewMDIChild As New Form2()
63
+ 'Set the Parent Form of the Child window.
64
+ NewMDIChild.MdiParent = Me
65
+ 'Display the new form.
66
+ NewMDIChild.Show()
67
+
68
+
69
+ 'AboutProject.txt表示
70
+ Dim sw1 As New System.IO.StreamWriter(path + "\MyConStudio\AppDate\text.txt", _
71
+ False, _
72
+ System.Text.Encoding.GetEncoding("shift_jis"))
73
+
74
+ sw1.Write(Pname + "AboutProject.txt")
75
+ '閉じる
76
+ sw1.Close()
77
+ Dim NewMDIChild2 As New Form2()
78
+ 'Set the Parent Form of the Child window.
79
+ NewMDIChild2.MdiParent = Me
80
+ 'Display the new form.
81
+ NewMDIChild2.Show()
25
82
  ```