mardi 17 avril 2018

C# - CheckChanged (checkbox) in usercontrol to use this statement in the Form

I'm having trouble with my C# project. I already checked all the posts about user controls, delegates, event handlers but I can't get it to work. I have a user control with 7 checkboxes in it and I want to use it about 10 times in my Form. I would like that when I check the first box of my user control, it increases the score of a value in my Form. Here is all my code so far (the user control is so messy I'm just desperate at this point and trying stuff). I'm so bad at C#...

Form1.cs:

Main window (first thing that appears)

Actual checkboxes system

namespace Test__windows_form_
{

public partial class Test : Form
{


    //Main window
    public Test()
    {
        InitializeComponent();
        this.FormBorderStyle = FormBorderStyle.None;
    }

    //Move the window with Title bar
    public const int WM_NCLBUTTONDOWN = 0xA1;
    public const int HT_CAPTION = 0x2;

    [DllImportAttribute("user32.dll")]
    public static extern int SendMessage(IntPtr hWnd, int Msg, int wParam, int lParam);
    [DllImportAttribute("user32.dll")]
    public static extern bool ReleaseCapture();

    private void logopanel_MouseDown(object sender, MouseEventArgs e)
    {
        if (e.Button == MouseButtons.Left)
        {
            ReleaseCapture();
            SendMessage(this.Handle, WM_NCLBUTTONDOWN, HT_CAPTION, 0);
        }
    }

    //Exit button
    private void close_Click(object sender, System.EventArgs e)
    {
        Close();
    }

    //Minimize button
    private void minimize_Click(object sender, System.EventArgs e)
    {
        WindowState = FormWindowState.Minimized;
    }


    private void Test_Load(object sender, EventArgs e)
    {


    }

    private void sidepanel_Paint(object sender, PaintEventArgs e)
    {

    }

    private void logopanel_Paint(object sender, PaintEventArgs e)
    {

    }

    private void intro_Paint(object sender, PaintEventArgs e)
    {

    }

    private void Questions1_Paint(object sender, PaintEventArgs e)
    {

    }


    //Tabs -> beginning
    private void bunifuFlatButton1_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Présentation;
    }

    //First question page
    private void start_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question1;
    }

    //Etc : it says where it gets us -> page of the tab control collection
    private void bunifuFlatButton5_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question2;


    }

    private void bunifuFlatButton6_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question3;
    }

    private void bunifuFlatButton7_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question4;
    }

    private void bunifuFlatButton8_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question5;
    }

    private void bunifuFlatButton9_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question6;
    }

    private void bunifuFlatButton10_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question7;
    }

    private void bunifuFlatButton11_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question8;
    }

    private void bunifuFlatButton12_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question9;
    }

    private void bunifuFlatButton13_Click(object sender, EventArgs e)
    {
        pages.SelectedTab = Question10;
    }


}
}

EIcheck.cs (user control):

User control about the EIscore (I have 4 scores so 4 user controls : the scores are EI / TF / JP / SN)

namespace Test__windows_form_
{


public partial class EIcheck : UserControl
{

    public EIcheck()
    {
        InitializeComponent();
    }

    public void EIcheck_Load(object sender, EventArgs e)
    {

    }

    int EIscore = 100;

    private void checkBox1_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox1.Checked)
        {
            EIscore -= 6;
        }
    }

    private void checkBox2_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox2.Checked)
        {
            EIscore -= 4;
        }
    }

    private void checkBox3_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox3.Checked)
        {
            EIscore -= 2;
        }
    }

    private void checkBox5_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox5.Checked)
        {
            EIscore += 2;
        }
    }

    private void checkBox6_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox6.Checked)
        {
            EIscore += 4;
        }
    }

    private void checkBox7_CheckedChanged(object sender, EventArgs e)
    {
        if (checkBox7.Checked)
        {
            EIscore += 6;
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        label1.Text = EIscore.ToString();
    }
}
}

My english level = utter garbage so tell me if it's not understandable




Aucun commentaire:

Enregistrer un commentaire