当前位置:首页 » 操作系统 » messagebox源码

messagebox源码

发布时间: 2023-03-19 22:43:52

❶ VS2013用C++的MessageBox怎么用头文件要什么的求源码看得懂的。只要那一个命令就

scanf_svc2005开始,微软加入了一些所谓的安全函数替代原来的函数诸如fopen_sfprintf_s等等哗歼野。只是加入了新的安全措施乱喊,原来的scanffopen一样是可以改猛用的。可以在编译选项中设置,不让warning出现。7281499

❷ c# Winform 实现登录界面验证码功能(文末附源码)

闲来无事,最近自己发现自己的验证码功能还没有写过。于是就写下了这篇文章。

界面就比较丑了,一个picturebox,一个textbox,一个button按钮主要想的是先把功能实现了,万一以后业务上需要使用呢。

实现以后的功能图

在文本框中输入对应文字,点击确定来验证,正确时候如图所示

如果验证失败,没有提示,直接更新验证码,当然需要使用的时候根据业务逻辑来就是了,这个就比较简单了。

第一:生成验证码字符串,用到的是Random随机函数

第二:将该字符串画在picturebox中

第三点击图片,刷新验证码

第四验证验证码不区分大小写

或者区分大小写

此时完成

源码:

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace suijima

{

    public partial class Form1 : Form

    {

        public Form1()

        {

            InitializeComponent();

        }

        //验证码的长度

        private const int iVerifyCodeLength = 6;

        //验证码

        private String strVerifyCode = "";

        //匹配字符的临时变量

        string strTemp = "";

        private void btnUpdate_Click(object sender, EventArgs e)

        {

            UpdateVerifyCode();

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            UpdateVerifyCode();

        }

        //更新验证码

        private void UpdateVerifyCode()

        {

            strVerifyCode = CreateRandomCode(iVerifyCodeLength);

            if(strVerifyCode=="")

            {

                return;

            }

            strTemp = strVerifyCode;

            CreateImage(strVerifyCode);

        }

        //生成验证码字符串

        private string CreateRandomCode(int iLength)

        {

            int rand;

            char code;

            string randomCode = String.Empty;

            //生成一定长度的验证码

            System.Random random = new Random();

            for (int i = 0; i < iLength; i++)

            {

                rand = random.Next();

                if (rand % 3 == 0)

                {

                    code = (char)('A' + (char)(rand % 26));

                }

                else

                {

                    code = (char)('0' + (char)(rand % 10));

                }

                randomCode += code.ToString();

            }

            return randomCode;

        }

        ///  创建验证码图片

        private void CreateImage(string strVerifyCode)

        {

            try

            {

                int iRandAngle = 45;    //随机转动角度

                int iMapWidth = (int)(strVerifyCode.Length * 21);

                Bitmap map = new Bitmap(iMapWidth, 28);    //创建图片背景

                Graphics graph = Graphics.FromImage(map);

                graph.Clear(Color.AliceBlue);//清除画面,填充背景

                graph.DrawRectangle(new Pen(Color.Black, 0), 0, 0, map.Width - 1, map.Height - 1);//画一个边框

                graph.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;//模式

                Random rand = new Random();

                //背景噪点生成

                Pen blackPen = new Pen(Color.LightGray, 0);

                for (int i = 0; i < 50; i++)

                {

                    int x = rand.Next(0, map.Width);

                    int y = rand.Next(0, map.Height);

                    graph.DrawRectangle(blackPen, x, y, 1, 1);

                }

                //验证码旋转,防止机器识别

                char[] chars = strVerifyCode.ToCharArray();//拆散字符串成单字符数组

                //文字距中

                StringFormat format = new StringFormat(StringFormatFlags.NoClip);

                format.Alignment = StringAlignment.Center;

                format.LineAlignment = StringAlignment.Center;

                //定义颜色

                Color[] c = { Color.Black, Color.Red, Color.DarkBlue, Color.Green,

Color.Orange, Color.Brown, Color.DarkCyan, Color.Purple };

                //定义字体

                string[] font = { "Verdana", "Microsoft Sans Serif", "Comic Sans MS", "Arial", "宋体" };

                for (int i = 0; i < chars.Length; i++)

                {

                    int cindex = rand.Next(7);

                    int findex = rand.Next(5); Font f = new System.Drawing.Font(font[findex], 13, System.Drawing.FontStyle.Bold);//字体样式(参数2为字体大小)

                    Brush b = new System.Drawing.SolidBrush(c[cindex]);

                    Point dot = new Point(16, 16);

                    float angle = rand.Next(-iRandAngle, iRandAngle);//转动的度数

                    graph.TranslateTransform(dot.X, dot.Y);//移动光标到指定位置

                    graph.RotateTransform(angle);

                    graph.DrawString(chars[i].ToString(), f, b, 1, 1, format);

                    graph.RotateTransform(-angle);//转回去

                    graph.TranslateTransform(2, -dot.Y);//移动光标到指定位置

                }

                pictureBox1.Image = map;

            }

            catch (ArgumentException)

            {

                MessageBox.Show("创建图片错误。");

            }

        }

        private void button1_Click(object sender, EventArgs e)

        {

            //验证大小写

                char[] ch1 = textBox1.Text.ToCharArray();

                char[] ch2 = strTemp.ToCharArray();

                int nCount = 0;

                for (int i = 0; i < strTemp.Length;i++ )

                {

                    if((ch1[i]>='a'&&ch1[i]<='z')||(ch1[i]>='A'&&ch1[i]<='Z'))

                    {

                        if (ch1[i] - 32 == ch2[i] || ch1[i] + 32 == ch2[i])

                        {

                            nCount++;

                        }

                    }

                    else

                    {

                        if (ch1[i]==ch2[i])

                        {

                            nCount++;

                        }

                    }

                }

                if (nCount==strTemp.Length)

                {

                    MessageBox.Show("验证通过");

                }

                else

                {

                    UpdateVerifyCode();

                    textBox1.Text = "";

                }

            ////不能验证大小写

            //if(textBox1.Text==strTemp)

            //{

            //    MessageBox.Show("验证通过");

            //}

            //else

            //{

            //    UpdateVerifyCode();

            //    textBox1.Text = "";

            //}

        }

        /// <summary>

        /// 图片点击事件

        /// </summary>

        /// <param name="sender"></param>

        /// <param name="e"></param>

        private void pictureBox1_Click(object sender, EventArgs e)

        {

            UpdateVerifyCode();

        }

    }

}

