我有这个程序,我有10个图片框,如果form1的文本框与form3文本框中的文本相同,它将显示一个复选标记的图片,否则它将显示十字标记的图片。但是当我输入答案时,它显示结果它只显示一个图片框和一个图片框,并始终显示一个复选标记,这不是为了程序的目的和其他九个图片框丢失..(我已经检查了图片框,它是启用和可见的属性都设置为TRUE)在先发制人的帮助下,我希望你能帮我解决这个问题。
Imports System.Convert
Imports System.IO
Imports System.Windows.Forms.PictureBox
Imports System.Drawing.Image
Public Class Form4
Inherits System.Windows.Forms.Form
Public frm1 As Form1
Private frm2 As Form2
Public frm3 As Form3
Private frm4 As Form4
Private frm5 As Form5
Private Form5 As Form5
Private Sub Form4_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim lbl3 As Integer
lbl3 = CInt(lbl3)
Me.Visible = False
End Sub
Public Sub New1(ByVal callerInstance As Form1)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm1 = callerInstance
End Sub
Public Sub New5(ByVal callerInstance As Form2)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm2 = callerInstance
End Sub
Public Sub New4(ByVal callerInstance As Form3)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm3 = callerInstance
End Sub
Public Sub New3(ByVal callerInstance As Form4)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm4 = callerInstance
End Sub
Public Sub New5(ByVal callerInstance As Form5)
' Call required if you add your constructor manually
InitializeComponent()
' save the instance of the Me variable passed to this constructor
frm5 = callerInstance
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim frm1 As Form1 = Form1
Dim frm2 As Form2 = Form2
Dim frm3 As Form3 = Form3
Dim frm5 As Form5 = Form5
If frm5 Is Nothing Then
frm5 = New Form5(Me)
AddHandler frm2.FormClosed, AddressOf Me.Form5HasBeenClosed
frm5.Label21.Text = frm1.TextBox1.Text
frm5.Label21.ForeColor = Color.Black
frm5.Label22.Text = frm1.TextBox2.Text
frm5.Label22.ForeColor = Color.Black
frm5.Label23.Text = frm1.TextBox3.Text
frm5.Label23.ForeColor = Color.Black
frm5.Label24.Text = frm1.TextBox4.Text
frm5.Label24.ForeColor = Color.Black
frm5.Label25.Text = frm1.TextBox5.Text
frm5.Label25.ForeColor = Color.Black
frm5.Label26.Text = frm1.TextBox6.Text
frm5.Label26.ForeColor = Color.Black
frm5.Label27.Text = frm1.TextBox7.Text
frm5.Label27.ForeColor = Color.Black
frm2.Label28.Text = frm1.TextBox8.Text
frm2.Label28.ForeColor = Color.Black
frm5.Label29.Text = frm1.TextBox9.Text
frm5.Label29.ForeColor = Color.Black
frm5.Label30.Text = frm1.TextBox10.Text
frm5.Label30.ForeColor = Color.Black
frm5.Label31.Text = frm1.TextBox11.Text
frm5.Label31.ForeColor = Color.Black
frm5.Label32.Text = frm1.TextBox12.Text
frm5.Label32.ForeColor = Color.Black
frm5.Label33.Text = frm1.TextBox13.Text
frm5.Label33.ForeColor = Color.Black
frm5.Label34.Text = frm1.TextBox14.Text
frm5.Label34.ForeColor = Color.Black
frm5.Label35.Text = frm1.TextBox15.Text
frm5.Label35.ForeColor = Color.Black
frm5.Label36.Text = frm1.TextBox16.Text
frm5.Label36.ForeColor = Color.Black
frm5.Label37.Text = frm1.TextBox17.Text
frm5.Label37.ForeColor = Color.Black
frm5.Label38.Text = frm1.TextBox18.Text
frm5.Label38.ForeColor = Color.Black
frm5.Label39.Text = frm1.TextBox19.Text
frm5.Label39.ForeColor = Color.Black
frm5.Label40.Text = frm1.TextBox20.Text
frm5.Label40.ForeColor = Color.Black
End If
If frm5 IsNot Nothing Then
frm5.Show(Me) 'Show Second Form
Me.Hide()
End If
If CBool(String.Compare(frm1.TextBox2.Text.Trim(), frm3.TextBox1.Text.Trim(), True)) Then
frm5.PictureBox1.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox1.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox4.Text.Trim(), frm3.TextBox2.Text.Trim(), True)) Then
frm5.PictureBox2.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox2.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox6.Text.Trim(), frm3.TextBox3.Text.Trim(), True)) Then
frm5.PictureBox3.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox3.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox8.Text.Trim(), frm3.TextBox4.Text.Trim(), True)) Then
frm5.PictureBox4.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox4.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox10.Text.Trim(), frm3.TextBox5.Text.Trim(), True)) Then
frm5.PictureBox5.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox5.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox12.Text.Trim(), frm3.TextBox6.Text.Trim(), True)) Then
frm5.PictureBox6.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox6.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox14.Text.Trim(), frm3.TextBox7.Text.Trim(), True)) Then
frm5.PictureBox7.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox7.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox16.Text.Trim(), frm3.TextBox8.Text.Trim(), True)) Then
frm5.PictureBox8.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox8.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox18.Text.Trim(), frm3.TextBox9.Text.Trim(), True)) Then
frm5.PictureBox9.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox9.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
If CBool(String.Compare(frm1.TextBox20.Text.Trim(), frm3.TextBox10.Text.Trim(), True)) Then
frm5.PictureBox10.Image = Image.FromFile("D:\vbproject\vbp\checkmark.jpg")
Else
frm5.PictureBox10.Image = Image.FromFile("D:\vbproject\vbp\crossmark.jpg")
frm5.Show()
Me.Hide()
End If
End If
End If
End If
End If
End If
End If
End If
End If
End If
If frm5 IsNot Nothing Then
frm5.Visible = False
frm5.Show() 'Show Second Form
Me.Hide()
End If
End Sub
Private Sub Form5HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
Throw New NotImplementedException
End Sub
End Class
答案 0 :(得分:0)
这里有一些问题需要解决: 你已经粘贴了很多代码。您只需要粘贴If语句(因为这是您遇到问题的地方,这就是问题所在)。 这是关于你的问题:
如果两个字符串匹配,String.Compare会给你结果0。 0(如果将其转换为布尔值,也称为false)。因此,当两个字符串匹配时,您正确显示一个Cross。比较还会告诉你哪个String比另一个大。如果第一个更大,则为1;如果不是,则为-1(Sidetrack在此处不重要)。我建议你改为:
If frm1.TextBox2.Text.ToUpper().Equals(frm3.TextBox1.Text.ToUpper()) Then
在这种情况下,发生的事情非常明显。如果字符串1等于字符串2,则结果为True。不需要CBool。
你的if语句搞砸了。问题2-oo仅在第一个陈述为假时才会得到解决。我会告诉你我的意思。
If statement = true Then
Display checkmark
Else
Display cross
'Now you do the next one inside the else statement
If statement2 = True Then
'Display checkmark
Else
Display cross
'And then you continue the nesting
End If
End If
您需要做的是:
If statement = true Then
'Display check
Else
'Display cross
End If 'Notice how I close the ifstatement before I go to the next one.
If statement2 = true Then
'Display check
Else
'Display cross
End If
etc...
我希望你能得到这个,否则请告诉我,我会尝试进一步简化它。