A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 流离 中级黑马   /  2013-10-14 23:35  /  1339 人查看  /  9 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

本帖最后由 流离 于 2013-10-15 02:39 编辑

页面上有一个文本框,文本框左侧右侧各一个按钮,点击左侧按钮文本框中的文字向左循环滚动一次,点击有侧按钮文本框中的文字向右循环滚动一次这是我看视频打得一部分代码后边实在无从下手
  1. namespace WindowsFormsApplication2
  2. {
  3.     public partial class Form1 : Form
  4.     {
  5.         public Form1()
  6.         {
  7.             InitializeComponent();
  8.         }

  9.         private void checkBox1_CheckedChanged(object sender, EventArgs e)
  10.         {

  11.         }

  12.         private void textBox1_TextChanged(object sender, EventArgs e)
  13.         {
  14.             string str = textBox1.Text;
  15.             char first = str[0];
  16.             string 剩下 = str.Substring(1);
  17.             textBox1.Text = 剩下 + first;
  18.         }

  19.         private void button2_Click(object sender, EventArgs e)
  20.         {
  21.             
  22.         }

  23.         private void button1_Click(object sender, EventArgs e)
  24.         {

  25.         }
  26.     }
  27. }
复制代码

评分

参与人数 1技术分 +1 收起 理由
haxyek + 1

查看全部评分

9 个回复

倒序浏览
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {
           
        }

        private void button2_Click(object sender, EventArgs e)
        {
              textBox1.Text=textBox1.Text.Substring(1)+textBox1.Text.Substring(0,1);//向左
        }

        private void button1_Click(object sender, EventArgs e)
        {
                 textBox1.Text=
             textBox1.Text.Substring(textBox1.Text.Length-1)+textBox1.Text.Substring(1,textBox1.Text.Length);
               //向右
        }
    }
}

评分

参与人数 1技术分 +1 收起 理由
haxyek + 1

查看全部评分

回复 使用道具 举报
飞、 发表于 2013-10-15 00:49
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form

向右代码有问题,我修改了一下
  1.   textBox1.Text = textBox1.Text.Substring( textBox1.Text.Length-2) +textBox1.Text.Substring(0,textBox1.Text.Length - 2) ;
复制代码
回复 使用道具 举报
明白过来原理了!为什么我设置的向右移动时候最右边的字符会消逝,一直持续到没有可以消逝为止
  1.   string str = textBox1.Text;
  2.             char first = str[textBox1 .Text.Length-1];
  3.             string 剩下 = str.Substring(0, textBox1.Text.Length-2);
  4.             textBox1.Text = 剩下 + first;
  5.         }
复制代码
这是我的向右代码看下有问题没
回复 使用道具 举报
  1. //向右
  2.             //textBox1.Text = textBox1.Text.Substring( textBox1.Text.Length-2) +textBox1.Text.Substring(0,textBox1.Text.Length - 2) ;
  3.             string str = textBox1.Text;
  4.             char first = str[textBox1 .Text.Length-1];
  5.             string 剩下 = str.Substring(0, textBox1.Text.Length-1);
  6.             textBox1.Text = first + 剩下;
  7.         }

  8.         private void button1_Click(object sender, EventArgs e)
  9.         {
  10.          //向左
  11.         //textBox1.Text = textBox1.Text.Substring(1) + textBox1.Text.Substring( 0,1);//
  12.             string str = textBox1.Text;
  13.             char first = str[0];
  14.             string 剩下 = str.Substring(1);
  15.             textBox1.Text = 剩下 + first;
复制代码
熬了一晚上啊!终于将这个小问题搞定啦!不容易啊!求加分
回复 使用道具 举报
飞、 发表于 2013-10-15 00:49
namespace WindowsFormsApplication2
{
    public partial class Form1 : Form

哦,是有点小问题,没上VS,直接在这写的,不好意思哦
   textBox1.Text=
             textBox1.Text.Substring(textBox1.Text.Length-1)+textBox1.Text.Substring(1,textBox1.Text.Length);
改成:
   textBox1.Text=
             textBox1.Text.Substring(textBox1.Text.Length-1)+textBox1.Text.Substring(0,textBox1.Text.Length-1);
这个是正确的

评分

参与人数 1技术分 +1 收起 理由
追溯客 + 1

查看全部评分

回复 使用道具 举报
飞、 中级黑马 2013-10-15 02:44:31
7#
流离 发表于 2013-10-15 02:12
明白过来原理了!为什么我设置的向右移动时候最右边的字符会消逝,一直持续到没有可以消逝为止这是我的向右 ...

string str = textBox1.Text;
            char first = str[textBox1 .Text.Length-1];
            string 剩下 = str.Substring(0, textBox1.Text.Length-2);// 应该要改成
            textBox1.Text = 剩下 + first;                                      str.Substring(0,textBox1.Text.Length-1)  
                                                                                          为什么你要减2呢  
回复 使用道具 举报
飞、 中级黑马 2013-10-15 02:46:49
8#
正好打开Winform,写一个给你吧!

private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "我爱黑马程序员";
        }
        private void button1_Click(object sender, EventArgs e)
        {
             string str = textBox1.Text;
             textBox1.Text = str.Substring(str.Length - 1) + str.Substring(0, str.Length - 1);
        }
       向右的

    问题弄好了你把它改为已解决呀,不然评不了分
回复 使用道具 举报
流离 中级黑马 2013-10-15 14:12:30
9#
飞、 发表于 2013-10-15 02:46
正好打开Winform,写一个给你吧!

private void Form1_Load(object sender, EventArgs e)

s.lenght不是一直数组长度吗?也就是说元素个数!可是数组char[]不是从零开始的吗?也就是说这个数组最后一个元素应该是char[s.lenht-1],而char[s.lenght-2]是倒数第二个元素!不知道我的理解对不对!因为我是小白
回复 使用道具 举报

同学给你加分了!好好学习!蔡蔡和叶叶在黑马等着你!黑马有你更精彩!快点为了当土豪努力吧!
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马