|
-
May 27th, 2002, 11:25 AM
#1
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.
-
May 27th, 2002, 02:37 PM
#2
Anyone create a user control yet? I really need to know this to finish my control, hence the bump up...
-
May 27th, 2002, 10:58 PM
#3
I may be wrong, but I don't believe the concept of design-time-only properties exists in VB.NET (or C#).
-
May 27th, 2002, 11:42 PM
#4
-
May 28th, 2002, 06:20 PM
#5
Addicted Member
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. 
-
May 28th, 2002, 06:49 PM
#6
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.
-
May 28th, 2002, 09:17 PM
#7
umm..
Unless I missed something, that code is for VB6 and it won't work in VB.NET.
-
May 29th, 2002, 12:18 AM
#8
Addicted Member
That which does not kill us, only makes us stronger. 
-
May 29th, 2002, 04:52 AM
#9
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.
-
May 29th, 2002, 09:20 AM
#10
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.
-
May 30th, 2002, 08:47 AM
#11
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.
-
May 30th, 2002, 09:51 AM
#12
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"
-
May 30th, 2002, 04:07 PM
#13
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.
-
May 30th, 2002, 05:32 PM
#14
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.
-
Jun 1st, 2002, 04:20 PM
#15
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|