473,322 Members | 1,403 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Readonly at runtime

How do I make a property of a class Readonly but only at RUNTIME?

I want to be able to edit the value in a property browser after dragging my
component on a form but then not allow any code to change this property when
the code is running.

TIA
Nov 21 '05 #1
4 1203
"elziko" <el****@NOTSPAMMINGyahoo.co.uk> schrieb:
How do I make a property of a class Readonly but only at RUNTIME?


Untested:

\\\
Public Property...
...
Set(ByVal Value As Foo)
If Me.DesignMode Then
m_Foo = Value
End If
End Set
End Property
///

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #2
You could do this if the class is a control...

int _myInt;

public int MyInt
{
get{ return _myInt;}
set
{
if(DesignMode)
_myInt=value;
}
}

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:ee****************@TK2MSFTNGP15.phx.gbl...
How do I make a property of a class Readonly but only at RUNTIME?

I want to be able to edit the value in a property browser after dragging my component on a form but then not allow any code to change this property when the code is running.

TIA

Nov 21 '05 #3
Sorry, VB forum...

dim myInt as Integer
public property MyInt as Integer
get
return myInt
end get
set
if me.DesignMode then
myInt=value
end if
end set
end property
--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:ee****************@TK2MSFTNGP15.phx.gbl...
How do I make a property of a class Readonly but only at RUNTIME?

I want to be able to edit the value in a property browser after dragging my component on a form but then not allow any code to change this property when the code is running.

TIA

Nov 21 '05 #4
Elziko,
I would modify Herfried's slightly:

Public Property...
...
Set(ByVal Value As Foo)
If Me.DesignMode Then
m_Foo = Value
Else
Throw New NotSupportedException
End If
End Set
End Property

Which will give a glaring runtime error if you attempt to set the property.

Hope this helps
Jay

"elziko" <el****@NOTSPAMMINGyahoo.co.uk> wrote in message
news:ee****************@TK2MSFTNGP15.phx.gbl...
How do I make a property of a class Readonly but only at RUNTIME?

I want to be able to edit the value in a property browser after dragging
my
component on a form but then not allow any code to change this property
when
the code is running.

TIA

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Kavitha | last post by:
Hi Pals, I am confused between const and static readonly in C#. I want to know the difference between then. Please give me clear explanation. thanks in advance. -- Kavitha
1
by: blah | last post by:
if i change my rtb to readonly then when a user presses a keyboad key it 'bings'. how do i stop the noise evertime a user presses a key? thanks, Rob
19
by: cody | last post by:
Iam wondering what the benefit of using const over static readonly is. static readonly is a runtime constant and can be set once in the initializer or the static ctor, whereas const is suffering...
1
by: Danielb | last post by:
I need to create a read-only copy of Object X at run time, I know how to find the type of Object X (using GetType) but how do I go about creating a readonly copy of X? What I want to do is this:...
13
by: My4thPersonality | last post by:
I am reading something about the details of C#, and I came acros the statements readonly and const. I do not understand, it seems to be the same, what's the difference? Here is the text were it...
7
by: DareDevil | last post by:
I have written a method that should modify the folder path passed to it into one that exists and is selected by the user. It then returns a boolean depending on whether a folder path was selected by...
2
by: Amit | last post by:
Hello, I have a class where I store a lot of setting names. Right now they're all declared as consts : public const CurDoc as string = "CURRENT_DOCUMENT" From what I know about const, every...
5
by: John Smith | last post by:
Is it possible to set DataGrid's ReadOnly property to True/False at runtime? An example: <asp:datagrid id="dg1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn...
3
by: R.A.M. | last post by:
Hello, I am learning C#.NET and I donst understand difference between meaning and usage of "readonly" and "const" keywords. Could you explain me please. Thank you /RAM/
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.