WLAN eingebaut

This commit is contained in:
2024-12-08 10:57:37 +01:00
parent 26d0656fb5
commit 12d4a3a0f8
2 changed files with 241 additions and 26 deletions
+165 -25
View File
@@ -34,14 +34,26 @@
label1 = new Label();
tb_URL = new TextBox();
tabPage2 = new TabPage();
bt_createQRAdress = new Button();
tabPage3 = new TabPage();
radioButton_NoPass = new RadioButton();
radioButton_WEP = new RadioButton();
radioButton_WPA = new RadioButton();
label3 = new Label();
label2 = new Label();
textBox_password = new TextBox();
textBox_ssid = new TextBox();
checkBox_isHidden = new CheckBox();
bt_createQR_WIFI = new Button();
pb_QRC = new PictureBox();
button1 = new Button();
pb_icon = new PictureBox();
bt_clear_Icon = new Button();
bt_createQRAdress = new Button();
button_Save_QRCode = new Button();
tabControl1.SuspendLayout();
tabPage1.SuspendLayout();
tabPage2.SuspendLayout();
tabPage3.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pb_QRC).BeginInit();
((System.ComponentModel.ISupportInitialize)pb_icon).BeginInit();
SuspendLayout();
@@ -50,10 +62,11 @@
//
tabControl1.Controls.Add(tabPage1);
tabControl1.Controls.Add(tabPage2);
tabControl1.Controls.Add(tabPage3);
tabControl1.Location = new Point(12, 12);
tabControl1.Name = "tabControl1";
tabControl1.SelectedIndex = 0;
tabControl1.Size = new Size(420, 200);
tabControl1.Size = new Size(420, 609);
tabControl1.TabIndex = 0;
//
// tabPage1
@@ -64,16 +77,16 @@
tabPage1.Location = new Point(4, 24);
tabPage1.Name = "tabPage1";
tabPage1.Padding = new Padding(3);
tabPage1.Size = new Size(412, 172);
tabPage1.Size = new Size(412, 581);
tabPage1.TabIndex = 0;
tabPage1.Text = "tabPage1";
tabPage1.Text = "Link";
tabPage1.UseVisualStyleBackColor = true;
//
// bt_gen_QR_URL
//
bt_gen_QR_URL.Location = new Point(71, 91);
bt_gen_QR_URL.Location = new Point(6, 552);
bt_gen_QR_URL.Name = "bt_gen_QR_URL";
bt_gen_QR_URL.Size = new Size(254, 23);
bt_gen_QR_URL.Size = new Size(400, 23);
bt_gen_QR_URL.TabIndex = 2;
bt_gen_QR_URL.Text = "generiere QR";
bt_gen_QR_URL.UseVisualStyleBackColor = true;
@@ -82,7 +95,7 @@
// label1
//
label1.AutoSize = true;
label1.Location = new Point(34, 70);
label1.Location = new Point(6, 3);
label1.Name = "label1";
label1.Size = new Size(31, 15);
label1.TabIndex = 1;
@@ -90,9 +103,9 @@
//
// tb_URL
//
tb_URL.Location = new Point(71, 62);
tb_URL.Location = new Point(6, 21);
tb_URL.Name = "tb_URL";
tb_URL.Size = new Size(254, 23);
tb_URL.Size = new Size(400, 23);
tb_URL.TabIndex = 0;
tb_URL.Text = "https://www.youtube.com/watch?v=3XW7SxiJC-k";
//
@@ -102,23 +115,136 @@
tabPage2.Location = new Point(4, 24);
tabPage2.Name = "tabPage2";
tabPage2.Padding = new Padding(3);
tabPage2.Size = new Size(412, 172);
tabPage2.Size = new Size(412, 581);
tabPage2.TabIndex = 1;
tabPage2.Text = "tabPage2";
tabPage2.Text = "Adresse";
tabPage2.UseVisualStyleBackColor = true;
//
// bt_createQRAdress
//
bt_createQRAdress.Location = new Point(6, 552);
bt_createQRAdress.Name = "bt_createQRAdress";
bt_createQRAdress.Size = new Size(400, 23);
bt_createQRAdress.TabIndex = 0;
bt_createQRAdress.Text = "generiere QR";
bt_createQRAdress.UseVisualStyleBackColor = true;
bt_createQRAdress.Click += bt_createQRAdress_Click;
//
// tabPage3
//
tabPage3.Controls.Add(radioButton_NoPass);
tabPage3.Controls.Add(radioButton_WEP);
tabPage3.Controls.Add(radioButton_WPA);
tabPage3.Controls.Add(label3);
tabPage3.Controls.Add(label2);
tabPage3.Controls.Add(textBox_password);
tabPage3.Controls.Add(textBox_ssid);
tabPage3.Controls.Add(checkBox_isHidden);
tabPage3.Controls.Add(bt_createQR_WIFI);
tabPage3.Location = new Point(4, 24);
tabPage3.Name = "tabPage3";
tabPage3.Size = new Size(412, 581);
tabPage3.TabIndex = 2;
tabPage3.Text = "WLAN";
tabPage3.UseVisualStyleBackColor = true;
//
// radioButton_NoPass
//
radioButton_NoPass.AutoSize = true;
radioButton_NoPass.Location = new Point(69, 161);
radioButton_NoPass.Name = "radioButton_NoPass";
radioButton_NoPass.Size = new Size(94, 19);
radioButton_NoPass.TabIndex = 9;
radioButton_NoPass.TabStop = true;
radioButton_NoPass.Text = "No Password";
radioButton_NoPass.UseVisualStyleBackColor = true;
//
// radioButton_WEP
//
radioButton_WEP.AutoSize = true;
radioButton_WEP.Location = new Point(69, 136);
radioButton_WEP.Name = "radioButton_WEP";
radioButton_WEP.Size = new Size(49, 19);
radioButton_WEP.TabIndex = 8;
radioButton_WEP.TabStop = true;
radioButton_WEP.Text = "WEP";
radioButton_WEP.UseVisualStyleBackColor = true;
//
// radioButton_WPA
//
radioButton_WPA.AutoSize = true;
radioButton_WPA.Location = new Point(69, 111);
radioButton_WPA.Name = "radioButton_WPA";
radioButton_WPA.Size = new Size(50, 19);
radioButton_WPA.TabIndex = 7;
radioButton_WPA.TabStop = true;
radioButton_WPA.Text = "WPA";
radioButton_WPA.UseVisualStyleBackColor = true;
//
// label3
//
label3.AutoSize = true;
label3.Location = new Point(6, 76);
label3.Name = "label3";
label3.Size = new Size(57, 15);
label3.TabIndex = 6;
label3.Text = "Password";
//
// label2
//
label2.AutoSize = true;
label2.Location = new Point(6, 37);
label2.Name = "label2";
label2.Size = new Size(27, 15);
label2.TabIndex = 5;
label2.Text = "ssid";
//
// textBox_password
//
textBox_password.Location = new Point(69, 73);
textBox_password.Name = "textBox_password";
textBox_password.Size = new Size(326, 23);
textBox_password.TabIndex = 4;
//
// textBox_ssid
//
textBox_ssid.Location = new Point(39, 31);
textBox_ssid.Name = "textBox_ssid";
textBox_ssid.Size = new Size(277, 23);
textBox_ssid.TabIndex = 3;
//
// checkBox_isHidden
//
checkBox_isHidden.AutoSize = true;
checkBox_isHidden.Location = new Point(322, 33);
checkBox_isHidden.Name = "checkBox_isHidden";
checkBox_isHidden.Size = new Size(73, 19);
checkBox_isHidden.TabIndex = 2;
checkBox_isHidden.Text = "Versteckt";
checkBox_isHidden.UseVisualStyleBackColor = true;
//
// bt_createQR_WIFI
//
bt_createQR_WIFI.Location = new Point(6, 552);
bt_createQR_WIFI.Name = "bt_createQR_WIFI";
bt_createQR_WIFI.Size = new Size(400, 23);
bt_createQR_WIFI.TabIndex = 1;
bt_createQR_WIFI.Text = "generiere QR";
bt_createQR_WIFI.UseVisualStyleBackColor = true;
bt_createQR_WIFI.Click += bt_createQR_WIFI_Click;
//
// pb_QRC
//
pb_QRC.Location = new Point(16, 218);
pb_QRC.Location = new Point(517, 243);
pb_QRC.Name = "pb_QRC";
pb_QRC.Size = new Size(300, 300);
pb_QRC.Size = new Size(400, 400);
pb_QRC.SizeMode = PictureBoxSizeMode.Zoom;
pb_QRC.TabIndex = 1;
pb_QRC.TabStop = false;
//
// button1
//
button1.Location = new Point(434, 36);
button1.Location = new Point(787, 185);
button1.Name = "button1";
button1.Size = new Size(96, 23);
button1.TabIndex = 2;
@@ -129,7 +255,7 @@
// pb_icon
//
pb_icon.BorderStyle = BorderStyle.FixedSingle;
pb_icon.Location = new Point(536, 36);
pb_icon.Location = new Point(733, 12);
pb_icon.Name = "pb_icon";
pb_icon.Size = new Size(184, 168);
pb_icon.SizeMode = PictureBoxSizeMode.Zoom;
@@ -138,7 +264,7 @@
//
// bt_clear_Icon
//
bt_clear_Icon.Location = new Point(433, 65);
bt_clear_Icon.Location = new Point(786, 214);
bt_clear_Icon.Name = "bt_clear_Icon";
bt_clear_Icon.Size = new Size(97, 23);
bt_clear_Icon.TabIndex = 4;
@@ -146,21 +272,22 @@
bt_clear_Icon.UseVisualStyleBackColor = true;
bt_clear_Icon.Click += bt_clear_Icon_Click;
//
// bt_createQRAdress
// button_Save_QRCode
//
bt_createQRAdress.Location = new Point(6, 143);
bt_createQRAdress.Name = "bt_createQRAdress";
bt_createQRAdress.Size = new Size(164, 23);
bt_createQRAdress.TabIndex = 0;
bt_createQRAdress.Text = "generiere QR";
bt_createQRAdress.UseVisualStyleBackColor = true;
bt_createQRAdress.Click += bt_createQRAdress_Click;
button_Save_QRCode.Location = new Point(517, 649);
button_Save_QRCode.Name = "button_Save_QRCode";
button_Save_QRCode.Size = new Size(400, 23);
button_Save_QRCode.TabIndex = 5;
button_Save_QRCode.Text = "QR-Code speichern";
button_Save_QRCode.UseVisualStyleBackColor = true;
button_Save_QRCode.Click += button_Save_QRCode_Click;
//
// Main
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(929, 633);
ClientSize = new Size(929, 733);
Controls.Add(button_Save_QRCode);
Controls.Add(bt_clear_Icon);
Controls.Add(pb_icon);
Controls.Add(button1);
@@ -172,6 +299,8 @@
tabPage1.ResumeLayout(false);
tabPage1.PerformLayout();
tabPage2.ResumeLayout(false);
tabPage3.ResumeLayout(false);
tabPage3.PerformLayout();
((System.ComponentModel.ISupportInitialize)pb_QRC).EndInit();
((System.ComponentModel.ISupportInitialize)pb_icon).EndInit();
ResumeLayout(false);
@@ -190,5 +319,16 @@
private PictureBox pb_icon;
private Button bt_clear_Icon;
private Button bt_createQRAdress;
private TabPage tabPage3;
private Button bt_createQR_WIFI;
private Label label3;
private Label label2;
private TextBox textBox_password;
private TextBox textBox_ssid;
private CheckBox checkBox_isHidden;
private RadioButton radioButton_NoPass;
private RadioButton radioButton_WEP;
private RadioButton radioButton_WPA;
private Button button_Save_QRCode;
}
}
+76 -1
View File
@@ -6,6 +6,13 @@ namespace QR_Code_Generator
{
public partial class Main : Form
{
int pixlesPerModul = 20;
public enum EncryptionType
{
WPA,
WEP,
NoPass
}
public Main()
{
InitializeComponent();
@@ -31,7 +38,7 @@ namespace QR_Code_Generator
}
using (QRCode qrCode = new QRCode(qrCodeData))
{
Bitmap qrCodeImage = qrCode.GetGraphic(20, Color.Black, Color.White, icon, 25, 3);
Bitmap qrCodeImage = qrCode.GetGraphic(pixlesPerModul, Color.Black, Color.White, icon, 25, 3);
pb_QRC.Image = qrCodeImage;
}
}
@@ -75,5 +82,73 @@ namespace QR_Code_Generator
string strasse = string.Empty;
}
private void bt_createQR_WIFI_Click(object sender, EventArgs e)
{
EncryptionType selectedType =
radioButton_WPA.Checked ? EncryptionType.WPA :
radioButton_WEP.Checked ? EncryptionType.WEP :
EncryptionType.NoPass;
pb_QRC.Image = GenerateWiFiQRCode(textBox_ssid.Text, textBox_password.Text, checkBox_isHidden.Checked, selectedType);
}
public Bitmap GenerateWiFiQRCode(string ssid, string password, bool isHidden, EncryptionType encryptionType)
{
// Erstelle das WiFi-Payload basierend auf dem ausgewählten EncryptionType
PayloadGenerator.WiFi.Authentication authType = encryptionType switch
{
EncryptionType.WPA => PayloadGenerator.WiFi.Authentication.WPA,
EncryptionType.WEP => PayloadGenerator.WiFi.Authentication.WEP,
EncryptionType.NoPass => PayloadGenerator.WiFi.Authentication.nopass,
_ => throw new ArgumentOutOfRangeException(nameof(encryptionType), "Ungültiger Verschlüsselungstyp")
};
var wifiPayload = new PayloadGenerator.WiFi(ssid, password, authType, isHidden);
string payload = wifiPayload.ToString();
// Generiere den QR-Code
using var qrGenerator = new QRCodeGenerator();
var qrCodeData = qrGenerator.CreateQrCode(payload, QRCodeGenerator.ECCLevel.Q);
var qrCode = new QRCode(qrCodeData);
// Rückgabe als Bitmap
return qrCode.GetGraphic(20);
}
public void SaveQRCodeFromPictureBox(PictureBox pictureBox)
{
// Überprüfen, ob ein Bild in der PictureBox vorhanden ist
if (pictureBox.Image == null)
{
MessageBox.Show("Es befindet sich kein Bild in der PictureBox.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
// Zeige einen Speicherdialog an
using (SaveFileDialog saveFileDialog = new SaveFileDialog())
{
saveFileDialog.Filter = "PNG-Datei|*.png";
saveFileDialog.Title = "QR-Code speichern";
saveFileDialog.FileName = "QRCode.png";
// Wenn der Benutzer einen Dateipfad auswählt, speichere das Bild
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
try
{
pictureBox.Image.Save(saveFileDialog.FileName, System.Drawing.Imaging.ImageFormat.Png);
MessageBox.Show("QR-Code erfolgreich gespeichert!", "Erfolg", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
MessageBox.Show($"Fehler beim Speichern: {ex.Message}", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
}
private void button_Save_QRCode_Click(object sender, EventArgs e)
{
SaveQRCodeFromPictureBox(pb_QRC);
}
}
}