I have a class that constructs a special kind of message boxes. In that class one of the arguments is a variable which i'm refering in the constructor However I need that variable to be recognized out of the constructor, more specifically when i click a button.
I took a look at methods behavior and noticed that in order for a method to recognize a value from a variable i had to refer it like this.
static void SetString1(ref string value)
{
if (value == "cat") // Test parameter value
{
Console.WriteLine("Is cat");
}
value = "dog"; // Assign parameter to new value
}
I wanna do the same, but in a button click method, however if i try to refer the variable ´variavelcaixa´, it will give me "No overload for buttonRight_click matched delegate System.eventhandler". What does this means, and how should i sucessfully refer the variable?
private void buttonRight_Click(object sender, System.EventArgs e, ref int variavelcaixa)
{
if (checkBox1.Checked == true)
{ variavelcaixa = 1; }
else { variavelcaixa = 0; }
}
EDIT: The code i have in the special message box class is as follows:
public partial class BetterDialog : Form
{
public int variavelcaixa;
static public DialogResult ShowDialog(string title, string largeHeading, string smallExplanation,
string leftButton, string rightButton, Image iconSet, ref int variavelcaixa)
{
using (BetterDialog dialog = new BetterDialog(title, largeHeading, smallExplanation, leftButton,
rightButton, iconSet, ref variavelcaixa))
{
DialogResult result = dialog.ShowDialog();
return result;
}
}
/// <summary>
/// The private constructor. This is only called by the static method ShowDialog.
/// </summary>
private BetterDialog(string title, string largeHeading, string smallExplanation,
string leftButton, string rightButton, Image iconSet, ref int variavelcaixa)
{
this.Font = SystemFonts.MessageBoxFont;
this.ForeColor = SystemColors.WindowText;
InitializeComponent();
//A bunch of graphic design
}
outside of the constructor there is the button click method
private void buttonRight_Click(object sender, System.EventArgs e)
{
if (checkBox1.Checked == true)
{ variavelcaixa = 1; }
else { variavelcaixa = 0; }
}
On the main class i simply add the ref variavelcaixa, with a specific variable attached to the message box object
MsgBoxCheck.MessageBox dlg = new MsgBoxCheck.MessageBox();
string icone = "C:\\warning.png";
DialogResult result = BetterDialog.ShowDialog("Alert",
"main message in message box",
"some secondary message",
"", "Ok", System.Drawing.Bitmap.FromFile(icone), ref Variables.checkbox53naomostrarnovamente);