Results 1 to 15 of 15

Thread: Design-Time Property Only?

  1. #1
    hellswraith
    Guest

    Question Design-Time Property Only?

    I am creating a custom control, and I need to create a Design-Time property. I don't want the user of my control to change the values during runtime, just during design time. How would you do that? I am sure there is a key word somewhere that I am missing...

    I am working in C#, but if anyone can give me an example in VB.Net, that would work also.

  2. #2
    hellswraith
    Guest
    Anyone create a user control yet? I really need to know this to finish my control, hence the bump up...

  3. #3
    Tygur
    Guest
    I may be wrong, but I don't believe the concept of design-time-only properties exists in VB.NET (or C#).

  4. #4
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    I could swear that I read how to test if your app is in design time. , but for the life of me I cannot find where I saw it, I was looking for something else.

    If this is possible and you can figure out how to do it... you could stop any changes unless they were in design time.

    I could be totaly wrong, but i could swear I read it somewhere.
    That which does not kill us, only makes us stronger.

  5. #5
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Here is a snippet that may help you.


    Public Property Let vFile(ByVal New_vFile As Variant)
    '// only allowed to set value at run time
    '// raise an error if we try to set it at design time.
    If Ambient.UserMode = False Then Err.Raise 382
    m_vFile = New_vFile
    PropertyChanged "vFile"
    End Property


    If you want the rest it is at...

    http://www.developerfusion.com/show/20/7/
    That which does not kill us, only makes us stronger.

  6. #6
    hellswraith
    Guest
    Great! That is exactly what I needed. Many thanks go out to you.

    Here is the quote from the site that I needed:
    If you want a property to be read-only at design time, then you can check the Ambient.UserMode property. It returns False when at design time, and True when at run-time.

  7. #7
    Tygur
    Guest
    umm..
    Unless I missed something, that code is for VB6 and it won't work in VB.NET.

  8. #8
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Oops! I'm an idiot!
    That which does not kill us, only makes us stronger.

  9. #9
    hellswraith
    Guest
    Yep, I went to go work on it later and quickly noticed that.

    Oh well, the search is still on people, if you know how, please tell.

  10. #10
    Tygur
    Guest
    Like I said before, the concept of design-time-only properties isn't there anymore. When you set properties at design time using the Properties Window, VB will simply put the code in the form to set the properties at run time. See for yourself. VB puts in a subroutine called InitializeComponent, which is run from the constructor of the form. The code to set the properties you chose at "design time" will automatically get inserted there. In reality, all properties are actually getting set at run time.

  11. #11
    hellswraith
    Guest
    I need it to be only done at design time. If it is done at runtime after things have been done to the control, it will mess up the layout of the controls on the form. I am putting picture boxes in either a vertical colum or horizontal row, not both. I want the user to decide before runtime what it will be. There has to be a way to tell if the program is running.

  12. #12
    Tygur
    Guest
    Here's an example of what I'm talking about:
    Create a new Windows Application. Then add a TextBox to the form. Change the Text property for the TextBox in the Properties window to "Stuff" (so you're changing it at design time). After that, look at the code for the form. Press Ctrl+F to bring up the find dialog. Check off "Search hidden text" and search for "Stuff". You will notice that VB automatically threw this line in:
    Code:
    Me.TextBox1.Text = "Stuff"

  13. #13
    hellswraith
    Guest
    I understand what you are saying. I know how it does the properties. It doesn't matter anyway, I figured it out on my own how to do it. It can be done. Here is how for anyone wanting to know (there is probably a better way, but I offer you this because no one has come up with an answer for me yet):

    (it is in C#, but you will easily understand it)
    Code:
    public class ThumbnailImagePanel : System.Windows.Form.Panel
    {
        //This is the variable declarations and the Constructor for my control:
       private bool bControlIsRunning;
       private int iThumbSizeX;
    
       public ThumbnailImagePanel()
       {
           bControlIsRunning = false;
           // This call is required by the Windows.Forms Form Designer.
           InitializeComponent();
           // TODO: Add any initialization after the InitForm call
           bControlIsRunning = true;
       }
    
       //This is a custom property for the control:
       public int ThumbSizeX
       {
          // Return width of thumbs.
          get
          {
             return iThumbSizeX;
          }
    
          // Sets the thumbs widths.
          set
          {
             if (bControlIsRunning == false)
             {
                iThumbSizeX = value;
             }
          }
       }
    }
    To explain: When the constructor is called, I immediately set the bControlIsRunning variable to false. Then the InitializeComponent() method is called. If the user has set properties in design time, that is where they will be put by the IDE, as Tygur above has stated. Because bControlIsRunning = false, the properties will be able to change. When the InitializeComponent call returns, I then set the bControlIsRunning variable to true, and not allowing the properties to be changed by any users code.

  14. #14
    hellswraith
    Guest
    Further testing shows the last method won't work unless your working with just the control. Damn, I thought I had it....lol. I guess to make the properties design time only, I am going to have to make some overloaded constructors that the user can choose from. I guess this will have to suffice.

  15. #15
    Addicted Member wolfofthenorth's Avatar
    Join Date
    Jan 2001
    Location
    Tatooine
    Posts
    169
    Have you seen the "DesignMode" property on a form? Maybe it is what you are looking for.

    This time it really is .NET code... I swear.
    That which does not kill us, only makes us stronger.

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