I am trying to add some components dynamically.
It works if the code is within form1.
When I try to move it to a module, I don't get any errors, but the
components don't display.
also the addhandler syntac is giving me trouble.
AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Below is the sample module code.
Thanks,
Gary...
Public Module module1
' Inherits System.Windows.Forms.Form
Public Sub Create_Objects()
Dim x As Integer
Dim cbCount As Integer
Dim fx As New Form1
fx.Panel1.Visible = True
fx.Refresh()
Dim ee As New System.EventArgs
'create controls for the amount in the textbox
Try
For x = 0 To 4
' For x = 0 To CType(tbButtonAmount.Text, Integer) - 1
Dim cb2 As New System.Windows.Forms.Button
cb2.Size = New System.Drawing.Size(120, 30)
cb2.Location = New System.Drawing.Point(250, 40 + x * 40)
cb2.Name = "RunTime" & CStr(cbCount)
cb2.Text = "RunTime" & CStr(cbCount)
fx.Controls.Add(cb2)
cbCount += 1
'add the click event and point to existing click event
' AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Next
Catch
MsgBox("Please ensure you have entered a number of controls to create in the
texbox!")
fx.tbButtonAmount.Select()
End Try
End Sub
End Module 7 960
"Gary Kahrau" <ka****@monair.com> schrieb: I am trying to add some components dynamically. It works if the code is within form1. When I try to move it to a module, I don't get any errors, but the components don't display.
also the addhandler syntac is giving me trouble. AddHandler cb2.Click, AddressOf fx.cbDesignTime_Click(fx, ee)
Below is the sample module code.
Thanks, Gary...
Public Module module1
' Inherits System.Windows.Forms.Form
Public Sub Create_Objects()
Dim x As Integer
Dim cbCount As Integer
Dim fx As New Form1
fx.Panel1.Visible = True
fx.Refresh()
The two lines above are useless because the form is not yet visible.
You'll either have to call 'fx.Show' after the controls/handlers were added
or add a parameter to the procedure that accepts an (already existing)
instance of 'Form1'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
OK,
I got the buttons to appear in a panel on form1.
what is the correct syntax for the event handler.
AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) '
<======== Wrong =======
I can't seem to figure this out. See sample code from form1 and module1.
Thanks,
Gary...
----------------- Code in Module1 ---------------------------------
Public Sub Create_Objects(ByRef fy As Form, ByRef pnl As Panel)
Dim ee As New System.EventArgs
Dim cb2 As New System.Windows.Forms.Button
cb2.Size = New System.Drawing.Size(120, 30)
cb2.Location = New System.Drawing.Point(10, 40 + x * 40)
cb2.Name = "RunTime1"
cb2.Text = "RunTime1"
pnl.Controls.Add(cb2)
AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) '
<===================
End Sub
----------------------------------- Form1 button
click -----------------------------------------
Public Sub cbDesignTime_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbDesignTime.Click
'get a reference to the sender onjects name
Dim cName As String = CType(sender, System.Windows.Forms.Button).Name
'check to see which control was clicked by name
If cName = "cbDesignTime" Then
MsgBox("You clicked the Button placed here in design time")
Else
Dim x As Integer
For x = 0 To cbCount
If cName = "RunTime" & x Then
MsgBox("You clicked RunTime" & x & " button")
End If
Next
End If
End Sub
OK,
I got the buttons to appear in a panel on form1.
what is the correct syntax for the event handler.
AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) '
<======== Wrong =======
I can't seem to figure this out. See sample code from form1 and module1.
Thanks,
Gary...
----------------- Code in Module1 ---------------------------------
Public Sub Create_Objects(ByRef fy As Form, ByRef pnl As Panel)
Dim ee As New System.EventArgs
Dim cb2 As New System.Windows.Forms.Button
cb2.Size = New System.Drawing.Size(120, 30)
cb2.Location = New System.Drawing.Point(10, 40 + x * 40)
cb2.Name = "RunTime1"
cb2.Text = "RunTime1"
pnl.Controls.Add(cb2)
AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) '
<===================
End Sub
----------------------------------- Form1 button
click -----------------------------------------
Public Sub cbDesignTime_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cbDesignTime.Click
'get a reference to the sender onjects name
Dim cName As String = CType(sender, System.Windows.Forms.Button).Name
'check to see which control was clicked by name
If cName = "cbDesignTime" Then
MsgBox("You clicked the Button placed here in design time")
Else
Dim x As Integer
For x = 0 To cbCount
If cName = "RunTime" & x Then
MsgBox("You clicked RunTime" & x & " button")
End If
Next
End If
End Sub
"Gary Kahrau" <ka****@monair.com> schrieb: what is the correct syntax for the event handler. AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) ' <======== Wrong =======
Remove the '(fy, ee') part and make sure the modifier of
'cbDesignTime_Click' is <> 'Private' or 'Protected'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
"Gary Kahrau" <ka****@monair.com> schrieb: what is the correct syntax for the event handler. AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) ' <======== Wrong =======
Remove the '(fy, ee') part and make sure the modifier of
'cbDesignTime_Click' is <> 'Private' or 'Protected'.
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried,
On the sample that I sent you,
'cbDesignTime_Click' is a Public sub in the form. I guessed at that.
It the module, VB complains that 'cbDesignTime_Click' is not declared.
How do I declare a public click event that resides in the form?
Gary...
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uq***************@TK2MSFTNGP11.phx.gbl... "Gary Kahrau" <ka****@monair.com> schrieb: what is the correct syntax for the event handler. AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) ' <======== Wrong =======
Remove the '(fy, ee') part and make sure the modifier of 'cbDesignTime_Click' is <> 'Private' or 'Protected'.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Herfried,
On the sample that I sent you,
'cbDesignTime_Click' is a Public sub in the form. I guessed at that.
It the module, VB complains that 'cbDesignTime_Click' is not declared.
How do I declare a public click event that resides in the form?
Gary...
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:uq***************@TK2MSFTNGP11.phx.gbl... "Gary Kahrau" <ka****@monair.com> schrieb: what is the correct syntax for the event handler. AddHandler cb2.Click, AddressOf fy.cbDesignTime_Click(fy, ee) ' <======== Wrong =======
Remove the '(fy, ee') part and make sure the modifier of 'cbDesignTime_Click' is <> 'Private' or 'Protected'.
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Paul Rubin |
last post by:
That's what the Python style guides advise. They don't seem to like
def frob(x):
import re
if re.search('sdfxyz', x): ...
instead preferring that you pollute your module's global namespace...
|
by: David MacQuigg |
last post by:
I'm setting up a large hierarchy of module packages and using a
variable to select which of many alternative packages to import. For
example, the variable 'config.modsel' points to a particular...
|
by: Andrew E |
last post by:
Hi all
I've written a python program that adds orders into our order routing
simulation system. It works well, and has a syntax along these lines:
./neworder --instrument NOKIA --size 23...
|
by: jwaixs |
last post by:
arg... I've lost 1.5 hours of my precious time to try letting re work
correcty. There's really not a single good re tutorial or documentation
I could found! There are only reference, and if you...
|
by: Just Me |
last post by:
I have a project that contains a usercontrol, some forms and a module.
The only thing in the module is one variable that is there so that it can be
used by the control and all the forms.
...
|
by: Tony Burrows |
last post by:
Just getting to grips with Python, a great language BUT
With something like Java I can find the syntax of a method call with no
problems, how do I do the same with Python?
For example, using...
|
by: adserte |
last post by:
i recently started using .adp project file in access 2003 with sql
server 2000 as backend. when using regular .mdb in access 2003, i could
call a module in a query simply by writing for example:...
|
by: rahatekarabhijeet |
last post by:
I downloaded the sorce from CPAN(PerlMagick-6.32.tar.gz).
I followed the normal procedure to install perl module on unix platform,
i.e.
1) perl Makefile.PL
during the execution of this command i...
|
by: norseman |
last post by:
mercado mercado wrote:
===================================
I started to import a module using its path and now see what you mean.
Python is missing the concept: Programmer dictates what machine...
|
by: Nadeem |
last post by:
Hello all,
I'm trying to write a function that will dynamically generate other
functions via exec. I then want to be able to import the file (module)
containing this function and use it in other...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
| |