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); } } } }