使用文本框 [英] Working with Textboxes

查看:87
本文介绍了使用文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



i在我的asp页面中有三个文本框,有三种颜色。我想将textbox1 bgcolor分配给第二个文本框,将textbox2的颜色分配给第三个文本框。 ..同样我想在文本框中重复一个循环。任何人都可以帮我完成这项任务!







我想改变每个人的bgcolor具有前一个文本框bgcolor颜色的文本框,这应该每5秒发生一次

Hi All,

i have three textboxes in my asp page with three colors.I want to assign textbox1 bgcolor to 2nd textbox and textbox2's color to 3rd textbox.... likewise i want to repeat a loop among the textboxes. Can any one help me in doing this task!



I want to change the bgcolor of each textbox with the color of previous textbox bgcolor and this should be happend for each 5 seconds

推荐答案





正如ThePhantomUpvoter所说,你应该尝试使用JavaScript,而不是使用C#。

试试这个:

Hi,

As ThePhantomUpvoter said, you should try to do this with JavaScript, not with C#.
Try this:
<form runat="server">
    <asp:TextBox runat="server" BackColor="Red" ID="textbox1" />
    <asp:TextBox runat="server" BackColor="Green" ID="textbox2" />
    <asp:textbox runat="server" BackColor="Blue" ID="textbox3" />
</form>
<script type="text/javascript">
    var txtbox1 = document.getElementById("<%=textbox1.ClientID%>");
    var txtbox2 = document.getElementById("<%=textbox2.ClientID%>");
    var txtbox3 = document.getElementById("<%=textbox3.ClientID%>");
    setInterval(function () {
        prevColorTxt1 = txtbox1.style.backgroundColor;
        prevColorTxt2 = txtbox2.style.backgroundColor;
        prevColorTxt3 = txtbox3.style.backgroundColor;
        txtbox2.style.backgroundColor = prevColorTxt1;
        txtbox3.style.backgroundColor = prevColorTxt2;
        txtbox1.style.backgroundColor = prevColorTxt3;
    }, 5000, null);
</script>

有关 setInterval 功能的更多信息:

https://developer.mozilla.org/en-US/docs/ Web / API / window.setInterval [ ^ ]



希望这有帮助。

More about the setInterval function:
https://developer.mozilla.org/en-US/docs/Web/API/window.setInterval[^]

Hope this helps.


static int flag = 0;
    static int counter = 1;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (flag == 0)
        {
            TextBox1.BackColor = System.Drawing.Color.Red;
            TextBox2.BackColor = System.Drawing.Color.Green;
            TextBox3.BackColor = System.Drawing.Color.Blue;

            flag = 1;
            counter = 1;
        }
    }
    protected void Timer1_Tick(object sender, EventArgs e)
    {
        if (counter == 1)
        {
            TextBox1.BackColor = System.Drawing.Color.Blue;
            TextBox2.BackColor = System.Drawing.Color.Red;
            TextBox3.BackColor = System.Drawing.Color.Green;
            counter = 2;
        }
        else if (counter == 2)
        {
            TextBox1.BackColor = System.Drawing.Color.Green;
            TextBox2.BackColor = System.Drawing.Color.Blue;
            TextBox3.BackColor = System.Drawing.Color.Red;
            counter = 3;
        }
        else if (counter == 3)
        {
            TextBox1.BackColor = System.Drawing.Color.Red;
            TextBox2.BackColor = System.Drawing.Color.Green;
            TextBox3.BackColor = System.Drawing.Color.Blue;
            counter = 0;
            flag = 0;
        }
    }


嗨!我使用Winform来完成这个任务



private void Form1_Load(object sender,EventArgs e)

{

timer1.Interval = 5000;

timer1.Tick + = new EventHandler(timer1_Tick);

timer1.Start();



}



void timer1_Tick(对象发送者,EventArgs e)

{

颜色temp1 = textBox1.BackColor;

textBox1.BackColor = textBox3.BackColor;



颜色temp2 = textBox2.BackColor;

textBox2.BackColor = temp1;



颜色temp3 = textBox3.BackColor;

textBox3.BackColor = temp2;

}
Hi! I use Winform to do this task

private void Form1_Load(object sender, EventArgs e)
{
timer1.Interval = 5000;
timer1.Tick += new EventHandler(timer1_Tick);
timer1.Start();

}

void timer1_Tick(object sender, EventArgs e)
{
Color temp1 = textBox1.BackColor;
textBox1.BackColor = textBox3.BackColor;

Color temp2 = textBox2.BackColor;
textBox2.BackColor = temp1;

Color temp3 = textBox3.BackColor;
textBox3.BackColor = temp2;
}


这篇关于使用文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