Changing text box property from another form

G

Guest

hello

I am trying to change text color of the textbox1 from another form named Form2. i am using following code right now but it doesnt change property of textbox1. can you tell me whats wrong here? thanks!

Code in Form1 that has Text box named Textbox

// this linedoes do anything it jsut shows theres one textbox1 insdie form on

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChange
End Su

// if user clicks on the button another form pops up with radio buttons where you can select colo

Private Sub BtnOptions_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnOptions.Clic
Dim N As New Form2(
N.Show(
End Su

// after selecting particular radio button user clicks ok, so text color in side text box in form1 should change..

Private Sub btnOkF2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOkF2.Clic
Dim N As New Form1(
If RadioButton1.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Blu
If RadioButton2.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Re
If RadioButton3.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Gree
If RadioButton4.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Blac
If RadioButton5.Checked = True Then N.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3
If RadioButton6.Checked = True Then N.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingl
N.TextBox1.Text = "Hellow World!
Me.Hide(


End Su

above code should change Text color in From1 Textbox1 but it doenst change color!! i dont know what is wrong with the code as it compiles without any error.
please help!!
 
C

Cor

Hi Shal,

When you handle your optionform as a dialog form it becomes very easy.
You make a property (or just a public field) in your optionform
Private Sub BtnOptions_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnOptions.Click
Dim N As New Form2()
N.Showdialog
mycolor = N.myoptioncolor
N.dispose
I hope this helps?

Cor
 
R

Rigga

"Dim N As New Form1()"

Is the incorrect line, this creates a new instance of Form1 instead of
referencing the existing Form1 Instance..

You will need to pass a reference into Form2, either for the Instance of
Form1 you currently have or for the specific textbox on Form1 you wish to
change. (I'd go for the second option, as you can then use it with other
textboxes also.. reusable code..).

So in Form2, create a TextBoxToAlter Property (or some such).. then when you
create Form2, set the Form2.TextBoxToAlter = Me.TextBox1 (Assuming you're
starting Form2 from Form1)

Then in Form2, use Me.TextBoxToAlter.ForeColor = Color.Blue etc.....

Rigga.

shal said:
hello:

I am trying to change text color of the textbox1 from another form named
Form2. i am using following code right now but it doesnt change property of
textbox1. can you tell me whats wrong here? thanks!!
Code in Form1 that has Text box named Textbox1

// this linedoes do anything it jsut shows theres one textbox1 insdie form one

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles TextBox1.TextChanged
End Sub

// if user clicks on the button another form pops up with radio buttons where you can select color

Private Sub BtnOptions_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BtnOptions.Click
Dim N As New Form2()
N.Show()
End Sub

// after selecting particular radio button user clicks ok, so text color
in side text box in form1 should change..
Private Sub btnOkF2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnOkF2.Click
Dim N As New Form1()
If RadioButton1.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Blue
If RadioButton2.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Red
If RadioButton3.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Green
If RadioButton4.Checked = True Then N.TextBox1.ForeColor = System.Drawing.Color.Black
If RadioButton5.Checked = True Then N.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D
If RadioButton6.Checked = True Then N.TextBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
N.TextBox1.Text = "Hellow World!"
Me.Hide()


End Sub

above code should change Text color in From1 Textbox1 but it doenst change
color!! i dont know what is wrong with the code as it compiles without any
error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top