I have multiple panels on same form and I want Passing a value between 2 panel - vb.net

I have multiple panels on the same form and I want Passing a value between 2 panels
I want to enter Username in the first panel and Show as Label in next panel
please not in between 2 Form but 2 Panels.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
Guna.UI.Lib.GraphicsHelper.ShadowForm(Me)
End Sub
Private Sub GunaButton1_Click(sender As Object, e As EventArgs) Handles GunaButton1.Click
pnLogin.BringToFront()
GunaTransition1.Hide(pnLogin)
End Sub
Private Sub GunaButton2_Click(sender As Object, e As EventArgs)
End Sub
Private Sub GunaGradientButton2_Click(sender As Object, e As EventArgs)
End Sub
Private Sub GunaTextBox1_Click(sender As Object, e As EventArgs) Handles GunaTextBox1.Click
End Sub
End Class

If all the controls are in the same Form, then the container they are within is irrelevant.
The code would look something like this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Label1.Text = TextBox1.Text
End Sub
You need to change the control names to what you have on your form for the Button, TextBox and Label.

You can simply declare the variable in form class scope and use it! can you explain more details?
Update:
Private Sub Button_Click(sender As Object, e As EventArgs) Handles Button.Click
Lable.text = TextBox.text
EndSub

Related

Change Backcolor for all inherited forms

i have a baseform and a few forms inherited from that.
Call them BaseForm and Form1, Form2
I want to select a color in Form1 and these color is set in all inherited forms.
That works, if the form is open after the color is changed.
Let me explain.
I open Form1
select the color and set a global variable(glColorVariable).
The Backgroundcolor in the Baseform.Designer.vb is set
me.backcolor=glColorVariable
The color in Form1 didn't change
If i now open form2 the color in form2 IS changed.
How can i ... repaint my Baseform in Form1 so the color is changed.
Thank you verry much!
Cornelia
You can't loop forms so that you can change a parameter on them.
I think the Assembly.GetExecutingAssembly().GetTypes() is dead end for this.
One solution, if you fill an list element with your forms.
Dim Forms As New List(Of Form)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Forms.Add(My.Forms.Form1)
Forms.Add(My.Forms.Form2)
Forms.Add(My.Forms.Form3)
End Sub
Sub SetBackColors(ByVal c As Color)
For Each f In Forms
f.BackColor = c
Next
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SetBackColors(Color.Red)
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form2.Show()
Form3.Show()
End Sub
or what Jimi wrote, use DataBindings:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Form2.DataBindings.Add("BackColor", Me, "BackColor", False, DataSourceUpdateMode.OnPropertyChanged)
Form3.DataBindings.Add("BackColor", Me, "BackColor", False, DataSourceUpdateMode.OnPropertyChanged)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.BackColor = Color.Red
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Form2.Show()
Form3.Show()
End Sub

hello! there is someone who can help me on my project? this is my code

Public Class frmColor
Dim red, green, yellow, blue, orange As New frmChanger
Private Sub BtnRed_Click(sender As Object, e As EventArgs) Handles BtnRed.Click
frmChanger.Show(red)
End Sub
Private Sub BtnGreen_Click(sender As Object, e As EventArgs) Handles BtnGreen.Click
frmChanger.Show(green)
End Sub
Private Sub BtnYellow_Click(sender As Object, e As EventArgs) Handles BtnYellow.Click
frmChanger.Show(yellow)
End Sub
Private Sub BtnBlue_Click(sender As Object, e As EventArgs) Handles BtnBlue.Click
frmChanger.Show(blue)
End Sub
Private Sub BtnOrange_Click(sender As Object, e As EventArgs) Handles BtnOrange.Click
frmChanger.Show(orange)
End Sub
End Class
that is my code on form1....
Public Class frmChanger
Private Sub PnlRed_Paint(sender As Object, e As PaintEventArgs) Handles PnlRed.Paint
PnlRed.BackColor = Color.Red
End Sub
Private Sub PnlGreen_Paint(sender As Object, e As PaintEventArgs) Handles PnlGreen.Paint
PnlGreen.BackColor = Color.Green
End Sub
Private Sub PnlYellow_Paint(sender As Object, e As PaintEventArgs) Handles PnlYellow.Paint
PnlYellow.BackColor = Color.Yellow
End Sub
Private Sub PnlBlue_Paint(sender As Object, e As PaintEventArgs) Handles PnlBlue.Paint
PnlBlue.BackColor = Color.Blue
End Sub
Private Sub PnlOrange_Paint(sender As Object, e As PaintEventArgs) Handles PnlOrange.Paint
PnlOrange.BackColor = Color.Orange
End Sub
End Class
and this is my code on form2....
what i need is, when i clicked the btnRed on form1, on form2 only the PnlRed show..
when the BtnGreen is clicked, Pnlgreen on form2..
my problem is both panel colors show when i click only one button.. what should i do? can someone help me please.
Add a Form level variable to frmChanger with its datatype as Color and its scope as Friend (so it can be seen from frmColor). This code is using the default instance of the form. You don't really need a separate form for each color. You only want to have a different color shown. How about a single panel that will have different colors instead of multiple panels.
In the Form1 code (your frmColor)
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Form2.panelColor = Color.Red
Form2.Show()
End Sub
Repeat for the other buttons with = Color.Green etc.
In Form2 (your frmChanger)
Friend panelColor As Color
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Panel1.BackColor = panelColor
End Sub

