473,327 Members | 1,920 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Programatticaly programme control with events

I am adding a seriese of controls to 'panel1' on 'form1' This works well but
I can't find a way to enable events. This example adds a 10 x 10 grid of
check boxes.

How can I create an event that will run if any of the check boxes are ticked.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As Integer
Dim y As Integer
Dim pt As New System.Drawing.Point
Dim sz As New System.Drawing.Size
For x = 1 To 10
For y = 1 To 10
pt.X = x * 25 : pt.Y = y * 25
sz.Height = 17 : sz.Width = 17
myBox(x, y) = New CheckBox
If x = 1 And y = 1 Then myBox(1, 1) = cb
Panel1.Controls.Add(myBox(x, y))
With myBox(x, y)
.Text = ""
.Location = pt
.Size = sz
End With
Next y
Next x
Dim lbl As New LinkLabel
pt.X = 37 : pt.Y = 280
lbl.Text = "JF"
lbl.Location = pt
Panel1.Controls.Add(lbl)
End Sub
Dec 6 '05 #1
3 782
"John F" <Jo***@discussions.microsoft.com> schrieb
I am adding a seriese of controls to 'panel1' on 'form1' This works
well but I can't find a way to enable events. This example adds a
10 x 10 grid of check boxes.

How can I create an event that will run if any of the check boxes
are ticked.

[...]
myBox(x, y) = New CheckBox


AddHandler mybox(x,y).CheckedChanged, addressof _____ 'Insert Name of
event handler
BTW, this is also explained in the docs:
http://msdn.microsoft.com/library/en...nheritance.asp
(also available via <F1>)
Armin

Dec 6 '05 #2
Hi you can use addhandler for that

for example

Private Sub CheckBox_CheckedChanged(ByVal sender As Object, ByVal e As
System.EventArgs)
msgbox(directcast(sender,CheckBox).Checked)
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As Integer
Dim y As Integer
Dim pt As New System.Drawing.Point
Dim sz As New System.Drawing.Size Dim myChk As CheckBox
For x = 1 To 10
For y = 1 To 10 myChk = New CheckBox
AddHandler myChk.CheckedChanged, AddressOf
CheckBox_CheckedChanged pt.X = x * 25 : pt.Y = y * 25
sz.Height = 17 : sz.Width = 17 With myChk
.Text = ""
.Location = pt
.Size = sz
End With
myBox(x, y) = myChk
Panel1.Controls.Add(myChk) Next y
Next x
Dim lbl As New LinkLabel
pt.X = 37 : pt.Y = 280
lbl.Text = "JF"
lbl.Location = pt
Panel1.Controls.Add(lbl)
End Sub
Hth Greetz Peter

--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)

"John F" <Jo***@discussions.microsoft.com> schreef in bericht
news:C5**********************************@microsof t.com... I am adding a seriese of controls to 'panel1' on 'form1' This works well but I can't find a way to enable events. This example adds a 10 x 10 grid of
check boxes.

How can I create an event that will run if any of the check boxes are ticked.
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim x As Integer
Dim y As Integer
Dim pt As New System.Drawing.Point
Dim sz As New System.Drawing.Size
For x = 1 To 10
For y = 1 To 10
pt.X = x * 25 : pt.Y = y * 25
sz.Height = 17 : sz.Width = 17
myBox(x, y) = New CheckBox
If x = 1 And y = 1 Then myBox(1, 1) = cb
Panel1.Controls.Add(myBox(x, y))
With myBox(x, y)
.Text = ""
.Location = pt
.Size = sz
End With
Next y
Next x
Dim lbl As New LinkLabel
pt.X = 37 : pt.Y = 280
lbl.Text = "JF"
lbl.Location = pt
Panel1.Controls.Add(lbl)
End Sub

Dec 6 '05 #3
Thanks Armin, Peter.

Exactly what I was lookin for.

John.
Dec 6 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: melledge | last post by:
Full Programme for XTech 2005 Announced Premier European XML Industry Event Expands Focus to "XML, the Web and Beyond"; Co-hosted by the Mozilla Foundation,W3C, and OASIS, Presenters Include...
2
by: dave | last post by:
Hi, I have a COM control / server I'm trying to get events from in my c# applications. 1) I'm trying to get events in both c# console apps and in c# winform apps. 2) I can call methods on the...
1
by: Earl Teigrob | last post by:
PROBLEM: When a user control is loaded into a PlaceHolder control more than once, the events do not fire on the first click of a control on the dynamically loaded user control. In other words, the...
2
by: John Lau | last post by:
Hi, Is there documentation that talks about the page lifecycle, the lifecycle of controls on the page, and the rendering of inline code, in a single document? Thanks, John
1
by: Martin | last post by:
Hi, I have produced a custom server control that simple outputs a row of 26 buttons, one button for each letter of the english alphabet. now what I would like to do is catch the button click...
0
by: gvrr | last post by:
Hello, I would like to know what are the basic require that I should be familiar within VB6 for creating a QUIZ programme (standalone) which can be a) an executable b) should access a DATA...
18
by: arnuld | last post by:
i compiled the "hello world" programme from K&R2: #include<stdio.h> int main() { printf("hello world\n"); }
6
by: chang | last post by:
Hi ALL, I am working in C from past few months. Still now i can't figure out who is called main() in 'C' programme? Main() is a function from that we can call our sunroutines but someone has to...
8
by: Rex the Strange | last post by:
Hello All, I don't know if this is possible, but I'll give it a shot, here. I'm sick of writing the following line of code in control event handlers: if not visible then exit sub Is it...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.