-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
126 lines (104 loc) · 3.92 KB
/
MainWindow.xaml.cs
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using Microsoft.Win32;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using ZXing;
using ZXing.ZKWeb;
namespace GenerateQRCode
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
/**
*code behind for button to generate.
*Creates button based on text entered into textbox
**/
private void BtnConvert_Click(object sender, RoutedEventArgs e)
{
try
{
BitmapImage bimg = new BitmapImage();
List<BitmapImage> imageList = new List<BitmapImage>();
using (var ms = new MemoryStream())
{
ZXing.BarcodeWriter writer;
writer = new ZXing.BarcodeWriter() { Format = BarcodeFormat.QR_CODE };
writer.Options.Height = 175;
writer.Options.Width = 350;
writer.Options.PureBarcode = true;
System.Drawing.Image img = writer.Write(this.txtbarcodecontent.Text);
img.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg);
ms.Position = 0;
bimg.BeginInit();
bimg.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
bimg.CacheOption = BitmapCacheOption.OnLoad;
bimg.UriSource = null;
bimg.StreamSource = ms;
bimg.EndInit();
this.imgbarcode.Source = bimg;
this.tbkbarcodecontent.Text = "Enjoy your QR code!";
this.tbkbarcodecontent.FontSize = 19;
}
}
catch (Exception ex)
{
MessageBox.Show("To generate a code, first enter some content for it.", "Error"
, MessageBoxButton.OK, MessageBoxImage.Error);
}
}
public void DiceRollButton(object sender, RoutedEventArgs e)
{
var arlist1 = new List<string>();
int counter = 0;
// Read the file and display it line by line.
foreach (string line in System.IO.File.ReadLines("C:\\Users\\TDL_User\\Documents\\sites.txt"))
{
System.Console.WriteLine(line);
arlist1.Add(line);
counter++;
}
Random random = new Random();
int index = random.Next(arlist1.Count);
var name = arlist1[index].ToString();
arlist1.RemoveAt(index);
this.txtbarcodecontent.Text = name;
}
public void ClearcontentsButton(object sender, RoutedEventArgs e)
{
this.txtbarcodecontent.Text = null;
this.imgbarcode.Source = null;
this.tbkbarcodecontent.Text = null;
}
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
MessageBoxResult closingMessegeBoxResult = MessageBox.Show("If you close now, any unsaved codes will be lost. Still close?", "Unsaved ",
MessageBoxButton.OKCancel, MessageBoxImage.Warning);
if (closingMessegeBoxResult != MessageBoxResult.OK)
{
e.Cancel = true;
}
}
}
}