event for Size structure 
Author Message
 event for Size structure

Hi, I have a Size object that is exposed publicly from my class, how can I
be notified when user change the width or height property of that size
object?

Thanks
Tony



Sun, 22 May 2005 15:15:01 GMT  
 event for Size structure
You might have to wrap it in a class to control access to the structure.
That way you can expose any events that you want.


Quote:
> Hi, I have a Size object that is exposed publicly from my class, how can I
> be notified when user change the width or height property of that size
> object?

> Thanks
> Tony



Sun, 22 May 2005 15:45:33 GMT  
 event for Size structure
Hi,

You can make it property and run your code when it is set.
Here's the code:

public class MyClass
{
    private Size m_Size;

    public Size mySize
    {
        set
        {
            m_Size = value;
            // put your code here
        }

        get
        {
            return m_Size;
        }
    }

Quote:
}

--
Cheers,
Adi


Quote:
> Hi, I have a Size object that is exposed publicly from my class, how can I
> be notified when user change the width or height property of that size
> object?

> Thanks
> Tony



Sun, 22 May 2005 20:51:29 GMT  
 event for Size structure
This doesn't work if they do:

MyClass myc = new MyClass();

myc.Size.X = 200;

That's a get_Size() call, but there's no set_Size() call.

-c


Quote:
> Hi,

> You can make it property and run your code when it is set.
> Here's the code:

> public class MyClass
> {
>     private Size m_Size;

>     public Size mySize
>     {
>         set
>         {
>             m_Size = value;
>             // put your code here
>         }

>         get
>         {
>             return m_Size;
>         }
>     }
> }

> --
> Cheers,
> Adi



> > Hi, I have a Size object that is exposed publicly from my class, how
can I
> > be notified when user change the width or height property of that
size
> > object?

> > Thanks
> > Tony



Sun, 22 May 2005 23:41:38 GMT  
 event for Size structure


Quote:
> This doesn't work if they do:

> MyClass myc = new MyClass();

> myc.Size.X = 200;

> That's a get_Size() call, but there's no set_Size() call.

There is an answer to this: use a struct. That is, the static
type of "MyClass.Size" should be a struct. A good candidate
here might be System.Drawing.Size.

Structs do not permit aliasing. What "myc.Size"
returns is a copy of the original struct. Any action you take
against it can affect only the copy, not the origional.

Furthermore, the compiler is smart enough to flag field
and property set operations against such a temporary
copy as errors. So in your example code, the last
line would be an error.

If you called a method, though, the compiler
would not complain. Even so, the Size kept inside
of MyClass would be unaffected; the method would
run against a local copy only. Again, the members
of 'myc' would be safe.

This means that if 'Size' returns a struct type, then
the only way the underlying field in'myc' can be
altered is by a set_Size() call.

Structs a very handy this way. The copy behavior,
I've noticed, also applies to reading from a readonly
field, though the docs do not seem to document this.



Mon, 23 May 2005 07:45:48 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Find size of variable size structure?

2. Structures of indefinite size

3. Structure problem - Size not known???

4. how to find the size of a private structure

5. how to copy a structure of record to another structure with type,size in the menber of structure...

6. binary file and different size of structures

7. zero sized structures

8. Help Me !! some strange in a structure size

9. Size of structure containing char fields

10. size of structure

11. Size of structures

12. The size of the structure array

 

 
Powered by phpBB® Forum Software