黑马程序员+Winform基础

---------------<a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IOS开发</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流!-------------

  1. 控件:Button 按钮,TextBox 文本框, Label 标签,RadioButton 单选按钮,CheckButton 复选框 ,ListBox 列表框  ,PictureBox 图片框,ComboBox 下拉列表框
  2. 属性:Text:文本框中输入的值 ,Name:通过name来操作对象,Form.Text:窗体的标题,ForeColor:前景色,TextAlign:文本对齐,Image 图片,PasswordChar:密码文本 ,MultiLine 多行文本,Items 数据项,DropDownStyle:控制组合框的外观和功能,SelectItem 选中的项,SelectIndex 选中项的索引
  3. string.Format(“{0},你好”,textBox1.Text); //设置输出格式
  4. 方法:Form.Hide():对象隐藏,TextBox. AppendText()附加文本,
  5. 事件:Click:点击, SelectedIndexChanged 选择项发生改变

6.练习:求和
/// <summary>

/// 求和

/// </summary>

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

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

private void btnAdd_Click(object sender, EventArgs e)

{

string num1 = txtnum1.Text;

string num2 = txtnum2.Text;

int i1,i2;

if (!int.TryParse(num1,out i1))//转换成int

{

MessageBox.Show("第一个数不合法!");

txtnum1.Text = "";//数字不合法,清空文本框

}

            else if (int.TryParse(num2, out i2) == false)

{

MessageBox.Show("第二个数不合法!");

txtnum2.Text = "";

}

else

{//求和输出

txtsum.Text = (i1 + i2).ToString();

}

}

7. 练习:核对Email,分析出用户名和域名
/// <summary>

///       核对Email,分析出用户名和域名

/// </summary>

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

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

private void button1_Click(object sender, EventArgs e)

{

string email = txtEmail.Text;

string[] str = email.Split('@');

if (str.Length!=2)

{

MessageBox.Show("Email不合法");

txtEmail.Text = "";

}

else

{

MessageBox.Show(string.Format("用户名:{0} , 域名:{1}",str[0],str[1]));

}

}

8. 练习:两个数的累加
          /// <summary>

/// 累加

/// </summary>

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

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

private void button2_Click(object sender, EventArgs e)

{

string num1 = textBox1.Text;

string num2 = textBox2.Text;

int i1, i2,sum=0;

if (!int.TryParse(num1,out i1))

{

MessageBox.Show("第一个数非法");

textBox1.Text = "";

}

else if (!int.TryParse(num2,out i2))

{

MessageBox.Show("第二个数非法");

textBox1.Text = "";

}

else

{ //判断

if (i1>=i2)

{

MessageBox.Show("第一个数必须小于第二个数");

textBox1.Text = "";

textBox2.Text = "";

}

else

{//累加

for (int i = i1; i <= i2; i++)

{

sum += i;

}

MessageBox.Show(string.Format("{0}累加到{1}和为{2}", i1, i2, sum));

}

}         

}

9 .练习:

/// <summary>

/// 查看图片(满18岁可查看)

/// </summary>

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

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

private void button5_Click(object sender, EventArgs e)

{

string id = textBox4.Text;

//验证输入的身份证是否合法

if (id.Length!=18)

{

MessageBox.Show("身份证输入不合法");

textBox4.Text = "";

}

else

{//判断是否成年

if (DateTime.Now.Year-Convert.ToInt32(id.Substring(6,4))>18)

{

pictureBox1.Visible = true;

}

else

{

pictureBox1.Visible = false;

MessageBox.Show("年龄太小!");

}

}

}

10.练习:
        /// <summary>

/// 向左移动

/// </summary>

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

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

private void button3_Click(object sender, EventArgs e)

{

string str = textBox3.Text;

this.textBox3.Text = str.Substring(1)+str.Substring(0,1);

}

/// <summary>

/// 向右移动

/// </summary>

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

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

private void button4_Click(object sender, EventArgs e)

{

string str = textBox3.Text;

this.textBox3.Text = str.Substring(str.Length-1)+str.Substring(0, str.Length - 1);

}

11.+=与appendText的区别
        /// <summary>

/// 附加文本

/// </summary>

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

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

private void button6_Click(object sender, EventArgs e)

{

//textBox5.Text += DateTime.Now+"\r\n";//用于数据量小

textBox5.AppendText(DateTime.Now.ToString()+"\n");//数据量大

}

12.练习:登录错三次不让再登录
              /// <summary>

/// 登录,失败超过3次后退出

/// </summary>

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

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

private  int errorTime = 0;

private void btnsubmit_Click(object sender, EventArgs e)

{

string userName = txtname.Text.Trim();

string pwd = txtpwd.Text.Trim();

if (userName.Equals("admin", StringComparison.OrdinalIgnoreCase)&&pwd.Equals("888888"))

{

MessageBox.Show("登录成功!");

}

else

{

errorTime++;//不能用局部变量,用类字段才可达到计数的功能

if (errorTime>=3)

{

MessageBox.Show("错误三次,不允许再登录!");

//this.Close();

Application.Exit();//退出程序

}

else

{

MessageBox.Show("登录失败!");

}

}

}

---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IOS开发</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流! ----------------------

详细请查看:<a href="http://edu.csdn.net" target="blank">http://edu.csdn.net</a>

黑马程序员+Winform基础(上)的更多相关文章

  1. 黑马程序员+Winform基础(下)

    ---------------<a href="http://edu.csdn.net"target="blank">ASP.Net+Android ...

  2. 黑马程序员+SQL基础(上)

    黑马程序员+SQL基础 ---------------<a href="http://edu.csdn.net"target="blank">ASP ...

  3. 黑马程序员Java基础班+就业班课程笔记全发布(持续更新)

    正在黑马学习,整理了一些课程知识点和比较重要的内容分享给大家,也是给自己拓宽一些视野,仅供大家交流学习,大家有什么更好的内容可以发给我 ,现有黑马教程2000G  QQ 1481135711 这是我总 ...

  4. 黑马程序员_Java基础:网络编程总结

    ------- android培训.java培训.期待与您交流! ---------- Java语言是在网络环境下诞生的,它是第一个完全融入网络的语言,虽然不能说它是对支持网络编程做得最好的语言,但是 ...

  5. 黑马程序员----java基础笔记中(毕向东)

    <p>------<a href="http://www.itheima.com" target="blank">Java培训.Andr ...

  6. 黑马程序员_Java基础组成

    Java语言基础组成 2.1关键字 main不是关键字,但被JVM所识别的名称. 关键字的定义和特点 定义:被Java语言赋予了特殊含义的单词. 特点:关键字中所有字母都为小写. 用于定义数据类型的关 ...

  7. 黑马程序员_Java基础视频-深入浅出精华版--PPT 文件列表

    \day01\code\第一章_Java概述.ppt;\day01\resource\资料\50道编程题(有精力的同学看看).doc;\day01\resource\资料\Sun_Java程序员认证考 ...

  8. 黑马程序员_Java基础:IO流总结

    ------- android培训.java培训.期待与您交流! ---------- IO流在是java中非常重要,也是应用非常频繁的一种技术.初学者要是能把IO技术的学透,java基础也就能更加牢 ...

  9. 黑马程序员——JAVA基础之泛型和通配符

    ------- android培训.java培训.期待与您交流! ---------- 泛型:            JDK1.5版本以后出现新特性.用于解决安全问题,是一个类型安全机制. 泛型好处: ...

随机推荐

  1. uva 10340 All in All

    水题,从头到尾扫一遍就可以了,输入两个字符串s和t,判断是否可以从t中删除0个或多个字符(其他字符顺序不变),得到字符串s.例如,abcde可以得到bce,但无法得到dc. #include<a ...

  2. vi的查找与替换

    0x01 查找 (在命令行模式下) /<要查找的字符>   向下查找要查找的字符 ?<要查找的字符>   向上查找要查找的字符 0x02 替换 (在底行模式下) :0,$s/s ...

  3. 相同的问题又出现了,struts2取不出数值

    debug里面是有数值的,不知道是不是又是表示错了.全部改成了小写也无济于事.正在想法解决中... 问题解决了,因为自己的不仔细,问题还是出在了action的set,get方法里,不是大小写没注意,改 ...

  4. Flume NG简介及配置

    Flume下载地址:http://apache.fayea.com/flume/ 常用的分布式日志收集系统: Apache Flume. Facebook Scribe. Apache Chukwa ...

  5. 【软件工程】用map 实现把英语文本文件词和个数打印出来

    #include <iostream> #include <fstream> #include <string> #include <map> usin ...

  6. Java制作证书的工具keytool用法总结

    一.keytool的概念 keytool 是个密钥和证书管理工具.它使用户能够管理自己的公钥/私钥对及相关证书,用于(通过数字签名)自我认证(用户向别的用户/服务认证自己)或数据完整性以及认证服务.在 ...

  7. OpenShift:外国的免费云平台

    二.安装openshift客户端 对于怎么安装openshift客户端,我就不说了,网上有很多教程,连官网也有他自己的教程. 官网教程:https://developers.openshift.com ...

  8. js根据生日计算出年龄

    /*根据出生日期算出年龄*/ function jsGetAge(strBirthday){ var returnAge; var strBirthdayArr=strBirthday.split(& ...

  9. Strict Standards: Only variables should be passed by reference

    <?php $tag="1 2 3 4 5 6 7"; $tag_sel = array_shift(explode(' ', $tag)); print_r($tag_se ...

  10. EhReport ,CReport改进版本,再次改进 ,V1.31

    取消了xlgrid依赖,带齐了第三方包. 安装更加方便. For D7 下载源码