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

C#求救

[复制链接]

5

主题

0

好友

1733

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

跳转到指定楼层
1#
发表于 2010-1-9 11:15 PM |只看该作者 |倒序浏览
这是我从书本上学到的
但是我的讲师说 这个ARRAY用的不对
可是我又不会弄


这是我的题目


[ 本帖最后由 shetaikeng 于 2010-1-27 12:57 AM 编辑 ]




收藏收藏0

13

主题

0

好友

2113

积分

白金长老

Rank: 10

2#
发表于 2010-1-9 11:39 PM |只看该作者
只是一段??
请把全部的 code 贴出来

还有 array 那里有visible 的 property??
你自己定义的 class 来的??


回复

使用道具 举报

5

主题

0

好友

1733

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

3#
发表于 2010-1-10 01:56 AM |只看该作者

回复 #2 goodday 的帖子

没有 .VISIBLE 的吗???
那我改一改
那个i 我 弄到了
谢谢哦


回复

使用道具 举报

5

主题

0

好友

1733

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

4#
发表于 2010-1-10 01:56 AM |只看该作者

回复 #2 goodday 的帖子

没有 .VISIBLE 的吗???
那我改一改
那个i 我 弄到了
谢谢哦


回复

使用道具 举报

5

主题

0

好友

1733

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

5#
发表于 2010-1-13 09:55 PM |只看该作者
没有人可以教教我吗?


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

6#
发表于 2010-1-13 11:05 PM |只看该作者

回复 #5 shetaikeng 的帖子

== 。。。 已经说的很清楚了啊, .Visible 是给某些东西的。 比如说 Textbox。

你把题目放上来好吗? 不然我们怎么教你呢?


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

7#
发表于 2010-1-13 11:33 PM |只看该作者

回复 #1 shetaikeng 的帖子

我就说点点吧, 反正我也很久没动 Code 了, 这个学期都是数学, 英文。

最基本的Array 是这样。

  1. string myfriend = new string[] {"kk" , "LCW" , "WILL" , "JS"};
复制代码


我举个例子

  1. int mynumber = new int[30];
复制代码

这个是基本的 Array  datatype 是前面的 int , 代表 Integer, 意思就是说只能放Integer。

Array 如果要存data, 那么其实不会很难。

  1. int a_number = 30;
  2. mynumber[0] = a_number;
复制代码


然后你Print 出来的方法就是...

  1. MessageBox.Show(mynumber[0]);
复制代码

那么你就会得到 30.

比如说我要存 For Loop 的 loop 号码, 那么我就这样写

  1. for(int i = 0 ; i < 30 ; i++) { mynumber[i] = i;};
复制代码

for loop 的概念就不多说了。 现在我们来看看 mynumber = i; 做了什么。
mynumber 是array 的名字 , 就是他的Index, 一定要是Integer 才能作为 Array 的Index。
mynumber = i; 就是把data Assign 给 i 位子。

print 出来的方法是。

  1. String numberString = "";

  2. for(int i = 0; i < mynumber.length; i++){
  3. numberString+= " " + mynumber[i];
  4. }
  5. MessageBox.Show(numberString);
复制代码


你会得到 0 ~ 29。

当然。除了int 你也能用别种DataType

  1. double doublenum = new double[30];
  2. string alotofstring = new string[30];
  3. object someobject = new object[30];
  4. student studentarr = new student[30];
复制代码

* student 是class, OOP 会教。 如果student class 内有 getname 这个 method, 那么 student[0].getname();  或 student[0].getname; 才是对的。 如果还没教到OOP , 那么你可以省略这个。


PS: 高手们, 如果大小写或写法, 或spelling 有错,或漏掉东西, 请大大指点和纠正我,不必对我客气。


回复

使用道具 举报

46

主题

6

好友

6456

积分

百变名嘴

Rank: 13Rank: 13Rank: 13Rank: 13

8#
发表于 2010-1-13 11:37 PM |只看该作者

回复 #1 shetaikeng 的帖子

MSDN , C# ARRAY。
http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx

Basic Array.  tutorial.
http://csharp.net-tutorials.com/basics/arrays/

Array , tutorial.(这个有点难==)
http://www.softsteel.co.uk/tutorials/cSharp/lesson6.html



这个是相关链接你能去看看下。


回复

使用道具 举报

5

主题

0

好友

1733

积分

白银长老

Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9Rank: 9

9#
发表于 2010-1-14 11:01 AM |只看该作者

回复 #7 宅男-兜着走 的帖子

