Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello to all

I have a program written in C#, when I click on the Start button it disables all the GroupBoxes and all the buttons except the Stop button but something strange happens.

1/ All the labels (circled in pink on the picture) which are normally white but after the click on the Start button they become black

The "RichTextBox" and the "ComboBox" (circled in green on the picture) which are normally black background color but they also change color when I click on the Start button to become white

2/ Another thing, do you know why the warning message (circled in blue on the picture) repeats itself indefinitely at each data refresh? However the information message which is underneath written in green is displayed only once
(yet the code of the 2 messages are similar)

Here is the code to disable the GroupBox and buttons:

C#
 private void btnStart_Click(object sender, EventArgs e)
 {
    this.grSettings.Enabled = false;
    this.grTelegramSetting.Enabled = false;
    this.grTradeSetting.Enabled = false;
    this.grAccountSetting.Enabled = false;
    this.btnCreateOrder.Enabled = false;
    this.cbCheckBlance.Enabled = false;
    this.btnClosePositionTest.Enabled = false;
    this.btnStart.Enabled = false;
    this.btnStop.Enabled = true;
}


Here is the code of the warning messages:

C#
if (!tradeSetting.FlagAutoCreateOrderDCA)
  FMain.Log.Warn((object)"La création de l'ordre DCA arrêter, ne pas activer le DCA auto.");


Here is the code of the info messages:

C#
try
{
   FMain.Log.Info((object)"Début de la vérification auto.");


What I have tried:

Here is the screenshot:

<a href=""></a><a href="https://zupimages.net/up/23/20/d0xe.png">https://zupimages.net/up/23/20/d0xe.png</a>[<a href="https://zupimages.net/up/23/20/d0xe.png" target="_blank" title="New Window">^</a>]

Thanks
Posted
Updated 19-May-23 1:45am
Comments
[no name] 19-May-23 0:20am    
Disabling controls (.Enabled = false;) usually changes their color to indicate they are disabled; i.e. "greyed" out.
Member 15627495 19-May-23 1:54am    
maybe your RichTextox is not "transparent" as could be the others controls.

1 solution

Based on the code snippet you provided, there is no code that directly changes the color of any item. The code you provided only disables several controls when the button is clicked. Without further information or additional code, it is not possible to determine why the color of each item is being changed automatically.

There might be a possible solution though (disabling controls might be the issue)-

Default Behavior: It's possible that the controls you are using have a default behavior that changes their color when they are disabled.

Event Handlers: There might be event handlers or style-related code in other parts of your application that are triggered.

External Code: The behavior you are experiencing could be a result of code executed elsewhere in your application or in a separate component or library.

To change the behavior you can try the following -
using System.Drawing;

private void btnStart_Click(object sender, EventArgs e)
{
    // Disable controls
    this.grSettings.Enabled = false;
    this.grTelegramSetting.Enabled = false;
    this.grTradeSetting.Enabled = false;
    this.grAccountSetting.Enabled = false;
    this.btnCreateOrder.Enabled = false;
    this.cbCheckBlance.Enabled = false;
    this.btnClosePositionTest.Enabled = false;
    this.btnStart.Enabled = false;
    this.btnStop.Enabled = true;

    // Change colors
    this.grSettings.BackColor = Color.Red;
    this.grTelegramSetting.BackColor = Color.Blue;
    // Add similar lines for other controls you want to change the color of
}
 
Share this answer
 
Comments
QuickSilvain 2023 19-May-23 12:59pm    
Thank you very much, it works
Andre Oosthuizen 20-May-23 5:56am    
Pleasure

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900