How does one access dynamic controls by name (or whatever other means)? I
have the following:
Dim newbtnPick As New Button
newbtnPick.Name = "SliceButto n" & CurSliceNum
newbtnPick.Loca tion = New Point(SILoc.SIP ickbtn, SILoc.SIY3)
newbtnPick.Size = New Size(SILoc.btnW , SILoc.btnH)
newbtnPick.Text = "Pick->"
Sender.Controls .Add(newbtnPick )
AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k
Dim TextBoxSlice1Be ginH As New TextBox
TextBoxSlice1Be ginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3)
TextBoxSlice1Be ginH.Size = New Size(SILoc.Text BoxSizeW, SILoc.TextBoxSi zeH)
Sender.Controls .Add(TextBoxSli ce1BeginH)
Now in the handler how do I address the textbox?:
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As EventArgs)
' How do I dosomething like this:
dim x as string
x = TextBoxSlice1Be ginH.Text
if x 60
x=x/2
end if
TextBoxSlice1Be ginH.Text = x
End Sub
Is there a web based tutorial or article that deals with this?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com 5 4988
The sender is the object that raised the event. Cast it to the appropriate
type.
You can't reference the control unless the variable for it is declared at
the class level. If you declare a reference to it in one method, then you
cannot access that variable in another.
"Anil Gupte" <an*******@icin ema.comwrote in message
news:ed******** ******@TK2MSFTN GP04.phx.gbl...
How does one access dynamic controls by name (or whatever other means)? I
have the following:
Dim newbtnPick As New Button
newbtnPick.Name = "SliceButto n" & CurSliceNum
newbtnPick.Loca tion = New Point(SILoc.SIP ickbtn, SILoc.SIY3)
newbtnPick.Size = New Size(SILoc.btnW , SILoc.btnH)
newbtnPick.Text = "Pick->"
Sender.Controls .Add(newbtnPick )
AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k
Dim TextBoxSlice1Be ginH As New TextBox
TextBoxSlice1Be ginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3)
TextBoxSlice1Be ginH.Size = New Size(SILoc.Text BoxSizeW,
SILoc.TextBoxSi zeH)
Sender.Controls .Add(TextBoxSli ce1BeginH)
Now in the handler how do I address the textbox?:
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As EventArgs)
' How do I dosomething like this:
dim x as string
x = TextBoxSlice1Be ginH.Text
if x 60
x=x/2
end if
TextBoxSlice1Be ginH.Text = x
End Sub
Is there a web based tutorial or article that deals with this?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com
Hi Anil,
You could set the tag property on the button to be the textbox. Then
in your click handler you can cast the sender to a button and then
again cast the tag to the textbox. This aproach allows you to have
many pairs of Button/Textbox.
Dim newbtnPick As New Button
newbtnPick.Name = "SliceButto n" & CurSliceNum
newbtnPick.Loca tion = New Point(SILoc.SIP ickbtn, SILoc.SIY3)
newbtnPick.Size = New Size(SILoc.btnW , SILoc.btnH)
newbtnPick.Text = "Pick->"
Sender.Controls .Add(newbtnPick )
AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k
Dim TextBoxSlice1Be ginH As New TextBox
TextBoxSlice1Be ginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3)
TextBoxSlice1Be ginH.Size = New Size(SILoc.Text BoxSizeW,
SILoc.TextBoxSi zeH)
Sender.Controls .Add(TextBoxSli ce1BeginH)
' Set the tag property of the button
newbtnPick.Tag = TextBoxSlice1Be ginH
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As
EventArgs)
' Cast the sender, which will be the button control
Dim sliceTextBox as TextBox = DirectCast(Dire ctCast(sender,
Button).Tag, TextBox)
' Then you can do the following:
dim x as string
x = sliceTextBox.Te xt
if x 60
x=x/2
end if
sliceTextBox.Te xt = x
End Sub
You could always write a simple composite control with a button and
textbox on.
Good luck,
Regards
Darren
Anil Gupte wrote:
How does one access dynamic controls by name (or whatever other means)? I
have the following:
Dim newbtnPick As New Button
newbtnPick.Name = "SliceButto n" & CurSliceNum
newbtnPick.Loca tion = New Point(SILoc.SIP ickbtn, SILoc.SIY3)
newbtnPick.Size = New Size(SILoc.btnW , SILoc.btnH)
newbtnPick.Text = "Pick->"
Sender.Controls .Add(newbtnPick )
AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k
Dim TextBoxSlice1Be ginH As New TextBox
TextBoxSlice1Be ginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3)
TextBoxSlice1Be ginH.Size = New Size(SILoc.Text BoxSizeW, SILoc.TextBoxSi zeH)
Sender.Controls .Add(TextBoxSli ce1BeginH)
Now in the handler how do I address the textbox?:
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As EventArgs)
' How do I dosomething like this:
dim x as string
x = TextBoxSlice1Be ginH.Text
if x 60
x=x/2
end if
TextBoxSlice1Be ginH.Text = x
End Sub
Is there a web based tutorial or article that deals with this?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com
Anil,
Is this simple enough, there are as well more advanced ones on our website. http://www.vb-tips.com/dbpages.aspx?...2-03abce36aa60
I hope this helps,
Cor
"Anil Gupte" <an*******@icin ema.comschreef in bericht
news:ed******** ******@TK2MSFTN GP04.phx.gbl...
How does one access dynamic controls by name (or whatever other means)? I
have the following:
Dim newbtnPick As New Button
newbtnPick.Name = "SliceButto n" & CurSliceNum
newbtnPick.Loca tion = New Point(SILoc.SIP ickbtn, SILoc.SIY3)
newbtnPick.Size = New Size(SILoc.btnW , SILoc.btnH)
newbtnPick.Text = "Pick->"
Sender.Controls .Add(newbtnPick )
AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k
Dim TextBoxSlice1Be ginH As New TextBox
TextBoxSlice1Be ginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3)
TextBoxSlice1Be ginH.Size = New Size(SILoc.Text BoxSizeW,
SILoc.TextBoxSi zeH)
Sender.Controls .Add(TextBoxSli ce1BeginH)
Now in the handler how do I address the textbox?:
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As EventArgs)
' How do I dosomething like this:
dim x as string
x = TextBoxSlice1Be ginH.Text
if x 60
x=x/2
end if
TextBoxSlice1Be ginH.Text = x
End Sub
Is there a web based tutorial or article that deals with this?
Thanx,
--
Anil Gupte www.keeninc.net www.icinema.com
Thanx, that did it! I moved the Dim statements outside the method (which
was the New method i.e. constructor for this class) and left the rest inside
the method. Now I can access the textbox(es) in the event handler for the
button.
Great! Appreciate the help.
--
Anil Gupte www.keeninc.net www.icinema.com
"Marina Levit [MVP]" <so*****@nospam .comwrote in message
news:ef******** *****@TK2MSFTNG P02.phx.gbl...
The sender is the object that raised the event. Cast it to the appropriate
type.
You can't reference the control unless the variable for it is declared at
the class level. If you declare a reference to it in one method, then you
cannot access that variable in another.
"Anil Gupte" <an*******@icin ema.comwrote in message
news:ed******** ******@TK2MSFTN GP04.phx.gbl...
>How does one access dynamic controls by name (or whatever other means)? I have the following:
Dim newbtnPick As New Button newbtnPick.Nam e = "SliceButto n" & CurSliceNum newbtnPick.Loc ation = New Point(SILoc.SIP ickbtn, SILoc.SIY3) newbtnPick.Siz e = New Size(SILoc.btnW , SILoc.btnH) newbtnPick.Tex t = "Pick->" Sender.Control s.Add(newbtnPic k) AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k Dim TextBoxSlice1Be ginH As New TextBox TextBoxSlice1B eginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3) TextBoxSlice1B eginH.Size = New Size(SILoc.Text BoxSizeW, SILoc.TextBoxS izeH) Sender.Control s.Add(TextBoxSl ice1BeginH)
Now in the handler how do I address the textbox?:
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As EventArgs) ' How do I dosomething like this: dim x as string x = TextBoxSlice1Be ginH.Text if x 60 x=x/2 end if TextBoxSlice1Be ginH.Text = x End Sub
Is there a web based tutorial or article that deals with this?
Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
Thanx for the code sample - I learned something new (also from Darren in the
previous message) that there is a Tag property on a control. I wonder if I
can address the control using that. It would be very useful to address the
control using the tag later, after leaving the creation code. For example,
based on its value and the value of the next set of controls, I may want to
relocate it on the form.
--
Anil Gupte www.keeninc.net www.icinema.com
"Cor Ligthert [MVP]" <no************ @planet.nlwrote in message
news:uL******** ******@TK2MSFTN GP05.phx.gbl...
Anil,
Is this simple enough, there are as well more advanced ones on our
website.
http://www.vb-tips.com/dbpages.aspx?...2-03abce36aa60
I hope this helps,
Cor
"Anil Gupte" <an*******@icin ema.comschreef in bericht
news:ed******** ******@TK2MSFTN GP04.phx.gbl...
>How does one access dynamic controls by name (or whatever other means)? I have the following:
Dim newbtnPick As New Button newbtnPick.Nam e = "SliceButto n" & CurSliceNum newbtnPick.Loc ation = New Point(SILoc.SIP ickbtn, SILoc.SIY3) newbtnPick.Siz e = New Size(SILoc.btnW , SILoc.btnH) newbtnPick.Tex t = "Pick->" Sender.Control s.Add(newbtnPic k) AddHandler newbtnPick.Clic k, AddressOf newbtnPick_Clic k Dim TextBoxSlice1Be ginH As New TextBox TextBoxSlice1B eginH.Location = New Point(SILoc.SIX 0, SILoc.SIY3) TextBoxSlice1B eginH.Size = New Size(SILoc.Text BoxSizeW, SILoc.TextBoxS izeH) Sender.Control s.Add(TextBoxSl ice1BeginH)
Now in the handler how do I address the textbox?:
Private Sub newbtnPick_Clic k(ByVal sender As Object, ByVal e As EventArgs) ' How do I dosomething like this: dim x as string x = TextBoxSlice1Be ginH.Text if x 60 x=x/2 end if TextBoxSlice1Be ginH.Text = x End Sub
Is there a web based tutorial or article that deals with this?
Thanx, -- Anil Gupte www.keeninc.net www.icinema.com
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bil Muh |
last post by:
Esteemede Developers,
I would like to Thank All of You in advance for your sincere guidances.
I am developing a software using Visual C++ .NET Standard Edition with
Windows Form (.NET) template.
Briefly
--------------------------------------------------------------------------------------------
I need to create dynamically some...
|
by: CSDunn |
last post by:
Hello,
I have a situation with MS Access 2000 in which I need to display report
data in spreadsheet orientation (much like a datasheet view for a form). If
you think of the report in terms of what a spreadsheet might show, the
column names will actually be dynamic, based on data from a SQL Server 2000
database. The row data will also come...
|
by: Yannick Turgeon |
last post by:
Hello,
We are in the process of examining our current main application. We have to
do some major changes and, in the process, are questionning/validating the
use of MS Access as front-end. The application is relatively big: around 200
tables, 200 forms and sub-forms, 150 queries and 150 repports, 5GB of data
(SQL Server 2000), 40 users.
...
|
by: MikeY |
last post by:
Hi Everyone,
I am working in C#, windows forms.My question is this. All my button dynamic
controls properties are present and accounted for except for the"FlatStyle"
properties. I can't seem to figure out, if there is a way of using
polymorphic way (if that is a word) of doing this particular property. A
sample of my code is as follows:
...
|
by: Shourie |
last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle.
1) MainPage_load
2) User control1_Load
user clicks a dropdown in UC1
_________________________
1) MainPage_Load
2) User Control_1 Load
| |
by: sleigh |
last post by:
Hello,
I'm building a web application that will build a dynamic form based
upon questions in a database. This form will have several different
sections that consist of a panel containing one to many questions.
To keep it simple, I'll describe the basics of what I'm trying to
design.
I've created a TextBox composite control that...
|
by: Venus |
last post by:
Hello,
Thanks for your reply.
I understand that a control can be created dynamically in several ways:
1) using StringBuilder
2) using Controls.Add
3) using ASP PlaceHolder
But this is just for the controls and not for the form itself.
What I am trying to achieve is to create an entire form (including controls)
|
by: Venus |
last post by:
Hello,
After trying some ways to do it I wanted to use something like the code
below but for some reason
is not working (I have to generate the entire form dynamically (not only the
controls)):
Can anyone make any suggestions on how to do it ?
Thanks
|
by: Leo J. Hart IV |
last post by:
OK, here's another question for the experts:
I am building a multi-step (3 steps actually) form using a panel for
each step and hiding/displaying the appropriate panel/panels depending
on which step you're on. This all works fine, but I ran into some
trouble when I started creating controls dynamically in my code-behind
file.
Each panel...
|
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...
|
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...
| |
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...
|
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...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |