خرید بک لینک

Vote count: 0

I'm creating a user control in C# but I can't figure out how to do the event stuff. I want to change the backcolor property of the panel on mouse hover but it's not working.

Code:

public partial class QuestionList : UserControl
{
    public QuestionList()
    {
        InitializeComponent();
    }

    public struct QuestionListItem
    {
        public string Question { get; set; }
        public string Answer { get; set; }

        public QuestionListItem(string question, string answer)
        {
            Question = question;
            Answer = answer;
        }
    }

    public void Add(QuestionListItem questionlistItem)
    {
        Panel panel = new Panel();
        panel.MouseHover += Panel_MouseHover;

        panel.Dock = DockStyle.Top;

        Label label = new Label();
        label.MouseHover += Label_MouseHover;
        label.Dock = DockStyle.Fill;
        label.Text = questionlistItem.Question;

        panel.Controls.Add(label);

        Controls.Add(panel);
    }

    //Here
    private void Label_MouseHover(Object sender, EventArgs e)
    {
        Label label = (Label)sender;
        Panel panel = (Panel)label.Container;
        panel.BackColor = Color.Red;
    }
}

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 9 اسفند 1394 ساعت: 8:32

صفحه بندی