4g0tt3nSou1 4g0tt3nSou1 - 8 months ago 35
C# Question

How to set an object's transparency via a Slider

I'm attempting to learn C#. (Working with Visual Studio 2015, as a Window Application Project)
I am trying to set the opacity of the main window via a HBar Slider.

I first assumed I would set it as an int (the value of the sidebar), and set the opacity of the window via that value.

I am having issues calling the value of the opacity for the window.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Clock
public partial class root : Form
int Window_Transparency;
public root()

private void Form1_Load(object sender, EventArgs e)


private void sbar_transp_001_Scroll(object sender, ScrollEventArgs e)
sbar_transp_001.Value = Window_Transparency;
root.equals.opacity = Windows_Transparency;

Gives an error:

Error CS0119 'object.Equals(object)' is a method, which is not valid in the given context

I googled around, and found nothing that seemed relevant.

Please forgive my inexperience to what I assume is quite simple.
If somebody could point me in the proper way of setting values of objects in C#, I'd be appreciative. (Bonus points for the opacity, rather than the general syntax :D)


Remember: Opacity ranges from 0 to 1, so, if your control varies from 0 to 100, you need:

 this.Opacity = (trackBar1.Value/100);

(suppose you're using TrackBar control).