# SaaExtensions

{% hint style="warning" %}
This documentation is for SaaUI 1.1.0. If you using older version please update to latest version.
{% endhint %}

`Type`: `Class`

Contains useful extension methods that you may find helpful.

{% hint style="info" %}
Make sure you add namespace <mark style="color:blue;">using SaaUI;</mark>
{% endhint %}

`Target`: `string`

`GetSize(string, font)`  returns the size of the specified text when drawn with the specified font.

Usage:

```csharp
string str = "This is string";
Size strSize = str.GetSize(Font);

//OR

string str = "This is string";
Size strSize = SaaExtensions.GetSize(str, Font);
```

`Target`: `string[]`

`ToList(string[])`  converts string array to List.

Usage:

```csharp
string[] strArray = { "Cat", "Dog", "Goat" };
List<string> list = strArray.ToList();

//OR

string[] strArray = { "Cat", "Dog", "Goat" };
List<string> list = SaaExtensions.ToList(strArray);
```

`Target: SaaToast`

`GetSize(SaaToast)` Gets the total Size (including Offsets) of all toasts that are open and visible on the screen.

`GetSize(SaaToast, ToastPosition)` Gets the total Size (including Offsets) of all toasts that are open and visible on the screen in the specified position.

Usage:

```csharp
Size TotalSize = saaToast1.GetSize();
Size BottomLeftSize = saaToast1.GetSize(ToastPosition.BottomLeft);

//OR

Size TotalSize = SaaExtensions.GetSize(saaToast1);
Size BottomLeftSize = SaaExtensions.GetSize(saaToast1, ToastPosition.BottomLeft);
```

`Target: Color`

`ToHex(Color)` converts color to hexadecimal like `#FFFF00`.

`ToRGB(Color)` converts color to RGB like `RGB(255,255,0)`.

Usage:

```csharp
Color _color = Color.Red;
string hexColor = _color.ToHex();
string rgbColor = _clor.ToRGB();

//OR

Color _color = Color.Red;
string hexColor = SaaExtensions.ToHex(_color);
string rgbColor = SaaExtensions.ToRGB(_color);
```

`Property: string`

`NewID` generates globally unique ids with no duplicates possible.

Usage:

```csharp
string Id = SaaExtensions.NewID;
```

{% hint style="info" %}
The possibility of generating same Ids for lifetime globally is 0%. This means you can rely on it without fearing of getting duplicate ids even if you are generating billions of ids per second.

It uses several individually generated [**universally unique identifier** (**UUID**)](https://en.wikipedia.org/wiki/Universally_unique_identifier) + locally created custom identifiers.
{% endhint %}

`Target: Color`

`GetTransparency(Color, Percentage)` makes a color transparent in the given percentage.

Usage:

```csharp
Color _color = Color.Red;
Color halfTranparentColor = _color.GetTransparency(50);

//OR

Color _color = Color.Red;
Color halfTranparentColor = SaaExtensions.GetTransparency(_color, 50);
```

`Target: Control`

`LocationRelativeToForm(Control)` returns the location of a control relative to where it appears on the form. No matter if the control is inside other containers or nested containers. This is different from `Control.Location`. `Control.Location` returns the location of the control relative to its parent container(panel, form etc).&#x20;

Assuming you have a button in a panel on a form, see the illustrations below.

![](https://3593808699-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MeLJp7jLxK-XmIvfxh3%2F-Mgpue8_-FgiZGjv1slD%2F-Mgpy7a9QZ_6i32X3fOj%2FLocation.png?alt=media\&token=8b85b4cf-cf06-4bd4-a1d9-8df7ddb68158)

![](https://3593808699-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-MeLJp7jLxK-XmIvfxh3%2Fuploads%2Fz0hULMDy8oImFk7aTbFm%2FLocationRelativeToForm.png?alt=media\&token=41b7c328-dfa5-4b9c-bb1a-116df8845a3f)

Usage:

```csharp
point location = button1.LocationRelativeToForm();

//OR

point location = SaaExtensions.LocationRelativeToForm(button1);

```

`Target: Control`

`MouseLocation(Control)` returns mouse location of a control relative to the parent form. If the mouse pointer is outside the form then it returns `Point.Empty`.

Usage:

```csharp
point Mouselocation = button1.MouseLocation();

//OR

point Mouselocation = SaaExtensions.MouseLocation(button1);
```

`Target: Control`

`InnerMouseLocation(Control)` returns mouse location of a control relative to itself. If the mouse pointer is outside the control then it returns -1 (both X and Y).

Usage:&#x20;

```csharp
point InnerMouseLocation = button1.InnerMouseLocation();

//OR

point InnerMouseLocation = SaaExtensions.InnerMouseLocation(button1);
```

`Target: Control`

`SetDoubleBuffering(Control, true/false)` enables or disables doubleBuffering for a control.

Usage:&#x20;

```csharp
button1.SetDoubleBuffering(true/false);

//OR

SaaExtensions.SetDoubleBuffering(button1, true/false);

```

`Target: String[]`

`Contains(string[], item, caseSensitive)` checks whether string array has the specified item in its collection. `caseSensitive` is optional argument and tells whether case-sensitivity must be respected. *I.e* with `caseSensitive` set `true`, **Name** and **name** are not same.

Usage:&#x20;

```csharp
string[] str = { "Cat", "Dog", "Chicken"}; 
bool isContains = str.Contains("dog"); //returns true 
bool isContains = str.Contains("dog", true); //returns false

//OR

bool isContains = SaaExtensions.Contains(str, "dog", [ true/false]);
```

`Target: Control`

`CopyPropertiesFrom(ToControl, FromControl, PropertiesToCopy)` copies specified propeties from one control to another.&#x20;

`CopyPropertiesFromExcept(ToControl, FromControl, PropertiesNotToCopy)` copies all properties except the ones specified from one control to another.&#x20;

Imaging you have designed a beautiful button and you want another button to have same design. Instead of again designing that button, you can just copy from the other one. I.e **Color**, **Text**, **Icon** etc. Works with any control.

Usage:&#x20;

```csharp
button2.CopyPropertiesFrom(button1, {"BackColor", "Font", "Text"}); // Copies BackColor, Font and Text from button1 to button2. 
button2.CopyPropertiesFromExcept(button1, {"BackColor", "Text"}); // Copies all properties except BackColor,and Text from button1 to button2.

//OR

SaaExtensions.CopyPropertiesFrom(button2, button1, {"BackColor", "Font", "Text"}); 
SaaExtensions.CopyPropertiesFromExcept(button2, button1, {"BackColor", "Text"});
```

`Target: Object`

`GetProperty(object, propertyName)` returns property value of an object.

`SetProperty(object, propertyName, value)` sets value to a property of an object. An `object` can be anything like `class`, `Button`, `Form`. In the following example we assume the `object` to be a `Form`.

Usage:

```csharp
 myForm.SetProperty("BackColor", Color.Blue); 
 Color bc = (Color)myForm.GetProperty("BackColor");
 
//OR

SaaExtensions.SetProperty(myForm1, "BackColor", Color.Blue); 
Color bc = (Color)SaaExtensions.GetProperty(myForm1, "BackColor");
```
