Facebook Sharer
选择您要替换的背景颜色:
【农历新年】背景图片:
个性化设定
 注册  找回密码
查看: 1617|回复: 1
打印 上一主题 下一主题

C++.NET If Then Else 范例

[复制链接]

62

主题

5

好友

3715

积分

本站名嘴

Rank: 11Rank: 11

跳转到指定楼层
1#
发表于 2008-12-14 02:32 PM |只看该作者 |倒序浏览
因为是我第一个Project,所以名字叫做 First CPP Project

  1. 这里可以不要看,GUI来的
  2. #pragma once


  3. namespace FirstCPPProject {

  4.         using namespace System;
  5.         using namespace System::ComponentModel;
  6.         using namespace System::Collections;
  7.         using namespace System::Windows::Forms;
  8.         using namespace System::Data;
  9.         using namespace System::Drawing;

  10.         /// <summary>
  11.         /// Summary for Form1
  12.         ///
  13.         /// WARNING: If you change the name of this class, you will need to change the
  14.         ///          'Resource File Name' property for the managed resource compiler tool
  15.         ///          associated with all .resx files this class depends on.  Otherwise,
  16.         ///          the designers will not be able to interact properly with localized
  17.         ///          resources associated with this form.
  18.         /// </summary>
  19.         public ref class Form1 : public System::Windows::Forms::Form
  20.         {
  21.         public:
  22.                 Form1(void)
  23.                 {
  24.                         InitializeComponent();
  25.                         //
  26.                         //TODO: Add the constructor code here
  27.                         //
  28.                 }

  29.         protected:
  30.                 /// <summary>
  31.                 /// Clean up any resources being used.
  32.                 /// </summary>
  33.                 ~Form1()
  34.                 {
  35.                         if (components)
  36.                         {
  37.                                 delete components;
  38.                         }
  39.                 }
  40.         private: System::Windows::Forms::Label^  label1;
  41.         protected:
  42.         private: System::Windows::Forms::TextBox^  textBox1;
  43.         private: System::Windows::Forms::Button^  button1;
  44.         private: System::Windows::Forms::Label^  label2;

  45.         private:
  46.                 /// <summary>
  47.                 /// Required designer variable.
  48.                 /// </summary>
  49.                 System::ComponentModel::Container ^components;

  50. #pragma region Windows Form Designer generated code
  51.                 /// <summary>
  52.                 /// Required method for Designer support - do not modify
  53.                 /// the contents of this method with the code editor.
  54.                 /// </summary>
  55.                 void InitializeComponent(void)
  56.                 {
  57.                         this->label1 = (gcnew System::Windows::Forms::Label());
  58.                         this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  59.                         this->button1 = (gcnew System::Windows::Forms::Button());
  60.                         this->label2 = (gcnew System::Windows::Forms::Label());
  61.                         this->SuspendLayout();
  62.                         //
  63.                         // label1
  64.                         //
  65.                         this->label1->AutoSize = true;
  66.                         this->label1->Location = System::Drawing::Point(12, 17);
  67.                         this->label1->Name = L"label1";
  68.                         this->label1->Size = System::Drawing::Size(56, 13);
  69.                         this->label1->TabIndex = 0;
  70.                         this->label1->Text = L"Password:";
  71.                         //
  72.                         // textBox1
  73.                         //
  74.                         this->textBox1->Location = System::Drawing::Point(74, 14);
  75.                         this->textBox1->Name = L"textBox1";
  76.                         this->textBox1->PasswordChar = '●';
  77.                         this->textBox1->Size = System::Drawing::Size(117, 20);
  78.                         this->textBox1->TabIndex = 1;
  79.                         //
  80.                         // button1
  81.                         //
  82.                         this->button1->Location = System::Drawing::Point(197, 12);
  83.                         this->button1->Name = L"button1";
  84.                         this->button1->Size = System::Drawing::Size(75, 23);
  85.                         this->button1->TabIndex = 2;
  86.                         this->button1->Text = L"Login";
  87.                         this->button1->UseVisualStyleBackColor = true;
  88.                         this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  89.                         //
  90.                         // label2
  91.                         //
  92.                         this->label2->AutoSize = true;
  93.                         this->label2->Location = System::Drawing::Point(13, 34);
  94.                         this->label2->Name = L"label2";
  95.                         this->label2->Size = System::Drawing::Size(35, 13);
  96.                         this->label2->TabIndex = 3;
  97.                         this->label2->Text = L"label2";
  98.                         //
  99.                         // Form1
  100.                         //
  101.                         this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  102.                         this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  103.                         this->ClientSize = System::Drawing::Size(284, 48);
  104.                         this->Controls->Add(this->label2);
  105.                         this->Controls->Add(this->button1);
  106.                         this->Controls->Add(this->textBox1);
  107.                         this->Controls->Add(this->label1);
  108.                         this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedSingle;
  109.                         this->MaximizeBox = false;
  110.                         this->Name = L"Form1";
  111.                         this->Text = L"Login";
  112.                         this->ResumeLayout(false);
  113.                         this->PerformLayout();

  114.                 }
  115. #pragma endregion
  116. //这里就是 If Then Else 的部分
  117.         private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  118.                                  if(textBox1->Text == "password")
  119.                                  {
  120.                                         label2->Text = "Correct Password!";
  121.                                  }else{
  122.                                          label2->Text = "Incorrect Password!";
  123.                                  }
  124.                          }
  125.         };
  126. }


复制代码




收藏收藏0

11

主题

0

好友

249

积分

支柱会员

Rank: 4Rank: 4Rank: 4Rank: 4

2#
发表于 2008-12-15 01:37 AM |只看该作者
有解释会更好
.......


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

JBTALKS.CC |联系我们 |隐私政策 |Share

GMT+8, 2024-10-25 12:28 PM , Processed in 0.104564 second(s), 26 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

Ultra High-performance Dedicated Server powered by iCore Technology Sdn. Bhd.
Domain Registration | Web Hosting | Email Hosting | Forum Hosting | ECShop Hosting | Dedicated Server | Colocation Services
本论坛言论纯属发表者个人意见,与本论坛立场无关
Copyright © 2003-2012 JBTALKS.CC All Rights Reserved
合作联盟网站:
JBTALKS 马来西亚中文论坛 | JBTALKS我的空间 | ICORE TECHNOLOGY SDN. BHD.
回顶部