tagCANDY CGI VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
VBレスキュー(花ちゃん) の Visual Basic 2010 用 掲示板(VB.NET 掲示板)
[ツリー表示へ]  [ワード検索]  [Home]

タイトル AcceptButton / CancelButton プロパティの利用
投稿日: 2008/09/05(Fri) 11:50
投稿者魔界の仮面弁士
> Button.Clickイベントコードを書かなくても良いのかな。

その通り。戻り値として DialogResult を返すだけでよいのなら、
OK/Cancel ボタンのコードは不要です。


以下、VBC.EXE  Version 9.0.21022.8 でコンパイルして動作確認。

'----
' ソースファイル名
' C:\a.vb
'----
' コンパイル方法
' C:\WINDOWS\Microsoft.NET\Framework\v3.5\VBC.EXE /t:winexe /out:C:\a.exe C:\a.vb
'----
Imports System
Imports System.Windows.Forms
Imports DR = System.Windows.Forms.DialogResult
Class Sample : Inherits Form
 Shared Sub Main()
  Application.Run(New Sample())
 End Sub

 WithEvents B As New Button() With { .Text = "テスト" }
 Private Sub New()
  Controls.Add(B)
 End Sub

 Sub B_Click() Handles B.Click
  Dim ret As DR = TextMsgBox.Show("タイトル")

  MsgBox(ret.ToString() & "が押されました。")
 End Sub
End Class


Public Class TextMsgBox : Inherits Form
 Private Sub New()
  Dim btnOK As New Button() With { .Text = "OK", .DialogResult = DR.OK }
  Controls.Add(btnOK)
  Dim btnCancel As New Button() With { .Text = "Cancel", .DialogResult = DR.Cancel, .Left = btnOK.Right + 3 }
  Controls.Add(btnCancel)
  CancelButton = btnCancel
  AcceptButton = btnOK
 End Sub

 Public Shared Overloads Function Show(ByVal text As String) As DialogResult
  Using F As New TextMsgBox()
   F.Text = text
   Return F.ShowDialog()
  End Using
 End Function

End Class

- 関連一覧ツリー をクリックするとツリー全体を一括表示します)

古いスレッドにレスはつけられません。