C# how to re-use variable from a button click event (ColorDialog)

  c++, forms, windows

I am trying to create a program in windows forms that consists of 2 check boxes for 2 textboxes to change colors of their background and font color. Plus 3 buttons, fore color, back color to store chosen color in and an executable to check if any checkboxes are checked to use adequate colours to the selection. I have no problem with the logic for the executable button.

    public void variableColours()
    {
        ColorDialog btnColour = new ColorDialog();
        DialogResult chosenColour;

        btnColour.FullOpen = true;
        chosenColour = btnColour.ShowDialog();

        if (chosenColour == DialogResult.Cancel)
        {
            return;
        }

    }
    public void callColour(bool isChosen, string txtbColour, string useColour)
    {
        //variableColours();
        if (isChosen)
        {
            txtbColour = useColour;
        }
    }```

I need to store colors chosen by the user from the ColorDialog when he clicks on either fore/back so then I can take the values from the button and execute a change of background and/or font color, but cant figure out the way to do so.. cuz anytime I’m trying to call ‘variableColours()’ it keeps asking the user to choose the color.
My ‘callColour’ function will ask if chosen, then in both strings txtbColour and useColour I would put the adequate property.

Please help, I’ve been stuck on this one for a couple days trying to find solution.

Source: Windows Questions

LEAVE A COMMENT