[Visual Basic] Overloads Public Function ShowDialog() As DialogResult [指定した所有者を持つモーダル ダイアログとしてフォームを表示します。
[Visual Basic] Overloads Public Function ShowDialog(IWin32Window) As DialogResult 使用例
[Visual Basic] Public Sub ShowMyDialogBox() Dim testDialog As New Form2()
'Show testDialog as a modal dialog and determine if DialogResult = OK. If testDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK Then Read the contents of testDialog's TextBox. txtResult.Text = testDialog.TextBox1.Text Else txtResult.Text = "Cancelled" End If testDialog.Dispose() End Sub 'ShowMyDialogBox
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim x As New Form2 If x.ShowDialog() = DialogResult.OK Then Debug.Write("OK") Else Debug.Write("CAN") End If End Sub
MSってなんで持って回ったような頓珍漢な例をかくんだろね。
817 名前:779 [04/12/01 08:37:56]
林センセの場合もそうですが、、、 (日経BPソフトプレスの全サンプルもそうですからしかたありませんが) 先生方こういうサンプルが多いんですがだめですよ。 戻り値がある場合は必ず戻り値を見るようにしましょうね。 If CommonDialog1.filename <> "" Then とくにこの判別のしかたはまずいですよ。誰かの本みて真似してるんでしょ。
■サンプル(悪) Private Sub Command1_Click() '***** ファイル名の取得 ***** With CommonDialog1 .filename = "" .Filter = "Data(*.dat)|*.dat" .ShowOpen End With '***** ファイルのオープンと表示 ***** If CommonDialog1.filename <> "" Then Open CommonDialog1.filename For Input As #1 Do Until EOF(1) Line Input #1, a$ Print a$ Loop Else MsgBox "キャンセルされました。", , "メッセージ" End If End Sub
818 名前:779 [04/12/01 08:38:17]
■改良サンプル try cd = CommonDialog1 cd.filename = "":cd.Filter = "Data(*.dat)|*.dat" if cd.ShowOpen = vbOk then fname = CommonDialog1.filename If fname <> "" Then '***** ファイルのオープンと表示 ***** End If end if catch ex as Exception msgbox ex.discription end try
819 名前:779 [04/12/01 09:20:05]
Public Sub ShowMyDialogBox() Dim testDialog As New Form2() .... testDialog.Dispose() End Sub
Public Class Form1 Structure ViewPort Dim Xgw As Integer Dim Ygw As Integer Dim Xgc As Integer Dim Ygc As Integer Dim Xvw As Double Dim Yvw As Double Dim Xvc As Double Dim Yvc As Double End Structure Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim c As Color Dim vp As ViewPort c = Color.FromArgb(255, 255, 0, 0) ↓ここから vp.Xgw = 000 vp.Ygw = 000 vp.Xgc = vp.Xgw / 2 vp.Ygc = vp.Ygw / 2 vp.Xvw = 000 vp.Yvw = 000 vp.Xvc = 000 vp.Yvc = 000 DrawPoint(000, 000, c) DrawPointScs(000, 000, c, vp) DrawPointWcs(000, 000, c, vp) DrawLine(000, 000, 000, 000, c) DrawLineScs(000, 000, 000, 000, c, vp) DrawLineWcs(000, 000, 000, 000, c, vp) ↑ここまで の数値入力がわかりません。 End Sub
861 名前:777 mailto:sage [04/12/02 11:32:43]
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click PictureBox1.Refresh() End Sub Private Sub DrawPoint(ByVal x As Integer, ByVal y As Integer, ByVal c As Color) Dim g As Graphics Dim p As Pen g = PictureBox1.CreateGraphics p = New Pen(c) g.DrawEllipse(p, x, y, 1, 1) End Sub
862 名前:777 mailto:sage [04/12/02 11:35:48]
Private Sub DrawLine(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal c As Color) Dim x As Integer Dim y As Integer Dim a As Double If x1 = x2 Then x = x1 If y1 <= y2 Then For y = y1 To y2 Step 1 DrawPoint(x, y, c) Next Else For y = y2 To y1 Step 1 DrawPoint(x, y, c) Next End If
863 名前:777 mailto:sage [04/12/02 11:36:15]
Else a = CDbl(y2 - y1) / CDbl(x2 - x1) If Math.Abs(a) <= 1 Then If x1 < x2 Then For x = x1 To x2 Step 1 y = CInt(a * CDbl(x - x1) + CDbl(y1)) DrawPoint(x, y, c) Next Else For x = x2 To x1 Step 1 y = CInt(a * CDbl(x - x1) + CDbl(y1)) DrawPoint(x, y, c) Next End If Else If y1 < y2 Then For y = y1 To y2 Step 1 x = CInt(1.0 / a * CDbl(y - y1) + CDbl(x1)) DrawPoint(x, y, c) Next Else For y = y2 To y1 Step 1 x = CInt(1.0 / a * CDbl(y - y1) + CDbl(x1)) DrawPoint(x, y, c) Next End If End If End If End Sub
864 名前:777 mailto:sage [04/12/02 11:36:40]
Private Sub DrawPointScs(ByVal x As Integer, ByVal y As Integer, ByVal c As Color, ByVal vp As ViewPort) Dim Xg As Integer Dim Yg As Integer Xg = x + vp.Xgc Yg = -y + vp.Ygc DrawPoint(Xg, Yg, c) End Sub
Private Sub DrawPointWcs(ByVal x As Double, ByVal y As Double, ByVal c As Color, ByVal vp As ViewPort) Dim Xv As Double Dim Yv As Double Dim Xs As Integer Dim Ys As Integer Xv = x - vp.Xvc Yv = y - vp.Yvc Xs = CInt(Xv * vp.Xgw / vp.Xvw) Ys = CInt(Yv * vp.Ygw / vp.Yvw) DrawPointScs(Xs, Ys, c, vp) End Sub
865 名前:777 mailto:sage [04/12/02 11:37:01]
Private Sub DrawLineScs(ByVal x1 As Integer, ByVal y1 As Integer, ByVal x2 As Integer, ByVal y2 As Integer, ByVal c As Color, ByVal vp As ViewPort) Dim Xg1 As Integer Dim Yg1 As Integer Dim Xg2 As Integer Dim Yg2 As Integer Xg1 = x1 + vp.Xgc Yg1 = -y1 + vp.Xgc Xg2 = x2 + vp.Xgc Yg2 = y2 + vp.Ygc DrawLine(Xg1, Yg1, Xg2, Yg2, c) End Sub Private Sub DrawLineWcs(ByVal x1 As Double, ByVal y1 As Double, ByVal x2 As Double, ByVal y2 As Double, ByVal c As Color, ByVal vp As ViewPort) Dim Xv1 As Double Dim Yv1 As Double Dim Xv2 As Double Dim Yv2 As Double Dim Xs1 As Double Dim Ys1 As Double Dim Xs2 As Double Dim Ys2 As Double Xv1 = x1 - vp.Xvc Yv1 = y1 - vp.Yvc Xv2 = x2 - vp.Xvc Yv2 = y2 - vp.Xvc Xs1 = CInt(Xv1 * vp.Xgw / vp.Xvw) Ys1 = CInt(Yv1 * vp.Ygw / vp.Yvw) Xs2 = CInt(Xv2 * vp.Xgw / vp.Xvw) Ys2 = CInt(Yv2 * vp.Ygw / vp.Yvw) DrawLineScs(Xs1, Ys1, Xs2, Ys2, c, vp) End Sub End Class
Private Sub combobox1_SelectedIndexChanged(・・・・・・) If combobox2.SelectionValue ="" then combobbox1.Enabled = False End If End Sub のようにすると「演算子が、型 'DBNull' および 文字列 "System.DBNull" に対して有効ではありません。」 になってしまいます。 「If combobox2.SelectionValue ="" then」 の部分を「If combobox2.SelectionValue = null then」 にしても同じでした。。。このような場合どのようにしてNULL値を取得するのでしょうか? よろしくお願いします。
すいません(T_T)コンボボックスの「1」と「2」が間違ってました。 Private Sub combobox1_SelectedIndexChanged(・・・・・・) If combobox1.SelectionValue ="" then combobbox2.Enabled = False End If End Sub
Dim aaa As Object Dim bbb As Boolean aaa = ComboBox1.SelectedValue bbb = IsDBNull(aaa) If bbb = True Then TextBox1.Text = "self" Else TextBox1.Enabled = True TextBox1.Text = ComboBox1.SelectedValue End If End Sub