VBGood网站全文搜索 Google

搜索VBGood全站网页(全文搜索)

VB爱好者乐园(VBGood)

 找回密码
 立即注册
搜索
查看: 6363|回复: 21

VC# 学习笔记

[复制链接]
 楼主| 发表于 2010-5-21 13:54:14 | 显示全部楼层 |阅读模式
本帖最后由 VBProFan 于 2010-5-21 15:12 编辑

感觉是VB和VC的组合。变量定义和VC几乎没区别,以分号结束语句也是C的语法。但控件的使用像VB,只是它是强类型语言。

UI.JPG

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace prjGD61
  9. {
  10.     public partial class Form1 : Form
  11.     {
  12.         public Form1()
  13.         {
  14.             InitializeComponent();
  15.         }
  16.         private void button1_Click(object sender, EventArgs e)
  17.         {
  18.             if (radioButton1.Checked)
  19.             {
  20.                 textBox3.Text = Convert.ToString(Convert.ToDecimal(textBox1.Text) + Convert.ToDecimal(textBox2.Text));
  21.             }
  22.             else
  23.             {
  24.                 textBox3.Text = Convert.ToString(Convert.ToDecimal(textBox1.Text) - Convert.ToDecimal(textBox2.Text));
  25.             }
  26.             label1.Text = textBox3.Text;
  27.         }
  28.         private void Form1_Load(object sender, EventArgs e)
  29.         {
  30.             listBox1.Items.Add("1");
  31.             listBox1.Items.Add("22");
  32.             listBox1.Items.Add("333");
  33.             listBox1.SelectedIndex = 0;
  34.             comboBox1.Items.Add("44");
  35.             comboBox1.Items.Add("55");
  36.             comboBox1.Items.Add("66");
  37.             comboBox1.SelectedIndex = 0;
  38.             timer1.Interval = 100;
  39.             timer1.Enabled = true;
  40.         }
  41.         private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
  42.         {
  43.             //以下两句等效:
  44.             //textBox1.Text = listBox1.SelectedItem.ToString();
  45.             textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
  46.         }
  47.         private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
  48.         {
  49.             //以下两句等效:
  50.             textBox2.Text = comboBox1.SelectedItem.ToString();
  51.             //textBox2.Text = comboBox1.Items[comboBox1.SelectedIndex].ToString();
  52.         }
  53.         private void comboBox1_TextChanged(object sender, EventArgs e)
  54.         {
  55.             textBox2.Text = comboBox1.Text;
  56.         }
  57.         private void timer1_Tick(object sender, EventArgs e)
  58.         {
  59.             if (checkBox1.Checked)
  60.             {
  61.                 if (progressBar1.Value < progressBar1.Maximum)
  62.                 {
  63.                     progressBar1.Value++;
  64.                 }
  65.                 else
  66.                 {
  67.                     progressBar1.Value = 0;
  68.                 }
  69.             }
  70.             else
  71.             {
  72.                 if (progressBar1.Value >0)
  73.                 {
  74.                     progressBar1.Value--;
  75.                 }
  76.                 else
  77.                 {
  78.                     progressBar1.Value = progressBar1.Maximum;
  79.                 }
  80.             }
  81.         }
  82.     }
  83. }
复制代码
有趣的是,它的进度条控件有三种风格,块、连续和搜索,其中第三种就是以前我在 VB 里苦苦寻找的最终没找到只能用两个 Image 控件实现的。不过这个控件也有个问题:“连续”风格用不了,效果和“块”风格一样,不知是不是哪里没设置。

在网上搜到答案了,把Program.cs文件中的这行注释掉才能看出效果:Application.EnableVisualStyles();
这句就相当于使用 XP 风格,用了以后进度条就没有连续风格了。
progressbar.JPG
发表于 2010-5-21 14:24:22 | 显示全部楼层
本帖最后由 仙剑魔 于 2010-5-21 14:25 编辑

c#邪恶就邪恶在必要的时候可以解开指针的封印...
什么时候VB也能这样就爽了...
话说在clr里控件的用法没差吧,c++也只是把.换成了->而已
回复 支持 反对

使用道具 举报

发表于 2010-5-21 16:54:25 | 显示全部楼层
看起来像JAVA……
回复 支持 反对

使用道具 举报

头像被屏蔽
发表于 2010-5-21 17:00:19 | 显示全部楼层
提示: 作者被禁止或删除 内容自动屏蔽
回复 支持 反对

使用道具 举报

发表于 2010-5-21 22:48:42 | 显示全部楼层
VB.net好像也是强类型吧……另外你确定VB.net里面没有指针?
回复 支持 反对

使用道具 举报

发表于 2010-5-21 22:51:58 | 显示全部楼层
VB.net好像也是强类型吧……另外你确定VB.net里面没有指针?
回复 支持 反对

使用道具 举报

发表于 2010-5-23 11:36:43 | 显示全部楼层
谢谢了。。。 我很赞成,继续努力吧
回复 支持 反对

使用道具 举报

发表于 2010-5-24 08:53:15 | 显示全部楼层
6# acme_pjz

我这里说的指针是指c++里的那种
不是光有一个地址的数字

话说.net里vb不算强类型吧...
Option Explicit Off之后就不用声明了
string和数字也可以直接转...
回复 支持 反对

使用道具 举报

发表于 2010-5-24 11:01:14 | 显示全部楼层
8# 仙剑魔

Option Strict On……它有这个功能,就是看你用不用……不过我对VB.net和C#都没好感,两者同一个内核,运行速度超慢……
回复 支持 反对

使用道具 举报

发表于 2010-5-24 11:24:54 | 显示全部楼层
9# acme_pjz

还是6.0用着舒服
回复 支持 反对

使用道具 举报

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

本版积分规则

文字版|手机版|小黑屋|VBGood  

GMT+8, 2023-3-22 04:50

VB爱好者乐园(VBGood)
快速回复 返回顶部 返回列表