Click to See Complete Forum and Search --> : Design-Time Property Only?
hellswraith
May 27th, 2002, 11:25 AM
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.
hellswraith
May 27th, 2002, 02:37 PM
Anyone create a user control yet? I really need to know this to finish my control, hence the bump up...
Tygur
May 27th, 2002, 10:58 PM
I may be wrong, but I don't believe the concept of design-time-only properties exists in VB.NET (or C#).
wolfofthenorth
May 27th, 2002, 11:42 PM
I could swear that I read how to test if your app is in design time. :rolleyes: , 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. :D
wolfofthenorth
May 28th, 2002, 06:20 PM
Here is a snippet that may help you. :cool:
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/
hellswraith
May 28th, 2002, 06:49 PM
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.
Tygur
May 28th, 2002, 09:17 PM
umm..
Unless I missed something, that code is for VB6 and it won't work in VB.NET.
wolfofthenorth
May 29th, 2002, 12:18 AM
Oops! :D I'm an idiot! :D :D
hellswraith
May 29th, 2002, 04:52 AM
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.
Tygur
May 29th, 2002, 09:20 AM
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.
hellswraith
May 30th, 2002, 08:47 AM
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.
Tygur
May 30th, 2002, 09:51 AM
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:
Me.TextBox1.Text = "Stuff"
hellswraith
May 30th, 2002, 04:07 PM
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)
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.
hellswraith
May 30th, 2002, 05:32 PM
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.
wolfofthenorth
Jun 1st, 2002, 04:20 PM
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. :D
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.