當前位置:首頁 » 操作系統 » 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為你羨孫的提示塵派悔信息

熱點內容
ip訪問速度 發布:2023-03-24 11:48:30 瀏覽:139
我的世界伺服器領地菜單 發布:2023-03-24 11:48:24 瀏覽:901
我的世界國際版好玩的伺服器116 發布:2023-03-24 11:45:31 瀏覽:171
修改登錄密碼風控拒絕是什麼意思 發布:2023-03-24 11:44:55 瀏覽:692
java的繼承實例 發布:2023-03-24 11:44:52 瀏覽:467
存儲過程參數傳遞 發布:2023-03-24 11:37:28 瀏覽:463
冗餘配置節點是什麼 發布:2023-03-24 11:35:30 瀏覽:380
已加密字串 發布:2023-03-24 11:34:42 瀏覽:529
安卓系統有線投屏怎麼弄 發布:2023-03-24 11:33:04 瀏覽:28
編程前端開發 發布:2023-03-24 11:30:36 瀏覽:144