VS2008中 一个闪烁的Label控件的代码怎么写?

VS2008中 一个闪烁的Label控件的代码怎么写?,第1张

向窗体添加Timer控件 ,添加全局变量int record,在Button中填写让时钟开始计时,在timer_Tick()中写处理;

代码如下:

public partial class Form1 : Form

{

int record= 0

public Form1()

{

InitializeComponent()

}

private void button1_Click(object sender, EventArgs e)

{

this.timer1.Start()

}

private void timer1_Tick(object sender, EventArgs e)

{

record++;

if (record% 2 == 0) //%后的数随便写

{

this.label1.Visible = false

label1.BackColor = Color.Red

}

else

this.label1.Visible = true

}

}

是你的session在set时错了,因为在你还没有set前他是不存在的应该这样写

Session.Add(Key, Value)

给你个封装好的类

using System

using System.Data

using System.Configuration

using System.Linq

using System.Web

using System.Web.Security

using System.Web.SessionState

using System.Web.UI

using System.Web.UI.HtmlControls

using System.Web.UI.WebControls

using System.Web.UI.WebControls.WebParts

using System.Xml.Linq

/// <summary>

/// Summary description for CSession

/// </summary>

public static class CSession

{

public static object Get(string Key)

{

return HttpContext.Current.Session[Key]

}

public static string GetString(string Key)

{

object obj = HttpContext.Current.Session[Key]

if (obj == null) return ""

else return obj.ToString()

}

public static object Get(string Key, object DefaultValue)

{

if (HttpContext.Current.Session[Key] == null)

return DefaultValue

else

return HttpContext.Current.Session[Key]

}

public static object Get(string Key, object DefaultValue, Boolean CanAdd)

{

if (HttpContext.Current.Session[Key] == null)

{

if (CanAdd == true)

HttpContext.Current.Session.Add(Key, DefaultValue)

return DefaultValue

}

else

return HttpContext.Current.Session[Key]

}

public static Boolean Set(string Key, object Value)

{

try

{

if (Value == null &&HttpContext.Current.Session[Key] != null)

{

HttpContext.Current.Session.Remove(Key)

}

else if (HttpContext.Current.Session[Key] == null)

{

HttpContext.Current.Session.Add(Key, Value)

}

else

{

HttpContext.Current.Session[Key] = Value

}

return true

}

catch (Exception ex)

{

JScript.Alert(ex.Message)

return false

}

}

}

右键点击要显示的txt框,选择添加变量,注意变量类型,你下位机传上来的是一个什么类型的值,就选择相同类型的变量。右边种类选择value.然后自定义一个变量名,在你的接收数据的程序里给这个变量名赋值就可以在对话框显示了。


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/bake/11734417.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-18
下一篇2023-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存