Over the years, I have collectedCode2
It's quite interesting to use vs to draw a picture when you are at work in the past few years. Let's take a look at how the verification code function is implemented with GDI +.
First, let's take a look at how to write text on winform to pave the way.
Figure 1 Text
Figure 2. Verification Code
What do we do when we see a verification code? Is it strange to see that the number is long? Is the word changed when you click it? Is the font color different? Isn't it clear at a glance? This is intended to prevent some evil people from registering with machines.
Train of Thought 1: The number inside is randomly generated
Enter the official section below.
- Random number obtained by the Verification Code
When we click on the Internet, is it an image? Therefore, you should drag an image control on the form and use the image click event.
Figure 3. Random number obtained by the Verification Code
My comments on the Code are very clear. For details, refer to the comments above.
In this step, we are faced with two problems: fonts and colors. Then, we need two arrays, one for the font and the other for the color.
Figure 4. Change the color and font of the Verification Code
Figure 5. Complete the color and font of the Verification Code
Each time a color is drawn, the above Code uses a for loop. When we achieve this step, the noise in the last number is worse. Let's think about it, isn't it just a little worse? Where is the maximum length of these lines? For example, if you draw ten lines, it is a for loop.
Figure 6. Drawing Noise
In the end, let's take a look at the last one.
Figure 7. Last
When we gradually access aspdot.net, we will find that such verification codes do not need to be manually drawn. However, when drawing verification codes, we need to master the basic programming ideas. Many exquisite GDI + diagrams are made in this way.
Author's recentArticle:
- The GDI + code I have collected over the years
-
- HTML language 3 that you cannot ignore
-
- HTML code 2 that you cannot ignore
-
- HTML language that you cannot ignore
- Our common Array
-
- Method (above) in C ):
-
- Comparison of three cycles