❸ C# MessageBox.Show()怎么设置3秒后 自动关闭

写好了,以下是截图和部分源码,完整的源码在附件中:

1.指定要弹出的消羡辩困息以及定时的时间(单位秒)

❹ MFC中 MessageBox 函数字符串前加 L 什么意思

vc++在最近的几个版本例如vs20032005,2008等等MFC默认的字符集

unicode见图

项目属性图

所以用L把字符串转换成unicode字符串,如果使用“多字节字符集”则不需要L

建议使用_T宏来代替这个L,关冲散于_T宏相见tchar.h

大体源码是这么的:

#define__T(x)L##x

#define_T(x)__T(x)

作用卖敏是当使用unicode字符集的时候_T被替换为L

使用散配氏宽字符就替换为空

❺ C#窗体 MessageBox.Show(); show出来的窗体我想让他在窗体上显示个 红色的叉 怎么弄源码 谢谢了

MessageBox.Show(this, "Message"派正, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
Message为你羡孙的提示尘派悔信息

热点内容
hadoop删除文件夹 发布:2025-05-13 17:00:14 浏览:508
sql数据库远程备份 发布:2025-05-13 16:48:13 浏览:528
app什么情况下找不到服务器 发布:2025-05-12 15:46:25 浏览:714
php跳过if 发布:2025-05-12 15:34:29 浏览:467
不定时算法 发布:2025-05-12 15:30:16 浏览:131
c语言延时1ms程序 发布:2025-05-12 15:01:30 浏览:167
动物园灵长类动物配置什么植物 发布:2025-05-12 14:49:59 浏览:738
wifi密码设置什么好 发布:2025-05-12 14:49:17 浏览:150
三位数乘两位数速算法 发布:2025-05-12 13:05:48 浏览:399
暴风影音缓存在哪里 发布:2025-05-12 12:42:03 浏览:545