how to create a vertical marquee in vb.net - vb.net

i have created a label within a panel and want to move it vertically .
moving horizontally works using:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Start()
If lbl1.Location.X + lbl1.Width < 0 Then
lbl1.Location = New Point(Panel5.Width, lbl1.Location.Y)
Else
lbl1.Location = New Point(lbl1.Location.X - 4, lbl1.Location.Y)
End If
End Sub
as u see in the above code (X) and (Y) is used for left and right drawing point. what is the drawing point for top and bottom

Your Horizontal routine:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If lbl1.Location.X + lbl1.Width < 0 Then
lbl1.Location = New Point(Panel5.Width, lbl1.Location.Y)
Else
lbl1.Location = New Point(lbl1.Location.X - 4, lbl1.Location.Y)
End If
End Sub
Converted to a Vertical routine:
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
If lbl1.Location.Y + lbl1.Height < 0 Then
lbl1.Location = New Point(lbl1.Location.X, Panel5.Height)
Else
lbl1.Location = New Point(lbl1.Location.X, lbl1.Location.Y - 4)
End If
End Sub

take your idea n modify for my own requirement:
Private isFirstTime As Boolean = True
Public Sub RunningText(ByVal lbl As Label, ByVal pnl As Panel, Optional fromRightBottom As Boolean = True, Optional ByVal isHorizontal As Boolean = True)
If isFirstTime Then
If isHorizontal Then
If fromRightBottom Then
lbl.Location = New Point(pnl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(-1 * lbl.Width, lbl.Location.Y)
End If
Else
If fromRightBottom Then
lbl.Location = New Point(lbl.Location.X, pnl.Height)
Else
lbl.Location = New Point(lbl.Location.X, 0)
End If
End If
isFirstTime = False
End If
If isHorizontal Then
If fromRightBottom Then
If lbl.Location.X + lbl.Width < 0 Then
lbl.Location = New Point(pnl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(lbl.Location.X - 4, lbl.Location.Y)
End If
Else
If lbl.Location.X + pnl.Width > lbl.Width + pnl.Width Then
lbl.Location = New Point(-1 * lbl.Width, lbl.Location.Y)
Else
lbl.Location = New Point(lbl.Location.X + 4, lbl.Location.Y)
End If
End If
Else
If fromRightBottom Then
If lbl.Location.Y + lbl.Height < 0 Then
lbl.Location = New Point(lbl.Location.X, pnl.Height)
Else
lbl.Location = New Point(lbl.Location.X, lbl.Location.Y - 4)
End If
Else
If lbl.Location.Y + lbl.Height > lbl.Height + pnl.Height Then
lbl.Location = New Point(lbl.Location.X, 0)
Else
lbl.Location = New Point(lbl.Location.X, lbl.Location.Y + 4)
End If
End If
End If
End Sub

Related

Need to stagger body parts of snake with timer

I need to stagger each body parts release so that they dont just overlap like they do currently.
Is there a way to stagger the running of this code?
Public Class Form1
Public xx As New List(Of Integer)
Public yy As New List(Of Integer)
Public up As Boolean = True
Public down As Boolean = False
Public lefty As Boolean = False
Public righty As Boolean = False
Public sizey As Integer = -1
Public tik As Integer = 0
Public neww As Boolean = False
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
newpart()
newpart()
newpart()
End Sub
Public Sub square(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.Clear(Color.Black)
For a = 0 To sizey
e.Graphics.FillRectangle(Brushes.Aqua, xx(a), yy(a), 20, 20)
Next
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Right Then
righty = True
lefty = False
up = False
down = False
ElseIf e.KeyCode = Keys.Left Then
righty = False
lefty = True
up = False
down = False
ElseIf e.KeyCode = Keys.Up Then
righty = False
lefty = False
up = True
down = False
ElseIf e.KeyCode = Keys.Down Then
righty = False
lefty = False
up = False
down = True
End If
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
square(sender, e)
End Sub
Private Sub clock_Tick(sender As Object, e As EventArgs) Handles head.Tick
If up = True Then
yy(0) = yy(0) - 20
ElseIf down = True Then
yy(0) = yy(0) + 20
ElseIf lefty = True Then
xx(0) = xx(0) - 20
ElseIf righty = True Then
xx(0) = xx(0) + 20
End If
Me.Refresh()
For b = 0 To sizey - 1
If yy(b) - yy(b + 1) = 0 Then
xx(b + 1) = xx(b + 1) + (xx(b) - xx(b + 1))
ElseIf xx(b) - xx(b + 1) = 0 Then
yy(b + 1) = yy(b + 1) + (yy(b) - yy(b + 1))
If neww = True Then
neww = False
Exit For
End If
End If
Next
End Sub
Sub newpart()
xx.Add(100)
yy.Add(100)
sizey = sizey + 1
neww = True
Return
End Sub
End Class
Its mainly the bit in the clock tick as in I need it to wait another tick before running the for loop again. This edited version works but really poorly as the third body part jumps to the first occasionally then just stays still.
You over-complicated that for loop there.
Just make tail catch up before you move head. It can be done in single tick.
Public Class Form1
Public p As New List(Of Point)
Public direction As eDircetion = eDircetion.Up
Public Enum eDircetion
Up
Down
Left
Right
End Enum
Public sizey As Integer = -1
Public tik As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
newpart()
newpart()
newpart()
head.Interval = 500
head.Start()
End Sub
Public Sub square(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs)
e.Graphics.Clear(Color.Black)
For a = 0 To sizey
e.Graphics.FillRectangle(Brushes.Aqua, p(a).X, p(a).Y, 20, 20)
Next
End Sub
Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.D Then
direction = eDircetion.Right
ElseIf e.KeyCode = Keys.A Then
direction = eDircetion.Left
ElseIf e.KeyCode = Keys.W Then
direction = eDircetion.Up
ElseIf e.KeyCode = Keys.S Then
direction = eDircetion.Down
End If
End Sub
Private Sub Form1_Paint(ByVal sender As Object, ByVal e _
As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint
square(sender, e)
End Sub
Private Sub clock_Tick(sender As Object, e As EventArgs) Handles head.Tick
'THIS!
For i = p.Count - 1 To 1 Step -1
p(i) = p(i - 1)
Next
Select Case direction
Case eDircetion.Up
p(0) -= New Size(0, 20)
Case eDircetion.Down
p(0) += New Size(0, 20)
Case eDircetion.Left
p(0) -= New Size(20, 0)
Case eDircetion.Right
p(0) += New Size(20, 0)
Case Else : Throw New Exception("Something went wrong")
End Select
'Me.Refresh()
me.Invalidate() 'This is faster.
Me.Update()
'For b = 0 To sizey - 1
' If p(b).Y - p(b + 1).Y = 0 Then
' p(b + 1).X = p(b + 1).X + (p(b).X - p(b + 1).X)
' ElseIf xx(b) - xx(b + 1) = 0 Then
' yy(b + 1) = yy(b + 1) + (yy(b) - yy(b + 1))
' If neww = True Then
' neww = False
' Exit For
' End If
' End If
'Next
End Sub
Sub newpart()
p.Add(New Point(100, 100))
sizey = sizey + 1
Return
End Sub
End Class
I made some minor changes:
-Use enum instead of 4 booleans, makes cleaner code
-Do not use Me.Refresh, it's slow and does things you do not need here
-It's better to use not two integer lists, but one point list
Hope it helps.

Disable form2 to move out of form1

I have two forms . Form1 and Form2
Form1 is a 600x500 and form2 is 300x250.
Form1 is allways open and when i open form2 it should be on top of form1. How to disable form2 to move out of width form1
Like this
Not like this
So it should be re sizable but unable to move out of edges form1.
If you're not planning to use MDI Forms
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.TopMost = True
Me.Left = Form1.Location.X
Me.Top = Form1.Location.Y + 30
End Sub
Private Sub Form2_Move(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Move
'check position
Dim topLeft, topRight, bottomLeft, BottomRight As Point
With Form1
topLeft = New Point(.Location.X, .Location.Y + 30)
topRight = New Point(.Location.X + .Width, .Location.Y + 30)
bottomLeft = New Point(.Location.X, .Location.Y + .Height)
'BottomRight = New Point(.Location.X + .Location.Y + .Height)
End With
Dim mytopLeft, mytopRight, mybottomLeft, myBottomRight As Point
With Me
mytopLeft = New Point(.Location.X, .Location.Y)
mytopRight = New Point(.Location.X + .Width, .Location.Y)
mybottomLeft = New Point(.Location.X, .Location.Y + .Height)
'myBottomRight = New Point(.Location.X + .Location.Y + .Height)
End With
If topLeft.X > mytopLeft.X Then
Me.Location = New Point(topLeft.X, Me.Location.Y)
Me.Text = "topLeftX"
End If
If topLeft.Y > mytopLeft.Y Then
Me.Location = New Point(Me.Location.X, topLeft.Y)
Me.Text = "topLeftY"
End If
If topRight.X < mytopRight.X Then
Me.Location = New Point(topRight.X - Me.Width, Me.Location.Y)
Me.Text = "topRightX"
End If
If bottomLeft.Y < mybottomLeft.Y Then
Me.Location = New Point(Me.Location.X, bottomLeft.Y - Me.Height)
Me.Text = "bottomLeftY"
End If
End Sub

How to automatically restart a program after it's closed

I'm developing a timer for my kids that will automatically shut down the computer once the time is up and I was trying to figure out a way that the program would automatically restart if it were to be closed via task manager.
I've posted my code for my program bellow if it's any help.
Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.Generic
Public Class Digparent
'add to startupp:
' My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).SetValue(Application.ProductName, Application.ExecutablePath)
'remove from startup
'My.Computer.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\Windows\CurrentVersion\Run", True).DeleteValue(Application.ProductName)
'use application setting boolean to not add same application to startup more than once
'charge for this feature
'to do
'
'wrongn height when make timer unstopable
'above all
Dim X, Y As Integer
Dim NewPoint As New System.Drawing.Point
Public second As Integer
Public checkdone As Boolean
Public checkoff As Boolean
Public unstop As Boolean
Dim Mondayt As String
Dim Tuesdayt As String
Dim Wendsdayt As String
Dim Thursdayt As String
Dim Fridayt As String
Dim Saturdayt As String
Dim Sundayt As String
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
' //
' //
' //
' //Start reader
' //
Dim timeinfo As String = "C:\Users\DigiParent\Desktop\Project data\good.txt"
' IO.File.SetAttributes("C:\Users\DigiParent\Desktop\Project data\Digitimeinfo.txt", IO.FileAttributes.Hidden)
Dim timeChecker As New System.IO.StreamWriter(timeinfo, True)
timeChecker.Close()
Dim readertime As New System.IO.StreamReader(timeinfo, Encoding.Default)
Dim texttime As String = readertime.ReadToEnd
readertime.Close()
If texttime = "" Then
Dim timeobjWriter As New System.IO.StreamWriter(timeinfo, True)
timeobjWriter.Write(",,,,")
timeobjWriter.Close()
End If
Dim startup As String = "C:\Users\DigiParent\Desktop\Project data\good.txt"
Dim reader As New System.IO.StreamReader(startup, Encoding.Default)
Dim data As String = reader.ReadToEnd
Dim aryTextFile(6) As String
aryTextFile = data.Split(",")
Mondayt = aryTextFile(0)
Tuesdayt = aryTextFile(1)
Wendsdayt = aryTextFile(2)
Thursdayt = aryTextFile(3)
Fridayt = aryTextFile(4)
'
'enable this for saturday and sunday
'
'Saturdayt = aryTextFile(5)
'Sundayt = aryTextFile(6)
reader.Close()
' //
' //
' //Finish reader
' //
End Sub
Private Sub Panel2_MouseMove(sender As Object, e As MouseEventArgs) Handles Panel2.MouseMove, time.MouseMove, timeup.MouseMove
If unstop = True Then
If e.Button = Windows.Forms.MouseButtons.Left Then
NewPoint = Control.MousePosition
NewPoint.X -= (X)
NewPoint.Y -= (Y)
Me.Location = NewPoint
End If
End If
End Sub
Private Sub Panel2_MouseDown(sender As Object, e As MouseEventArgs) Handles Panel2.MouseDown, time.MouseDown, timeup.MouseDown
If unstop = True Then
X = Control.MousePosition.X - Me.Location.X
Y = Control.MousePosition.Y - Me.Location.Y
End If
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
NumericUpDownhrs.Left -= 40
NumericUpDownmin.Left -= 40
NumericUpDownsec.Left -= 29 '25
Hourstxt.Left -= 40
Minutestxt.Left -= 30
secondstxt.Left -= 30
Panel1.Left -= 30
RadioButton2.Left -= 30
RadioButton1.Left -= 30
Label4.Left -= 30
Label5.Left -= 30
Button4.Left -= 30
time.Left -= 30
timeup.Left -= 30
If RadioButton1.Location = RadioButton5.Location Then
Timer1.Stop()
Else
End If
If Me.Height < 265 Then
Me.Height = Me.Height + 1
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
more.Visible = False
updateb.Visible = False
feedbackb.Visible = False
Timer1.Start()
Button1.Visible = False
End Sub
Private Sub RadioButton5_CheckedChanged(sender As Object, e As EventArgs) Handles RadioButton5.CheckedChanged
End Sub
Private Sub Button4_Click(snder As Object, e As EventArgs) Handles Button4.Click
My.Settings.Data = True
If RadioButton6.Checked = True Then
My.Settings.unstopable = True
Me.FormBorderStyle = Windows.Forms.FormBorderStyle.None
Me.ShowInTaskbar = False
Me.ControlBox = False
Me.Text = ""
Me.ShowIcon = False
Me.ShowInTaskbar = False
Me.ControlBox = False
unstop = True
Me.Height = 149
Else
My.Settings.unstopable = False
End If
If RadioButton1.Checked = True Then
My.Settings.Shutdown = True
checkoff = True
' System.Diagnostics.Process.Start("ShutDown", "/s")
Else
My.Settings.Shutdown = False
End If
vhrs = NumericUpDownhrs.Value
vmin = NumericUpDownmin.Value
vsec = NumericUpDownsec.Value
My.Settings.hours = vhrs
My.Settings.min = vmin
My.Settings.second = vsec
PictureBox1.Dock = DockStyle.None
PictureBox1.Visible = False
starttime.Start()
realTimer.Start()
End Sub
Public Hrs As Integer 'number of hours '
Public Min As Integer 'number of Minutes '
Public Sec As Integer 'number of Sec '
Public Function GetTime(Time As Integer) As String
'Seconds'
Sec = Time Mod 60
'Minutes'
Min = ((Time - Sec) / 60) Mod 60
'Hours'
Hrs = ((Time - (Sec + (Min * 60))) / 3600) Mod 60
Return Format(Hrs, "00") & ":" & Format(Min, "00") & ":" & Format(Sec, "00")
End Function
Private Sub realTimer_Tick(sender As Object, e As EventArgs) Handles realTimer.Tick
second = second + 1
time.Text = GetTime(second)
'now
If Min >= vmin And Hrs >= vhrs And Sec >= vsec Then
checkdone = True
Me.TopMost = True
'Me.FormBorderStyle = Windows.Forms.FormBorderStyle.FixedSingle
endtime.Start()
If unstop = True Then
closeb.Visible = True
End If
realTimer.Stop()
End If
If checkdone = True And checkoff = True Then
endtime.Start()
System.Diagnostics.Process.Start("ShutDown", "/s")
End If
End Sub
Private Sub starttime_Tick(sender As Object, e As EventArgs) Handles starttime.Tick
time.Left -= 30
Panel1.Left -= 30
RadioButton2.Left -= 30
RadioButton1.Left -= 30
Label4.Left -= 30
Label5.Left -= 30
Button4.Left -= 30
timeup.Left -= 30
If time.Location = Label2.Location Then
starttime.Stop()
End If
If Me.Height > 189 Then
Me.Height = Me.Height - 5
End If
End Sub
Private Sub endtime_Tick(sender As Object, e As EventArgs) Handles endtime.Tick
time.Left -= 30
timeup.Left -= 30
If timeup.Location = labeltimeup.Location Then
endtime.Stop()
End If
End Sub
Private Sub more_Click(sender As Object, e As EventArgs) Handles more.Click
Form3.Show()
'more.Visible = False
'moretimer.Start()
End Sub
Private Sub moretimer_Tick(sender As Object, e As EventArgs) Handles moretimer.Tick
If updateb.Location = Updatebutton.Location Then
moretimer.Stop()
End If
feedbackb.Left += 15
updateb.Left -= 15
End Sub
Private Sub updateb_Click(sender As Object, e As EventArgs) Handles updateb.Click
System.Diagnostics.Process.Start("http://digiparent.weebly.com/beta-20-update.html")
End Sub
Private Sub feedbackb_Click(sender As Object, e As EventArgs) Handles feedbackb.Click
System.Diagnostics.Process.Start("http://digiparent.weebly.com/feedback.html")
End Sub
Private Sub closeb_Click(sender As Object, e As EventArgs) Handles closeb.Click
Me.Close()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
NumericUpDownsec.Value = My.Settings.second
NumericUpDownmin.Value = My.Settings.min
NumericUpDownhrs.Value = My.Settings.hours
If My.Settings.Shutdown = True Then
RadioButton1.Checked = True
End If
If My.Settings.unstopable = True Then
RadioButton6.Checked = True
End If
Button2.Visible = False
End Sub
Private Sub Numericchanged(sender As Object, e As EventArgs) Handles NumericUpDownsec.ValueChanged, NumericUpDownmin.ValueChanged, NumericUpDownhrs.ValueChanged
If NumericUpDownsec.Value = 0 Then ' NumericUpDownhrs.Value = 0 NumericUpDownmin.Value = 0 Then
If NumericUpDownhrs.Value = 0 Then
If NumericUpDownmin.Value = 0 Then
Button2.Visible = True
Else
Button2.Visible = False
End If
Else
Button2.Visible = False
End If
Else
Button2.Visible = False
End If
End Sub
Private Sub Label4_Click(sender As Object, e As EventArgs) Handles Label4.Click
End Sub
End Class
Here's a very basic windowless watchdog app.
Start with a standard WinForms project.
Add a Module.
Add a Public Sub Main to it.
Go to Project --> Properties --> Application Tab, and Uncheck the "Enable Application Framework" box.
Above that, change the "Startup object:" dropdown from "Form1" to "Sub Main".
The code...
Module Module1
Public Sub Main()
Application.Run(New Watchdog)
End Sub
End Module
Public Class Watchdog
Inherits ApplicationContext
Private AppToWatch As String
Private FullPath As String = "C:\WINDOWS\system32\calc.exe"
Private WithEvents P As Process
Public Sub New()
AppToWatch = System.IO.Path.GetFileNameWithoutExtension(FullPath)
Dim PS() As Process = Process.GetProcessesByName(AppToWatch)
If PS.Length = 0 Then
StartIt()
Else
P = PS(0)
P.EnableRaisingEvents = True
End If
End Sub
Private Sub P_Exited(sender As Object, e As EventArgs) Handles P.Exited
StartIt()
End Sub
Private Sub StartIt()
P = Process.Start(FullPath)
P.EnableRaisingEvents = True
End Sub
End Class
Compile the program as a service, and configure it to start automatically.

Auto Scroll on panel vb.net

i am trying to get a automatic scroll going (goes all the way down a panel, then scrolls all the way back up). I get it to go down to the end of the panel, but cannot get it to come back up. It is set to work on a timer. Here is my code:
Private Sub tmrSCROLL_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSCROLL.Tick
pnlScrollFeed.AutoScrollPosition = New Point(pnlScrollFeed.AutoScrollPosition.X, Math.Abs(pnlScrollFeed.AutoScrollPosition.Y) + 1)
Dim totalHeight As Integer = pnlScrollFeed.VerticalScroll.Maximum
Dim tempHeight As Integer = pnlScrollFeed.VerticalScroll.Value
Dim tempDiff As Integer = totalHeight - tempHeight
If tempDiff > 800 Then
pnlScrollFeed.AutoScrollPosition = New Point(pnlScrollFeed.AutoScrollPosition.X, Math.Abs(pnlScrollFeed.AutoScrollPosition.Y) + 1)
ElseIf tempDiff <= 800 Then
pnlScrollFeed.AutoScrollPosition = New Point(pnlScrollFeed.AutoScrollPosition.X, Math.Abs(pnlScrollFeed.AutoScrollPosition.Y) - 1)
tempHeight += 1
End If
End Sub
Probably works better if you have a variable to tell you which direction to go, then just calculate when the scroll thumb hits the bottom or to top:
Private scrollUp As Boolean = False
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If scrollUp Then
Dim scrollY As Integer = -Panel1.AutoScrollPosition.Y - 1
If scrollY < 0 Then
scrollUp = False
Else
Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X, scrollY)
End If
Else
Dim scrollY As Integer = -Panel1.AutoScrollPosition.Y + 1
If scrollY > Panel1.AutoScrollMinSize.Height - Panel1.ClientSize.Height Then
scrollUp = True
Else
Panel1.AutoScrollPosition = New Point(Panel1.AutoScrollPosition.X, scrollY)
End If
End If
End Sub

My If Else Statement VB.Net's weird behavior

I have this program that when I typed the same text on the form and to the other form will add one (+1) to the label of my last form..There were no errors but when I wrote the correct answers on the textboxes it just gave me a number 1 instead of 10. Please help me guys. Thanks in advance :)
here is my code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm4 = New Form4()
frm1 = New Form1()
Dim Textbox1 As New TextBox
Dim Label3 As New Label
If Textbox1.Text = frm1.TextBox2.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox2.Text = frm1.TextBox4.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox3.Text = frm1.TextBox6.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox4.Text = frm1.TextBox8.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox5.Text = frm1.TextBox10.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox6.Text = frm1.TextBox12.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox7.Text = frm1.TextBox14.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox8.Text = frm1.TextBox16.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox9.Text = frm1.TextBox18.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox10.Text = frm1.TextBox20.Text Then
frm4.Label3.Text = (frm4.Label3.Text) + 1
End If
End If
End If
End If
End If
End If
End If
End If
End If
frm4.Show()
Else
frm4.Label3.Text = frm4.Label3.Text
frm4.Show()
End If
End Sub
Form 2 codes:
Public Class Form2
Private frm1 As Form1 ' remove the new here because it creates a new instance of Form1'
Private frm3 As Form3
Public lbl As New Label ' not needed?'
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Controls.Add(lbl)
End Sub
Public Sub New(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
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
' Dim Label21 As Label = New Label ' this label is not needed'
' Dim Textbox1 As TextBox = New TextBox ' this textbox is not needed'
' Create a new instance of Form3, do not use the automatic Form3 instance
' automatically created by VB.NET
frm3 = New Form3()
' now you are referring to the caller instance of Form1 '
' where there is the textbox filled with your text '
frm3.Label21.Text = frm1.TextBox1.Text
frm3.Label22.Text = frm1.TextBox3.Text
frm3.Label23.Text = frm1.TextBox5.Text
frm3.Label24.Text = frm1.TextBox7.Text
frm3.Label25.Text = frm1.TextBox9.Text
frm3.Label26.Text = frm1.TextBox11.Text
frm3.Label27.Text = frm1.TextBox13.Text
frm3.Label28.Text = frm1.TextBox15.Text
frm3.Label29.Text = frm1.TextBox17.Text
frm3.Label30.Text = frm1.TextBox19.Text
frm3.Show()
End Sub
End Class
Form1 Codes:
Public Class Form1
Private frm2 As Form2
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
If frm2 Is Nothing Then
frm2 = New Form2(Me)
AddHandler frm2.FormClosed, AddressOf Me.Form2HasBeenClosed
Dim Label21 As Label = New Label
frm2.Label21.Text = TextBox1.Text
frm2.Label21.ForeColor = Color.Black
Dim Label22 As Label = New Label
frm2.Label22.Text = TextBox2.Text
frm2.Label22.ForeColor = Color.Black
Dim Label23 As Label = New Label
frm2.Label23.Text = TextBox3.Text
frm2.Label23.ForeColor = Color.Black
Dim Label24 As Label = New Label
frm2.Label24.Text = TextBox4.Text
frm2.Label24.ForeColor = Color.Black
Dim Label25 As Label = New Label
frm2.Label25.Text = TextBox5.Text
frm2.Label25.ForeColor = Color.Black
Dim Label26 As Label = New Label
frm2.Label26.Text = TextBox6.Text
frm2.Label26.ForeColor = Color.Black
Dim Label27 As Label = New Label
frm2.Label27.Text = TextBox7.Text
frm2.Label27.ForeColor = Color.Black
Dim Label28 As Label = New Label
frm2.Label28.Text = TextBox8.Text
frm2.Label28.ForeColor = Color.Black
Dim Label29 As Label = New Label
frm2.Label29.Text = TextBox9.Text
frm2.Label29.ForeColor = Color.Black
Dim Label30 As Label = New Label
frm2.Label30.Text = TextBox10.Text
frm2.Label30.ForeColor = Color.Black
Dim Label31 As Label = New Label
frm2.Label31.Text = TextBox11.Text
frm2.Label31.ForeColor = Color.Black
Dim Label32 As Label = New Label
frm2.Label32.Text = TextBox12.Text
frm2.Label32.ForeColor = Color.Black
Dim Label33 As Label = New Label
frm2.Label33.Text = TextBox13.Text
frm2.Label33.ForeColor = Color.Black
Dim Label34 As Label = New Label
frm2.Label34.Text = TextBox14.Text
frm2.Label34.ForeColor = Color.Black
Dim Label35 As Label = New Label
frm2.Label35.Text = TextBox15.Text
frm2.Label35.ForeColor = Color.Black
Dim Label36 As Label = New Label
frm2.Label36.Text = TextBox16.Text
frm2.Label36.ForeColor = Color.Black
Dim Label37 As Label = New Label
frm2.Label37.Text = TextBox17.Text
frm2.Label37.ForeColor = Color.Black
Dim Label38 As Label = New Label
frm2.Label38.Text = TextBox18.Text
frm2.Label38.ForeColor = Color.Black
Dim Label39 As Label = New Label
frm2.Label39.Text = TextBox19.Text
frm2.Label39.ForeColor = Color.Black
Dim Label40 As Label = New Label
frm2.Label40.Text = TextBox20.Text
frm2.Label40.ForeColor = Color.Black
End If
If frm2 IsNot Nothing Then
frm2.Show(Me) 'Show Second Form
Me.Hide()
End If
End Sub
Sub Form2HasBeenClosed(ByVal sender As Object, ByVal e As FormClosedEventArgs)
frm2 = Nothing
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Form 3 Code:(instance calling to form1)
Public Class Form3
Private frm3 As Form3
Private frm1 As Form1
Private frm4 As Form4
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
End Class
If you want show in label number of right answers then
You need compare all user answers with right answers
And count times when answers are same:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
frm4 = New Form4()
frm1 = New Form1()
Dim Textbox1 As New TextBox
Dim Label3 As New Label
Dim sameQnt As Int32 = 0
If Textbox1.Text = frm1.TextBox2.Text Then sameQnt += 1
If Textbox2.Text = frm1.TextBox4.Text Then sameQnt += 1
If Textbox3.Text = frm1.TextBox6.Text Then sameQnt += 1
If Textbox4.Text = frm1.TextBox8.Text Then sameQnt += 1
If Textbox5.Text = frm1.TextBox10.Text Then sameQnt += 1
If Textbox6.Text = frm1.TextBox12.Text Then sameQnt += 1
If Textbox7.Text = frm1.TextBox14.Text Then sameQnt += 1
If Textbox8.Text = frm1.TextBox16.Text Then sameQnt += 1
If Textbox9.Text = frm1.TextBox18.Text Then sameQnt += 1
If Textbox10.Text = frm1.TextBox20.Text Then sameQnt += 1
'Print reslut
frm4.Label3.Text = sameQnt.ToString()
frm4.Show()
End Sub
Here is my new answer
Public Class MainForm '<----Your main form class name
Dim frm4 = New Form4()'<----declare it here
Dim frm1 = New Form1()'<----declare it here
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Textbox1 As New TextBox
Dim Label3 As New Label
Dim i As Integer = 0
If Textbox1.Text = frm1.TextBox2.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox2.Text = frm1.TextBox4.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox3.Text = frm1.TextBox6.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox4.Text = frm1.TextBox8.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox5.Text = frm1.TextBox10.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox6.Text = frm1.TextBox12.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox7.Text = frm1.TextBox14.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox8.Text = frm1.TextBox16.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox9.Text = frm1.TextBox18.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
If TextBox10.Text = frm1.TextBox20.Text Then i += 1 'frm4.Label3.Text = (frm4.Label3.Text) + 1
frm4.Label3.Text = i.ToString()
frm4.Show()
End Sub
End Class