I am trying to create a program in windows forms that consist of 2 checkboxes for 2 textboxes to change the colors of their background and font color. Plus 3 buttons, forecolor, back color to store chosen color in, and an executable to check if any checkboxes are checked to use adequate colors to the selection. I have no problem with the logic for the executable button.
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 can't figure out the way to do so.. cuz anytime I'm trying to call 'variableColour s()' 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.
Code:
namespace Assignment1 { public partial class frmTaskB : Form { public frmTaskB() { InitializeComponent(); } bool btnForeIsChecked; bool btnBackIsChecked; public static void variableColours() { ColorDialog btnColour = new ColorDialog(); DialogResult chosenColour; btnColour.FullOpen = true; chosenColour = btnColour.ShowDialog(); if (chosenColour == DialogResult.Cancel) { return; } } public static void callColour(bool isChosen, string txtbColour, string useColour) { //variableColours(); if (isChosen) { txtbColour = useColour; } } private void btnExit_Click(object sender, EventArgs e) { // Application closing button this.Close(); } public void btnFont_Click(object sender, EventArgs e) { //validating if checkbox 'chkTextBox1' is checked by user if (chkTextBox1.Checked) { if (btnBackIsChecked) { //calling colour changing methods callColour(true, "txtText1.BackColor", "BackColor.Color"); } else if (btnForeIsChecked) { callColour(true, "txtText1.ForeColor", "ForeColor.Color"); } if (btnBackIsChecked && btnForeIsChecked) { callColour(true, "txtText1.BackColor", "BackColor.Color"); callColour(true, "txtText1.ForeColor", "ForeColor.Color"); } } //validating if checkbox 'chkTextBox2' is checked by user else if (chkTextBox2.Checked) { //calling colour changing methods //ForeColourDialogtxt2(); //BackColourDialogtxt2(); } //validating if checkbox 'chkTextBox1' and 'chkTextBox2' are checked by user if (chkTextBox1.Checked && chkTextBox2.Checked) { //calling colour changing methods /*ForeColourDialogtxt1(); BackColourDialogtxt1(); ForeColourDialogtxt2(); BackColourDialogtxt2();*/ } } private void btnFore_Click(object sender, EventArgs e) { variableColours(); btnForeIsChecked = true; } private void btnBack_Click(object sender, EventArgs e) { variableColours(); btnBackIsChecked = true; } } }
My 'callColour' function will ask if chosen, then in both strings txtbColour and useColour I would put the adequate property.
Comment