CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Join Date
    Dec 2005
    Posts
    282

    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

  2. #2
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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.
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  3. #3
    Join Date
    Dec 2005
    Posts
    282

    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

  4. #4
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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;
    	}
    }
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  5. #5
    Join Date
    Dec 2005
    Posts
    282

    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

  6. #6
    Join Date
    Dec 2005
    Posts
    282

    Re: Text Property for user control

    Solved. I can set the property of the label only inside the Property Text

    Thanks
    Hansjörg

  7. #7
    Join Date
    Dec 2005
    Posts
    282

    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

  8. #8
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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.
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  9. #9
    Join Date
    Dec 2005
    Posts
    282

    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!

  10. #10
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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..
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  11. #11
    Join Date
    Dec 2005
    Posts
    282

    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

  12. #12
    Join Date
    Dec 2005
    Posts
    282

    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

  13. #13
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    Re: Text Property for user control

    Try to rebuild the control separately..then add it again to the form designer..
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

  14. #14
    Join Date
    Dec 2005
    Posts
    282

    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

  15. #15
    Join Date
    Apr 2002
    Location
    Egypt
    Posts
    2,210

    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.
    Hesham A. Amin
    My blog , Articles


    <a rel=https://twitter.com/HeshamAmin" border="0" /> @HeshamAmin

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured