I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i , pntcurrent)
Next
For k As Integer = 0 To buttons.GetUppe rBound(0)
AddHandler buttons(k).Clic k, AddressOf Button_click
Next
End Sub
Private Sub createbuttons(B yVal i As Integer, _
ByVal pnt As Point)
buttons(i) = New Button
buttons(i).Enab led = True
buttons(i).Visi ble = True
buttons(i).Text = Convert.ToStrin g(i + 1)
buttons(i).Size = New _
System.Drawing. Size(buttonwh, buttonwh)
buttons(i).Loca tion = pnt
Me.Controls.Add (buttons(i))
End Sub
Private Sub button_click(By Val sender As System.Object, _
ByVal e As System.EventArg s)
End Sub
End Class 4 1422
Or all buttons are created but not shown properly. I would start by dumping
the location (it looks like to me you are adding a small offset where you
would want to make a multiplication ? also i will be never 13 etc...).
---
Patrice
"Ron" <pt*****@yahoo. coma écrit dans le message de news: 11************* *********@e65g2 00...legr oups.com...
>I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i , pntcurrent)
Next
For k As Integer = 0 To buttons.GetUppe rBound(0)
AddHandler buttons(k).Clic k, AddressOf Button_click
Next
End Sub
Private Sub createbuttons(B yVal i As Integer, _
ByVal pnt As Point)
buttons(i) = New Button
buttons(i).Enab led = True
buttons(i).Visi ble = True
buttons(i).Text = Convert.ToStrin g(i + 1)
buttons(i).Size = New _
System.Drawing. Size(buttonwh, buttonwh)
buttons(i).Loca tion = pnt
Me.Controls.Add (buttons(i))
End Sub
Private Sub button_click(By Val sender As System.Object, _
ByVal e As System.EventArg s)
End Sub
End Class
On Apr 2, 8:01 am, "Ron" <pts4...@yahoo. comwrote:
I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
What is the purpose of calculating j? Since i is always less than 13,
the Mod calculation will always yield the value of i (0 Mod 13 = 0, 1
Mod 13 = 1, 2 Mod 13 = 2, etc). You can just write j = i + 2. Also,
i will never be 13 so your next line will never fall into the if
block.
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i , pntcurrent)
Next
<snip>
End Class
It looks like 10 buttons should be created. Have you stepped through
the code to verify that it is calling the createbuttons method 10
times? By the way the Call keyword is not necessary.
Chris
I don't get 10 buttons I only get one button created with the number 1
On Apr 2, 9:22 am, "Chris Dunaway" <dunaw...@gmail .comwrote:
On Apr 2, 8:01 am, "Ron" <pts4...@yahoo. comwrote:
I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
What is the purpose of calculating j? Since i is always less than 13,
the Mod calculation will always yield the value of i (0 Mod 13 = 0, 1
Mod 13 = 1, 2 Mod 13 = 2, etc). You can just write j = i + 2. Also,
i will never be 13 so your next line will never fall into the if
block.
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i , pntcurrent)
Next
<snip>
End Class
It looks like 10 buttons should be created. Have you stepped through
the code to verify that it is calling the createbuttons method 10
times? By the way the Call keyword is not necessary.
Chris
You meant you "see" one button ? IMO they are created but the code that
places them seems buggy to me. I would suggest to start with something
simple such as i*20 for both x and y cooordinates.
Then revise your code so that they are placed as you wish (looks like Mod
could do something else than you thought also you have a test on a number
that is never reached in your loop etc...)
--
Patrice
"Ron" <pt*****@yahoo. coma écrit dans le message de news: 11************* *******@y66g200 0h...legrou ps.com...
>I don't get 10 buttons I only get one button created with the number 1
On Apr 2, 9:22 am, "Chris Dunaway" <dunaw...@gmail .comwrote:
>On Apr 2, 8:01 am, "Ron" <pts4...@yahoo. comwrote:
I want to create 10 buttons on a form at runtime, the code below is
only creating one button labeled 1. Any idea what I am doing wrong?
Public Class Form1
Public code(10) As String
Public buttons(10) As Button
Const buttonwh As Integer = 30
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim i, j, row As Integer
Dim pntcurrent As Point
For i = 0 To 10
j = i Mod 13 + 2
What is the purpose of calculating j? Since i is always less than 13, the Mod calculation will always yield the value of i (0 Mod 13 = 0, 1 Mod 13 = 1, 2 Mod 13 = 2, etc). You can just write j = i + 2. Also, i will never be 13 so your next line will never fall into the if block.
If i = 13 Then
row = 65
End If
pntcurrent = New Point(j + (buttonwh + 8), row)
Call createbuttons(i , pntcurrent)
Next
<snip>
End Class
It looks like 10 buttons should be created. Have you stepped through the code to verify that it is calling the createbuttons method 10 times? By the way the Call keyword is not necessary.
Chris
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jon |
last post by:
Hello,
I have a datagrid and the data in it is dynamically created at runtime...
For iCounter = 0 To dataset.Tables(0).Columns.Count - 1
Dim objbc As New BoundColumn()
With objbc
.DataField = dsAllPastReplies.Tables(0).Columns(iCounter).ColumnName
.HeaderText = dsAllPastReplies.Tables(0).Columns(iCounter).ColumnName
If .DataField = dsAllPastReplies.Tables(0).Columns("ReplyID").ColumnName Then
|
by: DS |
last post by:
Anyone know of any downsides of using Transparent Buttons with Labels
behind them?
Thanks
DS
|
by: Bart Schelkens |
last post by:
Hi,
i have a label on my webpage.
I want to create some copys of this label at runtime, since i don't know how
many labels i will be needing.
How can i do this?
Thx
|
by: Jason |
last post by:
Hi everyone,
Have a small problem which I hope you can help me with.
I'm trying to create several link buttons at runtime which
run a routine when clicked.
I've tried to create a VERY basic example before I carry
on, but even this isn't working.
|
by: Tor Inge Rislaa |
last post by:
Creating Control Array
How to create an array of buttons, with common procedures based on the index
of the control.
How would this Example from VB 6.0 be in VB.NET?
Private Sub Command1_Click(Index As Integer)
Select Case Index
| |
by: Mats Lycken |
last post by:
Hi,
I'm creating a CMS that I would like to be plug-in based with different
plugins handling different kinds of content.
What I really want is to be able to load/unload plugins on the fly
without restarting the application.
What I did was to create an AppDomain that loaded the plugins and
everything was great, until I tried to pass something else that strings
between the domains...
|
by: Guillaume BRAUX |
last post by:
Hello,
What I want to do is to add a userControl to a form class witch is a
different class from the one the button is generated.
For example, I want to instanciate a label in "class1" and add it ("show
it") on a WinForm situated in "class2" (without having to add code to class2
!)
The problem is that I need to instanciate "class2" from "class1" to be able
to do a class2.controls.add(myLabel) in class1..
|
by: Pugi! |
last post by:
I am studying the book ASP.NET Data Web Controls. Very interesting, and
I try to put everything in runtime (VB.NET) code instead of in the
page. I got very far but now I am stuck.
I found examples of how to create a TemplateColumn in a DataGrid with a
hyperlink with two parameters at runtime
(http://www.c-sharpcorner.com/Code/2003/June/AddItemTemplateDynamically.asp).
But now I want to create a templatecolumn in a datalist with some...
|
by: Ron |
last post by:
Can anyone help me out? I am trying to add buttons numbered one
through 10 at runtime to a form.
I think they are getting added but they seem to be getting stacked one
on top of each other. so I only see 1, and not the others.
here is what I am doing can anyone tell me what I am doing wrong?
Public Class Form1
Public buttons(9) As Button
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| | |