# Me vs. Self

When you add a control such as a `DesktopButton</api/user_interface/desktop/desktopbutton>` to a `DesktopWindow</api/user_interface/desktop/desktopwindow>`, an instance of the control is created for you and added to the Window. Code that is in the event handlers of a control added to the Window can refer to both its own properties and methods as well as the properties and methods of the window.

By default, all code without a prefix refers to the properties and method of the `DesktopWindow</api/user_interface/desktop/desktopwindow>` itself (or `WebPage</api/user_interface/web/webpage>` or `MobileScreen</api/user_interface/mobile/mobilescreen>`). You can use the `Self</api/language/self_keyword>` prefix to be explicit that you are referring to the DesktopWindow/DesktopContainer (or WebPage/WebContainer or MobileScreen/MobileContainer) or you can leave it off.

If you want to access a property or method of the control from the code in one of its event handlers on the DesktopWindow/WebPage/MobileScreen or on the DesktopContainer/WebContainer/MobileContainer (such as Button.Pressed), you must use the `Me</api/language/me>` prefix.

For example, consider the Visible property which is on both a Button and the Window itself. If you want to make the button invisible when it is clicked, you have to make sure you use the proper Visible property in the Pressed event handler. This code:

``` xojo
Visible = False ' Hides window
```

will hide the window and not the button because the Visible property defaults to Self, which is the window.

To access the Button's Visible property, do this:

``` xojo
Me.Visible = False ' Hides button
```

To be even clearer, you can use the Self keyword to specifically state that you want to use the Window property. To hide the window, you could instead write:

``` xojo
Self.Visible = False ' Hides window
```

Note that you might be tempted to refer to the window name directly and write code such as this:

``` xojo
Window1.Visible = False
```

**Do not do this!** Should you rename your window, this code will cause a compile error because the name is no longer valid.

If you use the `Me</api/language/me>` prefix outside of a control's event handler on a DesktopWindow/WebPage/MobileScreen or on a DesktopContainer/WebContainer/MobileContainer (such as in a method), then `Me</api/language/me>` will work the same as `Self</api/language/self_keyword>`. To prevent confusion, you should refrain from using the `Me</api/language/me>` prefix outside of control event handlers on DesktopWindows/WebPages/MobileScreens or DesktopContainer/WebContainer/MobileContainer.

When working with classes and subclasses you have added to your project, you should always use `Self</api/language/self_keyword>` (or nothing since Self is the default). This is true even if you create a control subclass and are implementing its event handlers. Again, you only use `Me</api/language/me>` when in the event handler for a control (or class) that is added to a DesktopWindow/WebPage/MobileScreen or if you use the `Me</api/language/me>` prefix outside of a control's event handler on a DesktopWindow/WebPage/MobileScreen or on a DesktopContainer/WebContainer/MobileContainer (such as in a method), then `Me</api/language/me>` will work the same as `Self</api/language/self_keyword>`. To prevent confusion, you should refrain from using the `Me</api/language/me>` prefix outside of control event handlers on DesktopWindows/WebPages/MobileScreens or on DesktopContainer/WebContainer/MobileContainer.

<div id="/getting_started/object-oriented_programming/me_vs._self/see_also">

<div class="seealso">

`DesktopWindow</api/user_interface/desktop/desktopwindow>`, `WebPage</api/user_interface/web/webpage>`, `MobileScreen</api/user_interface/mobile/mobilescreen>`, `DesktopContainer</api/user_interface/desktop/desktopcontainer>`, `WebContainer</api/user_interface/web/webcontainer>`, `MobileContainer</api/user_interface/mobile/mobilecontainer>` classes; `Me</api/language/me>`, `Self</api/language/self_keyword>` commands

</div>

</div>
