sjones

sjones

  • NA
  • 135
  • 0

Using the Text property on UserControl

Apr 17 2004 8:00 PM
I created a basic User Control with a textbox and a button. I am trying to use the Text property of my control to pass data back and forth to the Textbox contol. I have it working where the form can set the .Text property on MyControl and have it show up in the Textbox. I can also read the MyControlText property to get the contents of the Textbox. Hell, I even raise an event back to the Form with this code: private void txtDir_TextChanged(object sender, System.EventArgs e) { OnTextChanged(e); } But what I can't seem to do is get the Form Designer to keep my Design Time Text value from the Properties grid. In order to even get it to show up there, I had to overload the Text property and put the [Browsable(true)] attribute on the property. When I put text in the Text Property in the Properties grid, they do show up on the form in the designer. But if I switch over to look at the code, all my other properties are being assigned, like Visible, Enabled, Name, Size, etc. But there is no entry for Text. Can anyone tell me why this is happening? Just for the hell of it I added the line this.MyControl.Text = "Just Testing"; in the code window's InitializeComponent(), and when I switched back to design view, my text was in the control and in the Properties grid. But as soon as I try to change the value to "Just Testing again" the old problem is back. The new value shows up in the control in the designer, but when I open the code window, there is no line to set the Text property.

Answers (1)