Second form is not loading properly on Visual Builder?

in the first form I have a text box where you can add your name, and then when you click Next window, the second form will pop up saying My name is : Your name . This is great, but how would I be able to change the name of the second form known as OtherForm to my name aswell so that when the second form pops up, on the top left corner my name would appear instead of OtherForm? Here is the code for the first and second form so far.
Main Form code:
Public Class MainForm
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Public Sub Label1_Click(sender As Object, e As EventArgs) Handles
WindowName.TextChanged
End Sub
Public Sub WindowName_TextChanged(sender As Object, e As EventArgs)
End Sub
Public Sub OffButton_Click(sender As Object, e As EventArgs) Handles
OffButton.Click
Me.Close()
End Sub
Public Sub NextButton_Click(sender As Object, e As EventArgs) Handles
NextButton.Click
OtherForm.NameLabel.Text = WindowName.Text
OtherForm.Show()
End Sub
End Class
Second form known as OtherForm
Public Class OtherForm
Public Sub CloseButton_Click(sender As Object, e As EventArgs) Handles
CloseButton.Click
Me.Close()
End Sub
Public Sub OtherForm_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
End Sub
Public Sub NameLabel_Click(sender As Object, e As EventArgs) Handles
NameLabel.Click
End Sub
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles
Label1.Click
End Sub
End Class
Try
OtherForm.Text = WindowName.Text
to set the title of the form. Or you can set the text to whatever you would like. I'm not sure if you mean "my name" or the name you entered.
If you do mean "my name" then you can enter that in the form property for "Text" instead of in code as well.

How to make a self replicating program in vb.net?

I'm trying to make a little prank program where a form keeps opening until it hits a certain number like 50 or something, I've tried this:
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Show()
End Sub
End Class
But that doesn't work, anyone willing to help? Thanks
Ditto what litelite said. If you want to show a new instance of the form, Show() won't cut it.
In fact, once you close that form, the timer you're using will be lost. So you'll need to handle the Form.Closing event as well. Since we're just having fun here, I'd suggest that you make that work like cutting off the head of a Hydra, two more replace it.
Try something like this:
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim _newForm as Form2 = new Form2()
_newForm.Show()
End Sub
Private Sub Me_Closing(sender As Object, e As EventArgs) Handles Form2.Closing
Dim _newForm as Form2 = new Form2()
_newForm.Show()
Dim _newForm2 as Form2 = new Form2()
_newForm2.Show()
End Sub
End Class

Changing the background color for Form2

i have two RadioButtons one for Light Blue and the other for Ghost White and a button to show the next Form (Form2)
i want to be able to check on a Radio Button and the backcolor of form2 changes to the checked Radio Button
this is what i have on my coding so far
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SecondForm.Show()
End Sub
Private Sub rbLightBlue_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbLightBlue.CheckedChanged
If rbLightBlue.Checked Then
SecondForm.BackColor = (Color.LightBlue)
End If
End Sub
Private Sub rbGhostWhite_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbGhostWhite.CheckedChanged
If rbGhostWhite.Checked Then
SecondForm.BackColor = (Color.GhostWhite)
End If
End Sub
The problem am having is making the background color change on Form2.
Any answer for this question will be very helpful.
I am not sure what you are doing, it probably has to do with how you are creating your SecondForm, this code does work, see if it helps you narrow it down.
Public Class Form1
Dim SecondForm As Form2 = New Form2
Private Sub rbLightBlue_CheckedChanged(sender As Object, e As EventArgs) Handles rbLightBlue.CheckedChanged
If DirectCast(sender, RadioButton).Checked Then
SecondForm.BackColor = Color.LightBlue
End If
End Sub
Private Sub rbGhostWhite_CheckedChanged(sender As Object, e As EventArgs) Handles rbGhostWhite.CheckedChanged
If DirectCast(sender, RadioButton).Checked Then
SecondForm.BackColor = Color.GhostWhite
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
SecondForm.Show()
End Sub
End Class