468,272 Members | 2,146 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,272 developers. It's quick & easy.

Changing text box property from another form

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!!
Nov 20 '05 #1
2 2146
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 End Sub

I hope this helps?

Cor
Nov 20 '05 #2
"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" <sh*************@msn.com> wrote in message
news:F9**********************************@microsof t.com...
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. please help!!

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by horos | last post: by
2 posts views Thread by ColinWard | last post: by
4 posts views Thread by Tony W | last post: by
3 posts views Thread by Doug | last post: by
3 posts views Thread by Mike Johnson | last post: by
5 posts views Thread by Kimmo Laine | last post: by
8 posts views Thread by Steve | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.