質問です。
現在MDIをつかったソフトを作っているのですが
子フォーム(Form2)のテキストボックスの内容を保存するために次のようなプログラムを書いたのですが、
[値をNullにすることはできません。]
と出てきてしまいます。
どうすればいいでしょうか?
Form2に書いてあるSAVEのコード
Fnameはファイルのパス
AzukiControl1はテキストボックスです。
lang
1Public Class Form2 2 Dim Fname As String 3 Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 4 Dim path As String = System.Environment.GetFolderPath(Environment.SpecialFolder.Personal) 'マイドキュメントのパス 5 Dim sr As New System.IO.StreamReader(path + "\MyConStudio\AppDate\text.txt", _ 6 System.Text.Encoding.GetEncoding("shift_jis")) 7 '内容をすべて読み込む 8 Fname = sr.ReadToEnd() 9 '閉じる 10 sr.Close() 11 12 Dim FL As New System.IO.StreamReader(Fname, _ 13 System.Text.Encoding.GetEncoding("shift_jis")) 14 '内容をすべて読み込む 15 AzukiControl1.Text = FL.ReadToEnd() 16 '閉じる 17 FL.Close() 18 Me.Text = Fname 19 End Sub 20 21 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 22 Me.Save() 23 24 End Sub 25 Public Sub Save() 26 Dim sw As New System.IO.StreamWriter(Fname, _ 27 False, _ 28 System.Text.Encoding.GetEncoding("shift_jis")) 29 'TextBox1.Textの内容を書き込む 30 sw.Write(Me.AzukiControl1.Text) 31 '閉じる 32 sw.Close() 33 End Sub 34End Class
MDI親フォーム(Form1)のコード
```lang-<VB.net>
Form2.Save()
MDI子フォームの呼び出し ```lang-<VB.net> 'main.mcs表示 Dim sw As New System.IO.StreamWriter(path + "\MyConStudio\AppDate\text.txt", _ False, _ System.Text.Encoding.GetEncoding("shift_jis")) sw.Write(Pname + "main.mcs") '閉じる sw.Close() Dim NewMDIChild As New Form2() 'Set the Parent Form of the Child window. NewMDIChild.MdiParent = Me 'Display the new form. NewMDIChild.Show() 'AboutProject.txt表示 Dim sw1 As New System.IO.StreamWriter(path + "\MyConStudio\AppDate\text.txt", _ False, _ System.Text.Encoding.GetEncoding("shift_jis")) sw1.Write(Pname + "AboutProject.txt") '閉じる sw1.Close() Dim NewMDIChild2 As New Form2() 'Set the Parent Form of the Child window. NewMDIChild2.MdiParent = Me 'Display the new form. NewMDIChild2.Show()
2つ質問があります。
①FnameはForm2メンバ変数ですか?実際はSaveメソッドの引数だったりします?
②親フォームからForm2を起動する処理を提示してください。気になっているのはForm2っていうインスタンス名なのかなと。
回答3件
あなたの回答
tips
プレビュー