123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- using System;
- using System.Collections.Generic;
- using ReactiveUI;
- using Avalonia.Media;
- using Avalonia.Controls.Shapes;
- using Avalonia.Threading;
- using AvaloniaApplication4.Models;
- using Avalonia.Controls;
- using static System.Net.Mime.MediaTypeNames;
- using Avalonia.Controls.Documents;
- namespace AvaloniaApplication4.ViewModels
- {
- public class Page1ViewModel : ReactiveObject
- {
- DispatcherTimer timer = new DispatcherTimer(); // ñîçäàíèå îáúåêòà äëÿ òàéìåðà
- // êîíñòðóêòîð
-
-
- public int count = 0;
- public string loginn = "";
- public int pass = 0;
- public string result = "";
- public string result1 = "";
- bool _isButtonVisible = true;
- bool _isButtonVisible1 = false;
- bool _isButtonVisible2 = false;
- bool _tbvis = false;
- public char[] stringChars;
- public string Login
- {
- get { return loginn; }
- set
- {
- this.RaiseAndSetIfChanged(ref loginn, value);
- }
- }
- public int Password
- {
- get { return pass; }
- set
- {
- this.RaiseAndSetIfChanged(ref pass, value);
- }
- }
- public string Res
- {
- get { return result; }
- set { this.RaiseAndSetIfChanged(ref result, value); }
- }
- public bool IsButtonVisible
- {
- get => _isButtonVisible;
- set => this.RaiseAndSetIfChanged(ref _isButtonVisible, value);
- }
- public bool IsButtonVisible1
- {
- get => _isButtonVisible1;
- set => this.RaiseAndSetIfChanged(ref _isButtonVisible1, value);
- }
- public bool IsButtonVisible2
- {
- get => _isButtonVisible2;
- set => this.RaiseAndSetIfChanged(ref _isButtonVisible2, value);
- }
-
-
- public bool IsTBvis
- {
- get => _tbvis;
- set => this.RaiseAndSetIfChanged(ref _tbvis, value);
- }
-
- Canvas _canva;
- public Canvas Canva
- {
- get => _canva;
- set => this.RaiseAndSetIfChanged(ref _canva, value);
- }
-
- private FontStyle GetRandomFontStyle()
- {
- Random random = new Random();
- FontStyle style = FontStyle.Normal;
- int font_ss = random.Next(1,2);
- if (font_ss == 1)
- {
- style = FontStyle.Italic;
- }
- else
- {
- style = FontStyle.Normal;
- }
-
- return style;
- }
- private FontWeight GetRandomFontW()
- {
- Random random = new Random();
- FontWeight style = FontWeight.Regular;
- int font_ss = random.Next(1, 2);
- if (font_ss == 1)
- {
- style = FontWeight.Bold;
- }
- else
- {
- style = FontWeight.Regular;
- }
- return style;
- }
- public void CreateCaptha()
- {
- Random rnd = new Random();
- SolidColorBrush color = new SolidColorBrush(Color.FromRgb(Convert.ToByte(rnd.Next(256)), Convert.ToByte(rnd.Next(255)), Convert.ToByte(rnd.Next(255))));
- FontStyle[] fs = new FontStyle[2] { FontStyle.Normal, FontStyle.Italic};
- FontWeight[] fw = new FontWeight[2] { FontWeight.Bold, FontWeight.Normal };
- int a;
- Canvas canvas = new Canvas()
- {
- Width = 400,
- Height = 400,
- Background = color
- };
- // ãåíåðèðóåì ëèíèè
- var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- var rs = rnd.Next(7, 11);
- stringChars = new char[rs];
- var random = new Random();
- int fixedLetterSpacing = 30;
- int font_ss = rnd.Next(0, 3);
- for (int i = 0; i < stringChars.Length; i++)
- {
- stringChars[i] = chars[random.Next(chars.Length)];
- }
- int min = 50;
- var finalString = new String(stringChars);
- for (int i = 0; i < stringChars.Length; i++)
- {
-
- TextBlock number = new TextBlock()
- {
- Text = stringChars[i].ToString(),
- FontSize = 40,
- Foreground = Brushes.Black,
- Padding = new Avalonia.Thickness(0, 0, 0, 0),
- Margin = new Avalonia.Thickness(min, rnd.Next(150, 250), 0, 0), // äîáàâëÿåì îòñòóïû
- FontStyle = fs[rnd.Next(0, 2)],
- FontWeight = fw[rnd.Next(0, 2)]
- };
- min += fixedLetterSpacing;
- canvas.Children.Add(number);
- }
- for (int i = 0; i < 20; i++)
- {
- Line line = new Line()
- {
- StartPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
- EndPoint = new Avalonia.Point(rnd.Next(400), rnd.Next(400)),
- Stroke = new SolidColorBrush(Color.FromArgb(128, 255, 255, 255)),
- StrokeThickness = 3
- };
- canvas.Children.Add(line);
- }
- Canva = canvas; // ïåðåäà÷à ñîçäàííîãî Canvas ñâ-âó Canvas äëÿ îòîáðàæåíèÿ
- }
- public string enteredtext = "";
- public string Enteredt
- {
- get { return enteredtext; }
- set
- {
- this.RaiseAndSetIfChanged(ref enteredtext, value);
- }
- }
- public string Res1
- {
- get { return result1; }
- set { this.RaiseAndSetIfChanged(ref result1, value); }
- }
- public bool _Enabled = true;
- public bool Enabled
- {
- get
- {
- return _Enabled;
- }
- set
- {
- this.RaiseAndSetIfChanged(ref _Enabled, value);
- }
- }
-
-
- }
- }
|