question

HemanthB-9452 avatar image
0 Votes"
HemanthB-9452 asked DanielZhang-MSFT edited

Add Alarm - C# Alarm

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


dotnet-csharp
image.png (141.7 KiB)
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi HemanthB-9452,
>> 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).
In order to find out the problem more accurately and create an alarm clock that is the same as before, please provide the relevant code for creating the alarm clock to reproduce the problem.
Best Regards,
Daniel Zhang

0 Votes 0 ·

For which control am I supposed to give the code. Below I have given the code for the "Add Alarm" button

Basically upon form load the "Create Alarm Panel" will not be visible. Only when the user clicks the "Add Alarm" button, the panel will be visible.

Code for Create Alarm button
private void button3_Click(object sender, EventArgs e) { createalarmpanel.Visible = true; }





0 Votes 0 ·

1 Answer

DanielZhang-MSFT avatar image
0 Votes"
DanielZhang-MSFT answered DanielZhang-MSFT edited

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




611.gif (160.3 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.