On Tue,2004年11月2日08:55:09 -0600,Jay B. Harlow [MVP - Outlook]" < Ja *** *********@msn.com>写道: Private Sub labelDisplay_Click(ByVal sender As Object,ByVal e As System.EventArgs) msgbox("你点击了单元格编号& labelDISPLAY.Name) ''你明白了...... :-) End Sub I have a piece of code thus: For iLOOP = 0 To iNoDays - 1For jLOOP = 0 To iMaxPeriods - 1iX = 10 + (iLOOP * (dCellWidth + 10))iY = 10 + (jLOOP * (dCellHeight + 10)) +Me.Size.Height / 4If jLOOP = 0 And iLOOP = 0 ThenlblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) = NewTextBoxlblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Text =" "lblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Location = New Point(iX, iY)lblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).AutoSize = FalselblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Height= dCellHeightlblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Width= dCellWidthlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Visible = FalselblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Name ="txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToStringMe.Controls.Add(lblDISPLAY(((iLOOP) * iMaxPeriods)+ jLOOP))ElseIf jLOOP = 0 And iLOOP > 0 ThenlblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) =New TextBoxlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Text = WeekdayName(iLOOP, , FirstDayOfWeek.Sunday)lblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Location = New Point(iX, iY)lblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Height = dCellHeightlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Width = dCellWidthlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).AutoSize = FalselblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).BorderStyle = BorderStyle.NonelblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).TextAlign = HorizontalAlignment.CenterlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToStringMe.Controls.Add(lblDISPLAY(((iLOOP) *iMaxPeriods) + jLOOP))ElseIf iLOOP = 0 And jLOOP > 0 ThenlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP) = New TextBoxlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Text = "Period " & jLOOP.ToStringlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Location = New Point(iX, iY)lblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Height = dCellHeightlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Width = dCellWidthlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).AutoSize = FalselblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).BorderStyle = BorderStyle.NonelblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).TextAlign = HorizontalAlignment.RightlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToStringMe.Controls.Add(lblDISPLAY(((iLOOP) *iMaxPeriods) + jLOOP))ElselblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP) = New TextBoxlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Text = "Label No " & ((iLOOP) * iMaxPeriods) + jLOOP.ToStringlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Location = New Point(iX, iY)lblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Height = dCellHeightlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Width = dCellWidthlblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).AutoSize = FalselblDISPLAY(((iLOOP) * iMaxPeriods) +jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToStringMe.Controls.Add(lblDISPLAY(((iLOOP) *iMaxPeriods) + jLOOP))End IfEnd IfEnd IfNext jLOOPNext iLOOP which creates a grid of text boxes on a form at runtime dependent onthe number of days and the number of periods - its a timetable sort ofthing. How do I capture events for these controls?such asprivate sub lblDISPLAY(((iLOOP) * iMaxPeriods)_Mouseclick or private sub lblDISPLAY(((iLOOP) * iMaxPeriods)_gotfocus ?? 解决方案 Tym,You can use AddHandler & RemoveHandler, something like: Dim index As Integer = ((iLOOP) * iMaxPeriods) + jLOOP AddHandler lblDISPLAY(index).Click, AddressOf labelDisplay_ClickAddHandler lblDISPLAY(index).GotFocus, AddressOflabelDisplay_GotFocus Private Sub labelDisplay_Click(ByVal sender As Object, ByVal e AsSystem.EventArgs) End Sub Private Sub labelDisplay_GotFocus(ByVal sender As Object, ByVal e AsSystem.EventArgs) End Sub Hope this helpsJay "Tym" <no*****@ictis.net> wrote in messagenews:5l********************************@4ax.com...I have a piece of code thus: For iLOOP = 0 To iNoDays - 1 For jLOOP = 0 To iMaxPeriods - 1 iX = 10 + (iLOOP * (dCellWidth + 10)) iY = 10 + (jLOOP * (dCellHeight + 10)) + Me.Size.Height / 4 If jLOOP = 0 And iLOOP = 0 Then lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) = New TextBox lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Text = " " lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Location = New Point(iX, iY) lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).AutoSize = False lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Height = dCellHeight lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Width = dCellWidth lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Visible = False lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString Me.Controls.Add(lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP)) Else If jLOOP = 0 And iLOOP > 0 Then lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) = New TextBox lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Text = WeekdayName(iLOOP, , FirstDayOfWeek.Sunday) lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Location = New Point(iX, iY) lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Height = dCellHeight lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Width = dCellWidth lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).AutoSize = False lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).BorderStyle = BorderStyle.None lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).TextAlign = HorizontalAlignment.Center lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString Me.Controls.Add(lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP)) Else If iLOOP = 0 And jLOOP > 0 Then lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) = New TextBox lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Text = "Period " & jLOOP.ToString lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Location = New Point(iX, iY) lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Height = dCellHeight lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Width = dCellWidth lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).AutoSize = False lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).BorderStyle = BorderStyle.None lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).TextAlign = HorizontalAlignment.Right lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString Me.Controls.Add(lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP)) Else lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP) = New TextBox lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Text = "Label No " & ((iLOOP) * iMaxPeriods) + jLOOP.ToString lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Location = New Point(iX, iY) lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Height = dCellHeight lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Width = dCellWidth lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).AutoSize = False lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP).Name = "txtPERIOD" & ((iLOOP) * iMaxPeriods) + jLOOP.ToString Me.Controls.Add(lblDISPLAY(((iLOOP) * iMaxPeriods) + jLOOP)) End If End If End If Next jLOOP Next iLOOP which creates a grid of text boxes on a form at runtime dependent on the number of days and the number of periods - its a timetable sort of thing. How do I capture events for these controls? such as private sub lblDISPLAY(((iLOOP) * iMaxPeriods)_Mouseclick or private sub lblDISPLAY(((iLOOP) * iMaxPeriods)_gotfocus ??Tym, You never saw my standard sample for this, it looks almost as your problem?. You can find it in this message http://groups.google.com/groups?selm...TNGP10.phx.gbl I hope it helps? Cor Jay - excellent code - worked right out of the box!! Just one further request - is there a way to detect which one has beenclicked?? advTHANKSance On Tue, 2 Nov 2004 08:55:09 -0600, "Jay B. Harlow [MVP - Outlook]"<Ja************@msn.com> wrote: Private Sub labelDisplay_Click(ByVal sender As Object, ByVal e As System.EventArgs)msgbox ("You have clicked on cell number " & labelDISPLAY.Name)'' you get the idea... :-) End Sub 这篇关于运行时创建控件的事件。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-15 01:09