As per Prerak K's update comment (since deleted):
I guess I have not presented the question properly.
Situation is this: I want to load data into a global variable based on the value of a control. I don't want to change the value of a control from the child thread. I'm not going to do it ever from a child thread.
So only accessing the value so that corresponding data can be fetched from the database.
The solution you want then should look like:
UserContrl1_LOadDataMethod()
{
string name = "";
if(textbox1.InvokeRequired)
{
textbox1.Invoke(new MethodInvoker(delegate { name = textbox1.text; }));
}
if(name == "MyName")
{
// do whatever
}
}
Do your serious processing in the separate thread before you attempt to switch back to the control's thread. For example:
UserContrl1_LOadDataMethod()
{
if(textbox1.text=="MyName") //<<======Now it wont give exception**
{
//Load data correspondin to "MyName"
//Populate a globale variable List<string> which will be
//bound to grid at some later stage
if(InvokeRequired)
{
// after we've done all the processing,
this.Invoke(new MethodInvoker(delegate {
// load the control with the appropriate data
}));
return;
}
}
}
Using the HSVtoRGB
procedure found here, you can hook both your TrackBar
controls to the same event handler and use this code:
Private Sub tbHUE_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbHUE.Scroll, tbSaturation.Scroll
Dim r, g, b As Integer
HSVtoRGB(r, g, b, tbHUE.Value, tbSaturation.Value / 50, 255)
BackColor = Color.FromArgb(r, g, b)
End Sub
Edit: Here is the corrected procedure since the one in the link doesn't really follow best practices:
Private Sub HSVtoRGB(ByRef Red As Integer, ByRef Green As Integer, ByRef Blue As Integer, ByVal Hue As Double, ByVal Sat As Double, ByVal Value As Integer)
Dim i As Integer
Dim f As Double, p As Double, q As Double, t As Double
If Sat = 0 Then
Red = Value
Green = Value
Blue = Value
Exit Sub
End If
i = CInt(Hue) \ 60
Hue = Hue / 60
f = Hue - i
p = Value * (1 - Sat)
q = Value * (1 - Sat * f)
t = Value * (1 - Sat * (1 - f))
Select Case i
Case 0
Red = Value
Green = CInt(t)
Blue = CInt(p)
Case 1
Red = CInt(q)
Green = Value
Blue = CInt(p)
Case 2
Red = CInt(p)
Green = Value
Blue = CInt(t)
Case 3
Red = CInt(p)
Green = CInt(q)
Blue = Value
Case 4
Red = CInt(t)
Green = CInt(p)
Blue = Value
Case 5
Red = Value
Green = CInt(p)
Blue = CInt(q)
End Select
End Sub
Best Answer
I didn't try out the stereopsis program, but it looks to me like the ColorOracle program just takes a "snapshot" of the screen, re-colors it however, and then pops up a screen-size form with the image on it (which goes away when you click it).
This would be easy to do in .Net, but I'm guessing that you want your actual real live screen to change hue, and I'm not sure that's even possible (unless your monitor settings can be changed programatically in Windows).