Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello every one,

Is there anyway to display a reCaptcha in a ppictur ebox in winforms?

I tried to,but the web browser could not load the scripts that make a recaptcha
like this :
JavaScript
<script src="http://www.google.com/recaptcha/api/js/recaptcha.js" type="text/javascript">

I want to get the reCaptcha of a website to login that website with a winform application.


Thanks for your help.
Posted
Updated 10-Mar-12 5:53am
v3

Have a look at this.
The below sample code works for images
try it out

http://www.dreamincode.net/forums/topic/240108-captcha-code-in-c%23-windows-application/[^]
 
Share this answer
 
C#
string code;

private void CreateImage()
{
	code = GetRandomText();

	Bitmap bitmap = new Bitmap(200, 50, PixelFormat.Format32bppArgb);
	Graphics g = Graphics.FromImage(bitmap);
	Pen pen = new Pen(Color.Yellow);
	Rectangle rect = new Rectangle(0, 0, 200, 50);
	SolidBrush b = new SolidBrush(Color.Black);
	SolidBrush blue = new SolidBrush(Color.Blue);
	int counter = 0;

	g.DrawRectangle(pen, rect);
	g.FillRectangle(b, rect);

	for (int i = 0; i < code.Length; i++)
	{
		g.DrawString(code[i].ToString(), new Font("Verdena", 10 + rand.Next(14, 18)), blue, new PointF(10 + counter, 10));

		counter += 20;

		int red = 0;
		int white = 11;

		while (white <= 100)
		{
			g.FillRectangle(Brushes.White, 0, red, 200, 10);
			g.FillRectangle(Brushes.White, 0, white, 200, 10);

			red += 20;
			white += 20;
		}
	}

	DrawRandomLines(g);

	pictureBox1.Image = bitmap;

/*	if (File.Exists("bitmap"))
	{
		try
		{
			File.Delete("bitmap");
			bitmap.Save("bitmap");
		}
		catch
		{
		}
	}
*/

//	g.Dispose();
//	bitmap.Dispose();
//	pictureBox1.Image = Image.FromFile(bitmap);
}

private void DrawRandomLines(Graphics g)
{
	SolidBrush green = new SolidBrush(Color.Green);

	for (int i = 0; i < 20; i++)
	{
		g.DrawLines(new Pen(green, 2), GetRandomPoints());
	}
}

private Point[] GetRandomPoints()
{
	Point[] points = { new Point(rand.Next(10, 150), rand.Next(10, 150)), new Point(rand.Next(10, 100), rand.Next(10, 100)) };
	
	return points;
}

private string GetRandomText()
{
	StringBuilder randomText = new StringBuilder();

	if (String.IsNullOrEmpty(code))
	{
		string alphabets = "abcdefghijklmnopqrstuvwxyz1234567890";
		Random r = new Random();
		
		for (int j = 0; j <= 5; j++)
		{
			randomText.Append(alphabets[r.Next(alphabets.Length)]);
		}

		code = randomText.ToString();
	}
	
	return code;
}
 
Share this answer
 
v2
Comments
André Kraak 10-Mar-12 13:06pm    
Edited solution:
Added pre tags
Formatted text/code
fjdiewornncalwe 4-Apr-13 15:34pm    
Plagiarized from the link provided in Solution 1. source

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900