-
Text Property for user control
Hello,
at the moment I create a usercontrol. I wan't to have for that a text property. But I don't have any idea, why my solution doesn't work...
Code:
[
Category("Appearance"),
Description("The text associated with the control.")
]
public string Text
{
get { return text; }
set { text = value; }
}
Regards
Hansjörg
-
Re: Text Property for user control
The control class (the base class of all user controls) already has the Text property..Why do you want to add your own?
You can override OnTextChanged method to add your special logic or override the Text property itself.
-
Re: Text Property for user control
I don't want a new Text propertie. I want to see and edit the text property in the property editor (at the moment I don't see it there), because I want to display the text in a label inside the usercontrol.
What is the best way for that?
Regards
hansjörg
-
Re: Text Property for user control
try to add the Browsable attribute:
Code:
[Browsable(true)]
public override string Text
{
get
{
return text;
}
set
{
text = value;
}
}
-
Re: Text Property for user control
Great it works. Is there also a possibility to bind the text property of a label to this text property? It would be great if I can see the text also in the designer
Regards and many thanks
Hansjörg
-
Re: Text Property for user control
Solved. I can set the property of the label only inside the Property Text
Thanks
Hansjörg
-
Re: Text Property for user control
Hello,
during the test I have found out that the text-Property is not saved if I close the form.
What I have to do to save it?
Regards
Hansjörg
-
Re: Text Property for user control
Quote:
Originally Posted by hansipet
Hello,
during the test I have found out that the text-Property is not saved if I close the form.
What I have to do to save it?
Regards
Hansjörg
strange
Please send the code of the property..or upload the code file.
-
Re: Text Property for user control
Code:
public partial class ConnectionDeviceSettingsCtrl : UserControl{
private string text;
[Browsable(true)]
public override string Text
{
get { return text; }
set
{
this.text = value;
connectionDevSettings.Text = value;
}
}
private System.Windows.Forms.GroupBox connectionDevSettings;
}
Regards and many thanks for your help!
-
Re: Text Property for user control
So..When you close the form designer and reopen it ,, you lose the last Text value...
This is so strange..I did not face this problem before..
-
Re: Text Property for user control
Yes I loose this property. I have another strange problem in this workspace.
If the control where the usercontrol is placed is open during closing my visualstudio 2005 express edition.
- control where the above usercontrol is used is open in designer
- close VS 2005 express edition
- open VS 2005 express edition
- open this project -->
Receive warnings:
Warning 1 Exception has been thrown by the target of an invocation. D:\daten\projekte\c#\NetWorkManagerDev\NetworkManager\View\ConfigCtrl.Designer.cs 531 0
Warning 2 Could not load file or assembly 'Ethernet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Das System kann die angegebene Datei nicht finden. D:\daten\projekte\c#\NetWorkManagerDev\NetworkManager\View\ConfigCtrl.Designer.cs 538 0
Warning 3 Could not load file or assembly 'Ethernet, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. Das System kann die angegebene Datei nicht finden. D:\daten\projekte\c#\NetWorkManagerDev\NetworkManager\View\ConfigCtrl.Designer.cs 537 0
Warning 4 Could not find type 'Ethernet.NetworkManager.Data.DeviceConnectionList'. Please make sure that the assembly that contains this type is referenced. If this type is a part of your development project, make sure that the project has been successfully built. D:\daten\projekte\c#\NetWorkManagerDev\NetworkManager\View\ConfigCtrl.Designer.cs 514 0
I don't know why. May be the two things are associated..
Regards
Hansjörg
-
Re: Text Property for user control
sorry I saw that some parts of the warnings are in german.
Das System kann die angegebene Datei nicht finden.
means
The system can't find the file
-
Re: Text Property for user control
Try to rebuild the control separately..then add it again to the form designer..
-
Re: Text Property for user control
What do you mean with build seperatly and add it to the form designer. Do you mean build the project seperatly and add it than to the VS2005 workspace?
Regards
Hansjörg
-
Re: Text Property for user control
No
delete the control from the form
then build the control project
then add it again to the form..
another last option:
remove the control project from the workspace..
build it
add it to the control box as an assemble..then drag and drop it on the form.
-
Re: Text Property for user control
I have made now the first step:
I think it is a bug of VS2005...
For some reason it seems that the building of the components not works properly...
if I have opened a form with the control -> close visual studio -> open project -> an error on the form appears. I have first to close the form, close the control -> rebuild project. open one time the control and after that it works..
Regards
Hansjörg
-
Re: Text Property for user control
I have the exact same problem now.
I needed the .Text field exposed in a user derived class of UserControl, so I added the Browsable(true), so now it shows up, but when changed, nothing get written to the file.
Any solution for this problem?
My woraround for now was to add a new field like this
Code:
[Category("Appearance"), Description("wrapper for .Text field")]
public string Title
{
get { return base.Text; }
set { base.Text = value; }
}
which of course is really ugly.
Any better way of exposing the Text field in the designer so it works?
Jesper
-
Re: Text Property for user control
How about:
Code:
[Browsable(true)]
public new string Text
{
get { return base.Text; }
set { base.Text = value; }
}
-
Re: Text Property for user control
That does not work.
I first tried override then new, neither works, the property is not written the file.
-
Re: Text Property for user control
Til now I work also only with the workaround (other property). I had the problem also for a few other controls. I don't have any idea, what is the problem.
Regards
Hansjörg
-
Re: Text Property for user control
yeah I guess we will just have to live with that bug.
-
Re: Text Property for user control
I found the answer on the microsoft.public.dotnet.languages.csharp group.
Code:
[EditorBrowsable(EditorBrowsableState.Always), Browsable(true),
DesignerSerializationVisibility(DesignerSerializationVisibility.Visible),
Bindable(true)]
public override string Text
{
get { return base.Text; }
set { base.Text = value; }
}
The important attribute is the DesignerSerializationVisibility one
Jesper
-
Re: Text Property for user control
It doesn't work too...I think this is a bug of the designer or something else...
-
Re: Text Property for user control
hm... it works for me. The field shows up in the designed (as before) and when changed and saved, the changes are written correct in the InitializeComponent method, so for me it works correct now.