質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
Visual Basic .NET

Microsoft Visual Basic .NET (VB.NET)とはオブジェクト志向のプログラム言語です。 Microsoft"s Visual Basic 6 のバージョンアップとしてみることができますが、Microsoft.NET Frameworktによって動かされています。

Visual Studio 2012

Microsoft Visual Studio 2012は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2010の次のバージョンです

Visual Studio 2013

Microsoft Visual Studio 2013は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2012の次のバージョンです

Q&A

解決済

2回答

660閲覧

模擬モバイルオーダーの作成について

xeee

総合スコア2

Visual Basic .NET

Microsoft Visual Basic .NET (VB.NET)とはオブジェクト志向のプログラム言語です。 Microsoft"s Visual Basic 6 のバージョンアップとしてみることができますが、Microsoft.NET Frameworktによって動かされています。

Visual Studio 2012

Microsoft Visual Studio 2012は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2010の次のバージョンです

Visual Studio 2013

Microsoft Visual Studio 2013は、Microsoftによる統合開発環境(IDE)であり、多種多様なプログラミング言語に対応しています。 Visual Studio 2012の次のバージョンです

0グッド

0クリップ

投稿2022/07/14 02:43

visual stadio 2019 visual basic  windows Form アプリケーション を使用しています。

やりたいこと

模擬モバイルオーダーのformアプリケーションを作成しています。form1で食べ物の写真をクリックするとform2が開き、20種類のドリンクから選んでサイズを選択し、form2に作成したButton1をクリックするとform1のlistboxに
商品名/ドリンク名,サイズ を表示するプログラムを作成しています。なお選択にはRadioButtonにはドリンク名がありそれをGroupBoxで囲む。写真の選択ではPictureBoxを使用しています。

質問

form2で選択したRadioButtonをform1のListboxに商品名/ドリンク名,サイズ のように出力する方法が分かりません。下記、form2 のプログラムになります。ご教授お願いします。

visual

1コード 2 3 Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load 4 connectcontroles() 5 connectevents() 6 End Sub 7 8 Private radiobutton() As System.Windows.Forms.RadioButton 9 Private Sub connectcontroles() 10 radiobutton = New System.Windows.Forms.RadioButton(20) {} 11 radiobutton(1) = RadioButton1 12 radiobutton(2) = RadioButton2 13 radiobutton(3) = RadioButton3 14 radiobutton(4) = RadioButton4 15 radiobutton(5) = RadioButton5 16 radiobutton(6) = RadioButton6 17 radiobutton(7) = RadioButton7 18 radiobutton(8) = RadioButton8 19 radiobutton(9) = RadioButton9 20 radiobutton(10) = RadioButton10 21 radiobutton(11) = RadioButton11 22 radiobutton(12) = RadioButton12 23 radiobutton(13) = RadioButton13 24 radiobutton(14) = RadioButton14 25 radiobutton(15) = RadioButton15 26 radiobutton(16) = RadioButton16 27 radiobutton(17) = RadioButton17 28 radiobutton(18) = RadioButton18 29 radiobutton(19) = RadioButton19 30 radiobutton(20) = RadioButton20 31 End Sub 32 33 Private Sub connectevents() 34 For i As Integer = 1 To 20 35 AddHandler radiobutton(i).Click, AddressOf Button1_Click 36 Next 37 End Sub 38 39Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 40 Dim select As String 41 For i As Integer = 1 To 20 42 If RadioButton21.Checked Then 'Sサイズ 43 select = radiobutton(i).Text & "," & RadioButton21.Text 44 ElseIf RadioButton22.Checked Then 'Mサイズ 45 select = radiobutton(i).Text & "," & RadioButton22.Text 46 ElseIf RadioButton23.Checked Then 'Lサイズ 47 select = radiobutton(i).Text & "," & RadioButton23.Text 48 End If 49 Next 50 End Sub

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

KOZ6.0

2022/07/14 13:48 編集

子から親に渡す項目が前の質問とちょっと違うだけです。 何が分からないのでしょう?
guest

回答2

0

ベストアンサー

ドリンク名とサイズの取り出し方がわからないってことでしょうか?
GroupBox1 の中にドリンク名のラジオボタンがあるなら、GroupBox1.Controls からコントロールを列挙して処理します。
サイズのほうは 3 つしかないので普通に分岐すればよいです。
もちろん、別の GroupBox に張り付けてドリンク名と同じように処理してもOK
connectcontroles/connectevents の処理は不要です。

VB

1Public Class Form2 2 3 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click 4 5 _DrinkName = String.Empty 6 For Each con As Control In GroupBox1.Controls 7 Dim rdo As RadioButton = TryCast(con, RadioButton) 8 If rdo IsNot Nothing AndAlso rdo.Checked Then 9 _DrinkName = rdo.Text 10 Exit For 11 End If 12 Next 13 If String.IsNullOrEmpty(_DrinkName) Then 14 MessageBox.Show("ドリンクを選択してください") 15 Return 16 End If 17 18 _DrinkSize = String.Empty 19 If RadioButton21.Checked Then 20 _DrinkSize = RadioButton21.Text 21 ElseIf RadioButton22.Checked Then 22 _DrinkSize = RadioButton22.Text 23 ElseIf RadioButton23.Checked Then 24 _DrinkSize = RadioButton23.Text 25 Else 26 MessageBox.Show("サイズを選択してください") 27 Return 28 End If 29 30 DialogResult = DialogResult.OK 31 End Sub 32 33 Private _DrinkName As String 34 Public ReadOnly Property DrinkName As String 35 Get 36 Return _DrinkName 37 End Get 38 End Property 39 40 Private _DrinkSize As String 41 Public ReadOnly Property DrinkSize As String 42 Get 43 Return _DrinkSize 44 End Get 45 End Property 46 47End Class

あとは Form1 側で DrinkName/DrinkSize を参照して処理してください。

投稿2022/07/14 21:00

KOZ6.0

総合スコア2626

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

xeee

2022/07/15 06:48

何度もすみませんm(_ _)m 前回と今回のでようやく理解できました。本当に助かりましたありがとうございます!
guest

0

form2の方で、商品名/ドリンク名,サイズを返すプロパティを設置しておき、それをform1から読めるようにしておけばよろしい

投稿2022/07/14 03:02

y_waiwai

総合スコア87747

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

xeee

2022/07/14 03:26

回答ありがとうございます。もしよろしければ少しだけ書いていただけないでしょうか?
Zuishin

2022/07/14 04:00

この人は VB.NET を知らないので聞いてもこれが限界です。
xeee

2022/07/14 11:09

そうなんですね。 よければどなたでも大丈夫ですので教えていただきたいですm(_ _)m
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問