-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpdateForm.cs
More file actions
106 lines (94 loc) · 4 KB
/
Copy pathUpdateForm.cs
File metadata and controls
106 lines (94 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
using System;
using System.Drawing;
using System.Windows.Forms;
using System.Diagnostics;
namespace OmniTools
{
public class UpdateForm : Form
{
private Label lblTitle;
private Label lblMessage;
private Button btnUpdate;
private Button btnCancel;
// Vous pouvez récupérer la version à afficher en paramètre
private readonly string _latestVersion;
public UpdateForm(string latestVersion)
{
_latestVersion = latestVersion;
InitializeComponent();
}
private void InitializeComponent()
{
// Paramètres de base de la fenêtre "UpdateForm"
this.Text = "Mise à jour disponible";
this.Size = new Size(500, 250);
this.StartPosition = FormStartPosition.CenterScreen;
this.FormBorderStyle = FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
// Création d'un panel principal
var mainPanel = new TableLayoutPanel();
mainPanel.Dock = DockStyle.Fill;
mainPanel.ColumnCount = 1;
mainPanel.RowCount = 3;
mainPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 30F)); // pour le titre
mainPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 40F)); // pour le message
mainPanel.RowStyles.Add(new RowStyle(SizeType.Percent, 30F)); // pour les boutons
this.Controls.Add(mainPanel);
// Label de titre
lblTitle = new Label();
lblTitle.Text = "Nouvelle version disponible !";
lblTitle.Font = new Font("Arial", 16, FontStyle.Bold);
lblTitle.ForeColor = Color.Navy;
lblTitle.Dock = DockStyle.Fill;
lblTitle.TextAlign = ContentAlignment.MiddleCenter;
mainPanel.Controls.Add(lblTitle, 0, 0);
// Label de message
lblMessage = new Label();
lblMessage.Text = $"Une nouvelle version ({_latestVersion}) d’OmniTools est disponible.\n" +
"Voulez-vous la télécharger et l’installer maintenant ?";
lblMessage.Font = new Font("Arial", 11);
lblMessage.TextAlign = ContentAlignment.MiddleCenter;
lblMessage.Dock = DockStyle.Fill;
lblMessage.AutoSize = false;
mainPanel.Controls.Add(lblMessage, 0, 1);
// Panel pour les boutons
var buttonsPanel = new FlowLayoutPanel();
buttonsPanel.Dock = DockStyle.Fill;
buttonsPanel.FlowDirection = FlowDirection.RightToLeft;
buttonsPanel.Padding = new Padding(10);
mainPanel.Controls.Add(buttonsPanel, 0, 2);
// Bouton "Mettre à jour"
btnUpdate = new Button();
btnUpdate.Text = "Mettre à jour";
btnUpdate.Size = new Size(120, 35);
btnUpdate.Click += BtnUpdate_Click;
buttonsPanel.Controls.Add(btnUpdate);
// Bouton "Non merci"
btnCancel = new Button();
btnCancel.Text = "Non merci";
btnCancel.Size = new Size(120, 35);
btnCancel.Click += BtnCancel_Click;
// On l’ajoute après le bouton "Mettre à jour" (mais l’affichage est inversé à cause de FlowDirection)
buttonsPanel.Controls.Add(btnCancel);
}
/// <summary>
/// L’utilisateur clique sur "Mettre à jour"
/// </summary>
private void BtnUpdate_Click(object sender, EventArgs e)
{
// On renvoie un DialogResult.OK pour signaler qu’on veut mettre à jour
this.DialogResult = DialogResult.OK;
this.Close();
}
/// <summary>
/// L’utilisateur clique sur "Non merci"
/// </summary>
private void BtnCancel_Click(object sender, EventArgs e)
{
// On renvoie un DialogResult.Cancel
this.DialogResult = DialogResult.Cancel;
this.Close();
}
}
}