你说的这些大致上我还能理解
但是我不理解的就是
我刚做了一个新的CODE
namespace mini_3rd_try
{
    public partial class Form1 : Form
    {
        private System.Windows.Forms.CheckBox[] _chkArray;
        public Form1()
        {
            InitializeComponent();
        }
        private void ChkForm(object sender, System.EventArgs e)
        {
            _chkArray = new CheckBox[]
                        {
                                       chkA1,
                                    chkB1,chkB2,
                                 chkC1,chkC2,chkC3,
                              chkD1,chkD2,chkD3,chkD4,
                            chkE1,chkE2,chkE3,chkE4,chkE5,
                         };
            for (int i = 0; i < 15; i++)
                this._chkArray.Click += new System.EventHandler(this.Click);
        }
        private void rulesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("1.The player can strike the sticks horizontally." + "\n" +
                          "2.The player can strike the stick next to the adjacent stick and so on after he/she has chosen a stick from that particular row" + "\n" +
                          "3.The player who strike the last stick is the loser", "Game Intro");
        }
        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            DialogResult DialogResult;
            DialogResult = MessageBox.Show("Are you sure you are closing?", "closing", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
            if (DialogResult == DialogResult.Yes)
            {
                Close();
            }
        }
        private void btnPlayer_Click(object sender, EventArgs e)
        {
            Game();
        }
        private void Game()
        {
            int i;
            if (btnPlayer.Text == "Start")
            {
                Color1();
                Color2();
                btnPlayer.Text = "Player 1";

                for (i = 0; i < 15; i++)
                {
                    _chkArray.Enabled = true;
                }
            }
            else if (btnPlayer.Text == "Player 1")
            {
                btnPlayer.Text = "Player 2";

            }
            else if (btnPlayer.Text == "Player 2")
            {

                btnPlayer.Text = "Player 1";
            }

            Endturn();
            btnRestart.Visible = true;
        }
        private void btnRestart_Click(object sender, EventArgs e)
        {
            int i = 0;
            for (i = 0; i < 15; i++)
            {
                _chkArray.Checked = false;
            }
            Game();

        }
        private void Color1()
        {
            if (colorDialog1.ShowDialog() == DialogResult.OK)
            {
                lblPlayer1.BackColor = colorDialog1.Color;
            }
            else
            {
                MessageBox.Show("Player 1 will use default Blue", "Player 1");
                lblPlayer1.BackColor = Color.Blue;
                colorDialog1.Color = Color.Blue;
            }

            CheckColor();
        }
        private void Color2()
        {
            if (colorDialog2.ShowDialog() == DialogResult.OK)
            {
                lblPlayer2.BackColor = colorDialog2.Color;
            }
            else
            {
                MessageBox.Show("Player 2 will use default Red", "Player 2");
                lblPlayer2.BackColor = Color.Red;
                colorDialog2.Color = Color.Red;
            }

            CheckColor();
        }
        private void CheckColor()
        {
            if (lblPlayer1.BackColor == lblPlayer2.BackColor)
            {
                MessageBox.Show("Player 1 and Player 2 Cant have the same colour");
                lblPlayer1.BackColor = Color.White;
                lblPlayer2.BackColor = Color.White;
                Color1();
                Color2();
            }

        }
        private void Endturn()
        {
            int i;
            for (i = 0; i < 15; i++)
            {
                if (_chkArray.Checked == true)
                {
                    _chkArray.Enabled = false;
                }
            }
        }
        private void colorme(int i)
        {
            if (_chkArray.Checked == true)
            {
                if (btnPlayer.Text == "Player 1")
                {
                    _chkArray.BackColor = colorDialog1.Color;
                }
                else if (btnPlayer.Text == "Player 2")
                {
                    _chkArray.BackColor = colorDialog2.Color;
                }
            }
            else
            {
                _chkArray.BackColor = Color.FloralWhite;
            }
        }
    }
}


但是有问题
就是但我要运行的时候
Error        1        The event 'System.Windows.Forms.Control.Click' can only appear on the left hand side of += or -=
就是红色字的那个

[ 本帖最后由 shetaikeng 于 2010-1-14 02:51 PM 编辑 ]


回复

使用道具 举报

10

主题

0

好友

862

积分

青铜长老

Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7Rank: 7

10#
发表于 2010-1-16 05:05 PM |只看该作者
我是觉得event handler 的问题
可以看看这个

http://www.switchonthecode.com/t ... stom-event-handlers


回复

使用道具 举报

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

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

GMT+8, 2024-7-9 05:00 AM , Processed in 0.126623 second(s), 27 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.
回顶部