특수한 종류의 메시지 상자를 구성하는 클래스가 있습니다. 그 클래스에서 인수 중 하나는 내가 생성자에서 참조하는 변수입니다. 그러나 버튼을 클릭 할 때 생성자에서 인식 할 변수가 필요합니다.button_click 메서드 내에서 변수 값을 참조하는 방법
나는 메소드의 동작을 살펴보고 메소드가 변수의 값을 인식 할 수 있도록이를 이와 같이 참조해야한다는 것을 알게되었습니다. "buttonRight_click에 대한 어떠한 과부하은 System.EventHandler을 위임 일치하지 않습니다"
static void SetString1(ref string value)
{
if (value == "cat") // Test parameter value
{
Console.WriteLine("Is cat");
}
value = "dog"; // Assign parameter to new value
}
나는 같은 일을하고 싶어,하지만 난 변수 'variavelcaixa'를 참조하려고하면 버튼 클릭 방식으로, 그러나, 저를 줄 것이다. 이것이 의미하는 바는 무엇이며 어떻게 변수를 성공적으로 참조해야합니까?
private void buttonRight_Click(object sender, System.EventArgs e, ref int variavelcaixa)
{
if (checkBox1.Checked == true)
{ variavelcaixa = 1; }
else { variavelcaixa = 0; }
}
는 편집 : 다음 내가 특별한 메시지 상자 클래스에있는 코드는대로 : 생성자의
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
}
외부는에 버튼 클릭 방법
private void buttonRight_Click(object sender, System.EventArgs e)
{
if (checkBox1.Checked == true)
{ variavelcaixa = 1; }
else { variavelcaixa = 0; }
}
있다 메인 클래스 나는 단순히 메시지 박스 객체에 첨부 된 특정 변수와 함께 ref variavelcaixa를 추가한다.
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);
'ref'로 전달한 경우에도 실제로 변수에 할당하지 않습니다. 매개 변수와 변수에 동일한 이름을 사용하면 자동으로 값이 할당되지 않습니다. –
@ shree.pat18 그래서 어떻게 링크합니까? – ng80092b
'ShowDialog'에서 변수에 지정하십시오! –