I have Form1 and Form2 simultaneously active, Form2 has a TabControl and I want button click event on Form1 to change 'Enable' property of tabControl on Form2

TabControl on Form2 is set to `tabControl1.enabled = false;` and Form1 acts as a login form for Form2, so I need a Login button on Form1 to enable 'tabControl1' on Form2

I can access the property by setting `private System.Windows.Forms.TabControl tabControl1;` to 'Public', still, using the following on button click event on Form1 doesn't do anything.

```
Form2 formnew2 = new Form2();
formnew2.tabControl1.Enabled = true;

```

Can someone please provide a simple example to help me understand or link to a previously answered question
['https://Stackoverflow.com/questions/34459128', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/2095012/']
You get this error since `xxxSlider.value` is of type `Float`, whereas `UIColor` initialiser calls for type `CGFloat` for all four arguments.

You can redeem this error by changing the line into:

```
colorView.backgroundColor = UIColor(red: CGFloat(redSlider.value), green: CGFloat(greenSlider.value), blue: CGFloat(blueSlider.value), alpha: 1.0)

```

However, to achieve the goal of your program, there are more issues that needs to be addressed. I'll go through these below.

---

First of all, you have one `@IBAction` as well as one `@IBOutlet` connected to each slider. With former (action), the latter is really not needed. Hence, remove the `@IBOutlet` connections (code as well as connections)

```
@IBOutlet weak var redSlider: UISlider! // remove (also remove connection)
@IBOutlet weak var greenSlider: UISlider! // ...
@IBOutlet weak var blueSlider: UISlider! // ...

```

Now, in your `@IBAction`:s, you define a local variable that is never used

```
var red = CGFloat(sender.value) // in @IBAction func redValueChanged(...
var green = CGFloat(sender.value) // ...
var blue = CGFloat(sender.value) // ...

```

In their current form, you don't need these, so remove these also.

Instead, in the scope of the class (see full program below), declare three class variables to hold the current value of each slide (note: these are not to be defined *within* a class method/action/function). Moreover, let these be of type `CGFloat` rather than `Float`, as initialiser of `UIColor` that we use to change background colour takes arguments of type `CGFloat`:

```
var redValue: CGFloat = 0.5 // 0.5: middle slider (init)
var greenValue: CGFloat = 0.5
var blueValue: CGFloat = 0.5

```

In your `@IBAction` closures, change these class variables by the `sender.value` (which holds slider value). After update of variable value, call your `displayColors()` method (that we will look at shortly).

```
// Actions
@IBAction func redValueChanged(sender: UISlider) {
    redValue = CGFloat(sender.value)
    displayColors()
}

@IBAction func greenValueChanged(sender: UISlider) {
    greenValue = CGFloat(sender.value)
    displayColors()
}

@IBAction func blueValueChanged(sender: UISlider) {
    blueValue = CGFloat(sender.value)
    displayColors()
}

```

Your `displayColors()` can be simplified simply to:

```
func displayColors() {
    colorView.backgroundColor = UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1.0)
}

```

Finally, not that the overridden method `viewDidLoad()` is only called once when the ViewController is loaded, so in this case, you can see this as an initialiser for your ViewController. The only thing we want to do here is set the default colour: RGB(0.5, 0.5, 0.5) = gray.

```
override func viewDidLoad() {
    super.viewDidLoad()

    // Initial BG color (viewDidLoad() loads only once when ViewController view loads)
    colorView.backgroundColor = UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1.0)
}

```

And we're done!

---

Wrapping it up, your ViewController class should now look like the following

```
import UIKit

class ViewController: UIViewController {

    // Properties
    var redValue: CGFloat = 0.5
    var greenValue: CGFloat = 0.5
    var blueValue: CGFloat = 0.5

    @IBOutlet weak var colorView: UIView!

    // Actions
    @IBAction func redValueChanged(sender: UISlider) {
        redValue = CGFloat(sender.value)
        displayColors()
    }

    @IBAction func greenValueChanged(sender: UISlider) {
        greenValue = CGFloat(sender.value)
        displayColors()
    }

    @IBAction func blueValueChanged(sender: UISlider) {
        blueValue = CGFloat(sender.value)
        displayColors()
    }

    func displayColors() {
        colorView.backgroundColor = UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1.0)
    }

    override func viewDidLoad() {
        super.viewDidLoad()

        // Initial BG color (viewDidLoad() loads only once when ViewController view loads)
        colorView.backgroundColor = UIColor(red: redValue, green: greenValue, blue: blueValue, alpha: 1.0)
    }
}

```

Running your app produces the following behaviour:

[![enter image description here](https://i.stack.imgur.com/jJGuP.gif)](https://i.stack.imgur.com/jJGuP.gif)
In my app using Swift 4, I am using this to convert Float to CGFloat:

```
let slider = sender as? UISlider
let val = CGFloat((slider?.value)!)

```

And then using the variable val as needed, which in my case is for hue, saturation and brightness, e.g.

```
coolButton.saturation = val

```