|
本帖最后由 VBProFan 于 2010-5-21 15:12 编辑
感觉是VB和VC的组合。变量定义和VC几乎没区别,以分号结束语句也是C的语法。但控件的使用像VB,只是它是强类型语言。
-
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace prjGD61
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- if (radioButton1.Checked)
- {
- textBox3.Text = Convert.ToString(Convert.ToDecimal(textBox1.Text) + Convert.ToDecimal(textBox2.Text));
- }
- else
- {
- textBox3.Text = Convert.ToString(Convert.ToDecimal(textBox1.Text) - Convert.ToDecimal(textBox2.Text));
- }
- label1.Text = textBox3.Text;
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- listBox1.Items.Add("1");
- listBox1.Items.Add("22");
- listBox1.Items.Add("333");
- listBox1.SelectedIndex = 0;
- comboBox1.Items.Add("44");
- comboBox1.Items.Add("55");
- comboBox1.Items.Add("66");
- comboBox1.SelectedIndex = 0;
- timer1.Interval = 100;
- timer1.Enabled = true;
- }
- private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- //以下两句等效:
- //textBox1.Text = listBox1.SelectedItem.ToString();
- textBox1.Text = listBox1.Items[listBox1.SelectedIndex].ToString();
- }
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
- //以下两句等效:
- textBox2.Text = comboBox1.SelectedItem.ToString();
- //textBox2.Text = comboBox1.Items[comboBox1.SelectedIndex].ToString();
- }
- private void comboBox1_TextChanged(object sender, EventArgs e)
- {
- textBox2.Text = comboBox1.Text;
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- if (checkBox1.Checked)
- {
- if (progressBar1.Value < progressBar1.Maximum)
- {
- progressBar1.Value++;
- }
- else
- {
- progressBar1.Value = 0;
- }
- }
- else
- {
- if (progressBar1.Value >0)
- {
- progressBar1.Value--;
- }
- else
- {
- progressBar1.Value = progressBar1.Maximum;
- }
- }
- }
- }
- }
复制代码 有趣的是,它的进度条控件有三种风格,块、连续和搜索,其中第三种就是以前我在 VB 里苦苦寻找的最终没找到只能用两个 Image 控件实现的。不过这个控件也有个问题:“连续”风格用不了,效果和“块”风格一样,不知是不是哪里没设置。
在网上搜到答案了,把Program.cs文件中的这行注释掉才能看出效果:Application.EnableVisualStyles();
这句就相当于使用 XP 风格,用了以后进度条就没有连续风格了。 |
-
|