PC Review


Reply
Thread Tools Rate Thread

Changing text box property from another form

 
 
=?Utf-8?B?c2hhbA==?=
Guest
Posts: n/a
 
      3rd Mar 2004
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!!
 
Reply With Quote
 
 
 
 
Cor
Guest
Posts: n/a
 
      3rd Mar 2004
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


 
Reply With Quote
 
Rigga
Guest
Posts: n/a
 
      3rd Mar 2004
"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" <(E-Mail Removed)> wrote in message
news:F9C28C83-9212-4601-AE77-(E-Mail Removed)...
> 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!!



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Changing Label text property on another form, post #2 Mike Johnson Microsoft VB .NET 3 17th May 2004 05:44 PM
Changing Label text property on another form Mike Johnson Microsoft VB .NET 3 17th May 2004 03:29 PM
Changing text box property after Update Jim/Chris Microsoft Access Macros 1 21st Apr 2004 07:25 PM
changing parent form property from child form Microsoft C# .NET 0 25th Sep 2003 05:43 PM
changing parent form property from child form Microsoft C# .NET 0 25th Sep 2003 03:41 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:49 AM.