'定义一个新的图像控件
Dim thePic1 As New Image
thePic1.Width = "13" '设置图像控件的宽度
thePic1.Height = "21" '设置图像控件的高度
'设置显示图像的路径
thePic1.ImageUrl = "pic/" & Trim(str1) & ".gif"
'在容器控件PlaceHolder中添加图像控件
PlaceHolder1.Controls.Add(thePic1)
上面一段红色代码 当定义一个新的图像控件时Image类后面应该有括号,但是总是不显示请给为指点一下。
所有源代码如下:
If Not IsPostBack Then
Dim StrTxt As String
Dim StrPath As String
Dim IntCount As Integer
Dim i, j, theLen As Integer
Dim str1 As String
'获取存储计数器的值得文件路径
StrPath = Server.MapPath("Count.txt")
'读取此前计数
StrTxt = Trim(ReadText(StrPath))
'计算当前计数
If Trim(StrTxt) = "" Or Not IsNumeric(Trim(StrTxt)) Then
IntCount = 1
Else
IntCount = Convert.ToInt32(Trim(StrTxt)) + 1
'更新存储文件
WriteText(StrPath, Convert.ToString(IntCount))
theLen = Len(Trim(IntCount))
'循环计数值得每一位,将其用图像来代替显示
For i = 1 To theLen
str1 = Mid(Trim(IntCount), i, 1)
'定义一个新的图像控件
Dim thePic1 As New Image
thePic1.Width = "13" '设置图像控件的宽度
thePic1.Height = "21" '设置图像控件的高度
'设置显示图像的路径
thePic1.ImageUrl = "pic/" & Trim(str1) & ".gif"
'在容器控件PlaceHolder中添加图像控件
PlaceHolder1.Controls.Add(thePic1)
Next
End If
End If
'在此处放置初始化页的用户代码
End Sub
'读取文本信息
Sub WriteText(ByVal PathStr As String, ByVal TextStr As String)
Dim WriteStream As StreamWriter = New StreamWriter(PathStr)
WriteStream.WriteLine(TextStr)
WriteStream.Close()
End Sub
'写入文本信息
Function ReadText(ByVal PathStr As String) As String
Dim ReadStream As StreamReader
If File.Exists(PathStr) Then
ReadStream = File.OpenText(PathStr)
ReadText = ReadStream.ReadLine()
ReadStream.Close()
Else
ReadText = ""
End If
End Function
计数器用图像显示问题