|
Hi folks
I'm trying to work out if it's possible to make controls on a form transparent or not in the sense that i would like to be able to 'see through' a label control to partially read the text on other controls behind it.
By setting the Color.Transparent property i seem to pick up the color of the parent control but this doesn't allow me to read anything on the parent control - it just sets my child control to the same color.
I know this can be done with Forms by amending the Opacity property but is there any way this can be applied to controls on forms?
Cheers
|
|
|
|
|
|
Hello all,
Please show me where I can find out a drawing application that built by C# using GDI+. The source code is enclosed certainly.
Thanks.
|
|
|
|
|
there's a C#-scribble in my MSDN-documentation. maybe you also have one...
:wq
|
|
|
|
|
If I write following code:
int i = 1;
object o = i;
object a = o;
Is 'o' a reference to 'i' or
is 'o' a copy of 'i' ???
Is 'a' a reference to 'o' or
is 'a' a copy of 'o' ???
(Sorry for my bad english )
Thanks for every answer!
|
|
|
|
|
jb_dani wrote:
Sorry for my bad english
It's fine.
int i = 1;
object o = i;
Console.WriteLine(o.ToString());
i=10;
Console.WriteLine(o.ToString());
Console.ReadLine();
Output is: "1 \n 1"
The "i" value is copied to object "o", so there is no longer a reference between the two.
HTH
Cheers,
Simon
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
|
|
|
|
|
Thanks, but i a second question (sorry)...
What's with the following code:
Test t1 = new Test();
Test t2 = t1;
What is 't2'? Is it also a copy of t1 or a reference?
Thanks!!!
MFG Daniel.
|
|
|
|
|
I'm not sure what those classes are, but:
class Test1
{
public int _i =-1;
public Test1(int i)
{_i=i;}
public override string ToString()
{return _i.ToString();}
}
Test1 t1 = new Test1(100);
Test1 t2 = t1;
Console.WriteLine(t1.ToString());
t2._i=200;
Console.WriteLine(t2.ToString());
Console.WriteLine(t1.ToString());
Console.ReadLine(); Proves that t2 and t1 point to the same location in mem.
Does that help you?
Cheers,
Simon
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
|
|
|
|
|
I how can i make a full copy of a object, so that when i change the member in object 1, the member in object 2 will not be changed???? So, as a deep copy in c++!!!
MFG Daniel.
|
|
|
|
|
I'm pretty sure there's a copy and a clone method for this type of thing, but I have a feeling that you're going to have to implement it yourself.
I'll have a look though.
modified: do a search for ICloneable.Clone Method in MSDN. The ICloneable interface looks like what you're looking for.
HTH
Cheers,
Simon
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
|
|
|
|
|
To get a deep copy in C# do this:
public static object Clone(object objectToClone)
{
if (objectToClone == null)
{
throw new ArgumentNullException("objectToClone", "Parameter can not be null.");
}
BinaryFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream();
formatter.Serialize(stream, objectToClone);
stream.Seek(0, SeekOrigin.Begin);
return formatter.Deserialize(stream);
}
To deep copy an object with this method, use:
MyTest originalObject = new MyTest(a, lot, of, stuff);
MyTest cloneObject = (MyTest)Clone(originalObject);
The best part is that this is generic: extend MyTest with properties and you don't have to change the clone method.
Øyvind
|
|
|
|
|
SimonS wrote:
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
This beats them all.
|
|
|
|
|
O will be an Object that points to a new System.Int32 with the value of i, and if you change the value of O to 2, i will still be 1.
So the short answer is that it is a copy.
/Bo
|
|
|
|
|
And the follwing code:
Test t1 = new Test();
Test t2 = t1;
What is 't2'? Is it also a copy of t1 or a reference?
Thanks!!!
MFG Daniel.
|
|
|
|
|
Both t1 and t2 will be references to the new Test object created. No copy is made - and yes they are "pointers" - even if somebody tells you that C# ´don't have pointers.
/Bo
|
|
|
|
|
have you heard about boxing and unboxing?
i'm not 100% but pretty sure it goes like this:
* i is an int and placed on the stack.
* o is an object and therefore placed on the heap - i is "boxed" and the boxed copy is referenced by o - i believe, o is a COPY of i
* you can check with object.ReferenceEquals(a,o) that a and o point to the same object
as said before - i'm not 100 percent sure about it...(still a beginner to C# and .NET)
:wq
|
|
|
|
|
Oh boy am I tired, but glad I read your post because I was just getting ready to respond with the explanation you gave.
To my knowledge, any time you instansiate an object of a class in C# you are doing so on the heap, however when you use static methods, objects aren't required for this and therefore they process on the stack. Hopefully I am not mumbling here as I have been up for way to long.
HTH
Nick Parker
|
|
|
|
|
my experiences and deductions lead me to believe that any class inheriting from object is passed by reference.
READ MSDN
|
|
|
|
|
int and string both inherit from object, but are passed by val.
I think it has more to do with boxing than their hierarchy. I could be wrong though.
Cheers,
Simon
"Sign up for a chance to be among the first to experience the wrath of the gods.", Microsoft's home page (24/06/2002)
|
|
|
|
|
int is passed by value; string is passed by reference (but strings are immutable).
Any class that inherits from ValueType is passed by value; any other class is passed by reference. A struct is a special kind of class, it inherits from ValueType.
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
To clear it all up since there have been either incorrect or misleading statements mentioned.
o is a reference to a copy of i; a is a reference to whatever o is referencing.
Here is a small program which illustrates that
using System;
namespace test
{
public class Test
{
public static void Main(string [] args)
{
int a = 1;
object o = a;
object o2 = o;
Console.WriteLine("a = {0}, o = {1}, o2 = {2}", a, o, o2);
a = 2;
Console.WriteLine("a = {0}, o = {1}, o2 = {2}", a, o, o2);
o = 3;
Console.WriteLine("a = {0}, o = {1}, o2 = {2}", a, o, o2);
}
}
} The output should be
a = 1, o = 1, o2 = 1<br />
a = 2, o = 1, o2 = 1<br />
a = 2, o = 3, o2 = 1
HTH,
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Hi James, sorry, but i have a question to you about your sample program.
In your sample program is 'a' an 'int' with the value '1' and 'o' a reference to a copy of 'a', is that right? And 'o2' is a reference to 'o', is that also right?
But why is the last 'Console.WriteLine' Function the output value of 'o2' '1' and not '3' ???
I don't understand why the value of 'o2' is '1' and not '3' like the value of 'o'.
(Sorry for my bad english )
MFG Daniel.
|
|
|
|
|
jb_dani wrote:
Sorry for my bad english
Thats ok, I was able to read everything just fine
jb_dani wrote:
In your sample program is 'a' an 'int' with the value '1' and 'o' a reference to a copy of 'a', is that right?
Correct.
jb_dani wrote:
And 'o2' is a reference to 'o', is that also right?
What happens here would be much clearer if we had the C++ syntax.
object *o, *o2;
int i;
i = 1;
o = __box(i);
o2 = o;
i = 3;
o = __box(i);
If you don't understand C++ I hope the comments clarify it for you
James
"Java is free - and worth every penny." - Christian Graus
|
|
|
|
|
Thank you very much!
(I am happy that my english is not so bad!)
MFG Daniel.
|
|
|
|
|
I had no any c# experience, but some java
maybe sometime copy, sometime reference
eg, reference:
----------------------------------------------
CMyCustObj i = new CMyCustObj()
object o = i;
object a = o;
---------------------------------------------
you can compare the address of i,o,a
|
|
|
|