Add Alarm - C# Alarm

Hemanth B 886 Reputation points
2021-06-09T06:29:09.727+00:00

Hi, I am creating an alarm in C# the Design is below in the image. So I added this functionality to the "Add Alarm" button: When that button is clicked, the "Create An Alarm" panel opens and users set their alarm. Now when they "Save" their alarm, the panel shrinks in size and settles in the top right corner of the app and some buttons and titles change (just like in Windows 10 Alarms & Clocks app). Now when the user saves an alarm and wants to add another alarm they will click "Add Alarm" right? I want the same "Create An Alarm" panel to appear without affecting previously saved Alarms. So when the User sets and saves their second alarm the second alarm panel should go and settle next to the previously saved alarms (just like in Windows 10 Alarms & Clocks app). Please help me with this.

103732-image.png

Developer technologies | C#
{count} votes

Accepted answer
  1. Daniel Zhang-MSFT 9,656 Reputation points
    2021-06-11T08:16:43.84+00:00

    Hi HemanthB-9452,
    You can save the alarm panel at the same time as the new setting alarm panel appears
    I made a simple code example you can refer to.

    private void Form1_Load(object sender, EventArgs e)  
    {  
        panel1.Visible = false;  
                    
    }  
      
    private void button1_Click(object sender, EventArgs e)  
    {  
        panel1.Visible = true;  
        panel1.BackColor = Color.Gray;  
        button2.Text = "Save";  
        panel1.Controls.Add(button2);             
                
    }  
    List<Panel> panels = new List<Panel>();  
    Panel pl;  
    private void CreateAlarm()   
    {  
        //creat another same alarm panel     
        Button b2 = new Button();  
        b2.Text = "Save";  
        b2.Location = new Point(0, 100);  
        b2.Click += new EventHandler(b2_Click);  
        DateTimePicker DateTimePicker = new DateTimePicker();  
        pl = new Panel();  
        pl.BackColor = Color.Red;  
        pl.Visible = true;  
        this.Controls.Add(pl);  
        panels.Add(pl);  
        pl.Controls.Add(b2);  
        pl.Controls.Add(DateTimePicker);  
        pl.Size = new Size(203, 234);  
        pl.Location = new Point(200, 200);  
      
    }  
    private void b2_Click(object sender, EventArgs e)  
    {  
        //when the User sets and saves their second alarm the second alarm panel should go and settle next to the previously saved alarms  
        //Meanwhile,the new alarm setting panel appears  
        pl.Size = new Size(panel1.Width, panel1.Height);  
        pl.Location = new Point(panel1.Location.X + (panel1.Width * panels.Count), panel1.Location.Y);  
        CreateAlarm();  
    }  
    private void button2_Click(object sender, EventArgs e)  
    {  
        panel1.Location = new Point(0, 0);  
        panel1.Size = new Size(200, 100);  
        CreateAlarm();  
    }  
    

    The result:
    104666-611.gif
    Best Regards,
    Daniel Zhang

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.