using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
namespace centersborki.page.c
{
public class CaptchaImage
{
public string Text
{
get { return this.text; }
}
public Bitmap Image
{
get { return this.image; }
}
public int Width
{
get { return this.width; }
}
public int Height
{
get { return this.height; }
}
private string text;
private int width;
private int height;
private string familyName;
private Bitmap image;
private Random random = new Random();
public CaptchaImage(string s , int width , int height)
{
this.text = s;
this.SetDimensions(width , height);
this.GenerateImage();
}
public CaptchaImage(string s , int width , int height , string familyName)
{
this.text = s;
this.SetDimensions(width , height);
this.SetFamilyName(familyName);
this.GenerateImage();
}
~CaptchaImage()
{
Dispose(false);
}
public void Dispose()
{
GC.SuppressFinalize(this);
this.Dispose(true);
}
protected virtual void Dispose(bool disposing)
{
if (disposing)
this.image.Dispose();
}
private void SetDimensions(int width , int height)
{
if (width <= 0)
throw new ArgumentOutOfRangeException("width" , width , "Argument out of range, must be greater than zero.");
if (height <= 0)
throw new ArgumentOutOfRangeException("height" , height , "Argument out of range, must be greater than zero.");
this.width = width;
this.height = height;
}
private void SetFamilyName(string familyName)
{
try
{
Font font = new Font(this.familyName , 12F);
this.familyName = familyName;
font.Dispose();
}
catch (Exception ex)
{
this.familyName = System.Drawing.FontFamily.GenericSerif.Name;
}
}
private void GenerateImage()
{
Bitmap bitmap = new Bitmap(this.width , this.height , PixelFormat.Format32bppArgb);
Graphics g = Graphics.FromImage(bitmap);
g.SmoothingMode = SmoothingMode.AntiAlias;
Rectangle rect = new Rectangle(0 , 0 , this.width , this.height);
HatchBrush hatchBrush = new HatchBrush(HatchStyle.SmallConfetti , Color.LightGray , Color.White);
g.FillRectangle(hatchBrush , rect);
SizeF size;
float fontSize = rect.Height + 1;
Font font;
do
{
fontSize--;
font = new Font(this.familyName , fontSize , FontStyle.Bold);
size = g.MeasureString(this.text , font);
} while (size.Width > rect.Width);
StringFormat format = new StringFormat();
format.Alignment = StringAlignment.Center;
format.LineAlignment = StringAlignment.Center;
GraphicsPath path = new GraphicsPath();
path.AddString(this.text , font.FontFamily , (int) font.Style , font.Size , rect , format);
float v = 4F;
PointF[] points =
{
new PointF(this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, this.random.Next(rect.Height) / v),
new PointF(this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v),
new PointF(rect.Width - this.random.Next(rect.Width) / v, rect.Height - this.random.Next(rect.Height) / v)
};
Matrix matrix = new Matrix();
matrix.Translate(0F , 0F);
path.Warp(points , rect , matrix , WarpMode.Perspective , 0F);
hatchBrush = new HatchBrush(HatchStyle.LargeConfetti , Color.LightGray , Color.DarkGray);
g.FillPath(hatchBrush , path);
int m = Math.Max(rect.Width , rect.Height);
for (int i = 0 ; i < (int) (rect.Width * rect.Height / 30F) ; i++)
{
int x = this.random.Next(rect.Width);
int y = this.random.Next(rect.Height);
int w = this.random.Next(m / 50);
int h = this.random.Next(m / 50);
g.FillEllipse(hatchBrush , x , y , w , h);
}
font.Dispose();
hatchBrush.Dispose();
g.Dispose();
this.image = bitmap;
}
}
}
1)Я соединил страницы через using как класс
2) У меня есть код на xaml
<Grid x:Name="formregistration" Background="#FFE5E5E5" DataContext="{StaticResource tblUserViewSource}">
<Grid x:Name="grid3" HorizontalAlignment="Left" Margin="24,20,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="User Name:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="userNameTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding UserName, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
</Grid>
<Grid x:Name="grid4" HorizontalAlignment="Left" Margin="10,57,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Email Address:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="emailAddressTextBox1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding EmailAddress, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
</Grid>
<Grid x:Name="grid5" HorizontalAlignment="Left" Margin="24,94,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Description:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="descriptionTextBox" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding Description, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
</Grid>
<Grid x:Name="grid6" HorizontalAlignment="Left" Margin="61,131,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="pass:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<TextBox x:Name="passTextBox1" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="3" Grid.Row="0" Text="{Binding pass, Mode=TwoWay, NotifyOnValidationError=true, ValidatesOnExceptions=true}" VerticalAlignment="Center" Width="120"/>
</Grid>
<Button x:Name="btnreg" Content="Button" HorizontalAlignment="Center" Margin="0,215,0,0" VerticalAlignment="Top" Width="122" Click="btnreg_Click" Height="37"/>
<Grid x:Name="grid7" DataContext="{StaticResource gorodViewSource}" HorizontalAlignment="Left" Margin="317,10,0,0" VerticalAlignment="Top" Height="218">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
</Grid>
<Grid x:Name="grid9" DataContext="{StaticResource gorodViewSource}" HorizontalAlignment="Left" Margin="289,20,0,0" VerticalAlignment="Top">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="name:" Grid.Column="0" HorizontalAlignment="Left" Margin="3" Grid.Row="0" VerticalAlignment="Center"/>
<ComboBox x:Name="nameComboBox" Grid.Column="1" DisplayMemberPath="name" HorizontalAlignment="Left" Height="Auto" ItemsSource="{Binding}" Margin="3" Grid.Row="0" VerticalAlignment="Center" Width="120">
<ComboBox.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel/>
</ItemsPanelTemplate>
</ComboBox.ItemsPanel>
</ComboBox>
</Grid>
<CheckBox Content="CheckBox" HorizontalAlignment="Left" Margin="229,184,0,0" VerticalAlignment="Top"/>
<Button x:Name="bref" Content="refrash" HorizontalAlignment="Left" Margin="357,160,0,0" VerticalAlignment="Top" Width="75" Click="Button_Click_1"/>
<Grid x:Name="bcap" HorizontalAlignment="Left" Height="61" Margin="289,94,0,0" VerticalAlignment="Top" Width="214"/>
</Grid>
HOW TO WRITE IN CONNECTION captcha XML??
capcha
|