muthuraman Posted October 31, 2003 Posted October 31, 2003 Hi there, I am trying to create a textbox dynamically in my code. When I try to set the backcolor of the textbox to somecolor, it doesn't happen. I find that the backcolor of the form is overriding the control's backcolor. Same is the case with forecolor. Can anyone help me?. Thank You. Quote
Administrators PlausiblyDamp Posted October 31, 2003 Administrators Posted October 31, 2003 Could you show hte code you are using? Just tried the following in a button click event and it worked without any problems. Dim t As New TextBox t.BackColor = Color.Beige t.Visible = True Me.Controls.Add(t) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
muthuraman Posted October 31, 2003 Author Posted October 31, 2003 Hi, The following is the code I tried. Dim test as TextBox 'The following code goes into Form Load event test.BackColor = System.Drawing.Color.Aqua test.Text = "Hello" test.Left = 300 test.Top = 400 Me.Controls.Add(test) This works fine if I have it in Form Load. The same code doesn't work inside a button click event. Quote
*Experts* mutant Posted October 31, 2003 *Experts* Posted October 31, 2003 That code wouldnt work. You need to create a new instance of the TextBox object, not just a variable of that type: Dim test As New TextBox Quote
muthuraman Posted October 31, 2003 Author Posted October 31, 2003 Sorry about that. I created a new instance. Quote
Administrators PlausiblyDamp Posted October 31, 2003 Administrators Posted October 31, 2003 Cut and pasted your code into a click event handler (and created a new instance) - worked first time. Is there any other code in the form load or paint events? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
muthuraman Posted October 31, 2003 Author Posted October 31, 2003 Yes, I have some other code in the form load event Quote
Administrators PlausiblyDamp Posted October 31, 2003 Administrators Posted October 31, 2003 Does that modify backcolor properties for the form / controls on the form? Could you post hte code here? Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
muthuraman Posted October 31, 2003 Author Posted October 31, 2003 Oh yes, it does. I have a function call which checks if each textbox has a non-numerical value and highlights the respective fields. Then I set back the color of all the fields to the default color. It works fine if I paste my code after this function call. Thanks a lot 'PlausiblyDamp'... :) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.