How to get current background color info from a form
-
I have a current form that is either lime or red. I think that (due to background worker threads), the best way to check the current state is to check the color of the form. How do I do this? I set it with
SetBackground(Color.Lime);
I saw the following threads, but they didn't seem to be the same thing, as far as I can tell. If it's the same, I'm not sure how to apply it to my situation. [^] http://www.masonmc.com/2008/getting-system-colors-in-c/[^]
-
I have a current form that is either lime or red. I think that (due to background worker threads), the best way to check the current state is to check the color of the form. How do I do this? I set it with
SetBackground(Color.Lime);
I saw the following threads, but they didn't seem to be the same thing, as far as I can tell. If it's the same, I'm not sure how to apply it to my situation. [^] http://www.masonmc.com/2008/getting-system-colors-in-c/[^]
MichCl wrote:
I have a current form that is either lime or red. I think that (due to background worker threads), the best way to check the current state is to check the color of the form.
The way I read this, the forms' color determines the "state"? Usually, we keep it in a separate variable, and set the color based on that. I'm having trouble understanding the question; am I correct in guessing that you want to "read/access" a property from a background-worker?
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
MichCl wrote:
I have a current form that is either lime or red. I think that (due to background worker threads), the best way to check the current state is to check the color of the form.
The way I read this, the forms' color determines the "state"? Usually, we keep it in a separate variable, and set the color based on that. I'm having trouble understanding the question; am I correct in guessing that you want to "read/access" a property from a background-worker?
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
I'm having trouble recording the new state because I'm on a different thread than I started on (using background worker). But I was able to set the color of the background on this thread, so I can wait until I exit the other thread, read the color of the background, and set my state variable. I've tried looking into setting variables created in different threads, but had trouble with what was suggested, and so far I've been able to avoid the issue. For this case, I program something and have success, so I set the form color for success. Then I have to record the number of success' or failures, and that's the problem. My success/failure count and the form field it's shown in were created in a different thread. Any idea how to get the form color so I can increment my counts based on that?
-
I'm having trouble recording the new state because I'm on a different thread than I started on (using background worker). But I was able to set the color of the background on this thread, so I can wait until I exit the other thread, read the color of the background, and set my state variable. I've tried looking into setting variables created in different threads, but had trouble with what was suggested, and so far I've been able to avoid the issue. For this case, I program something and have success, so I set the form color for success. Then I have to record the number of success' or failures, and that's the problem. My success/failure count and the form field it's shown in were created in a different thread. Any idea how to get the form color so I can increment my counts based on that?
MichCl wrote:
For this case, I program something and have success, so I set the form color for success. Then I have to record the number of success' or failures, and that's the problem. My success/failure count and the form field it's shown in were created in a different thread.
Let's call that thread the mainthread or the UI-thread. The "something" you speak of, is that running in it's own thread? You could poll a property in the form from a thread, but that requires locking -something that's always cool to avoid.
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
MichCl wrote:
For this case, I program something and have success, so I set the form color for success. Then I have to record the number of success' or failures, and that's the problem. My success/failure count and the form field it's shown in were created in a different thread.
Let's call that thread the mainthread or the UI-thread. The "something" you speak of, is that running in it's own thread? You could poll a property in the form from a thread, but that requires locking -something that's always cool to avoid.
Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]
-
I could avoid locking and thread jumping by just querying the color of the background. Any idea how to do it?
-
I have a current form that is either lime or red. I think that (due to background worker threads), the best way to check the current state is to check the color of the form. How do I do this? I set it with
SetBackground(Color.Lime);
I saw the following threads, but they didn't seem to be the same thing, as far as I can tell. If it's the same, I'm not sure how to apply it to my situation. [^] http://www.masonmc.com/2008/getting-system-colors-in-c/[^]
MichCl wrote:
I have a current form that is either lime or red. ... check the color of the form. How do I do this?
That doesn't smell right. The color of the form should be driven the state of an object, not the other way around. It seems what you want to do is to raise an event when the status of your object changes (presumably from "good" to "bad"). Any number of observers can listen for this change and respond to it an appropriate manner. /ravi
My new year resolution: 2048 x 1536 Home | Articles | My .NET bits | Freeware ravib(at)ravib(dot)com
-
I could avoid locking and thread jumping by just querying the color of the background. Any idea how to do it?
The Control.Invoke method has an object return type and so with an appropriate delegated method any information can be obtained from a Control. e.g.
private delegate Color ColourDelegate(Control c); private void GetColourInfo(Control c) { // With explicit method Color bgcol = (Color)c.Invoke(new ColourDelegate(GetColour), c); // or with an anonymous method Color bgcol2 = (Color)c.Invoke(new ColourDelegate(delegate { return c.BackColor; })); } private Color GetColour(Control ctrl) { return ctrl.BackColor; }
Alan.