473,413 Members | 1,696 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,413 software developers and data experts.

Create textbox at runtime

How to create textbox randomly by written code in a command button?
Nov 16 '07 #1
4 27481
AHMEDYO
112 100+
HI...

what you mean by randomaly , you mean dynamically???
Nov 16 '07 #2
AHMEDYO
112 100+
Hey..

You have 3 ways to do that I will descript you begin from simple method and terminate by complex one.

Method 1:

You can create your run-time controls first by placing Textbox control in your form and then change index property to 0 to create array of textbox control, then you can use it to load new controls at runtime, and you can receive events from all of controls by Text1 control events and use Index parameter to identify your control.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     Dim TextControl As TextBox
  3.     ControlID = ControlID + 1
  4.     Load Text1(ControlID)
  5.     Set TextControl = Text1(ControlID)
  6.     With TextControl
  7.         .Left = (Text1(ControlID - 1).Left + Text1(ControlID - 1).Width) + 10
  8.         .Top = 20
  9.         .Width = 100
  10.         .Height = 20
  11.         .Visible = True
  12.     End With
  13. End Sub
'================================================= =======
Method 2:

You can create new controls using Form.Controls object, but you can't receive events from VB IDE about these controls, to handle events you must work a lot using API functions.

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command1_Click()
  2.     Dim TextControl As TextBox
  3.     Dim PrevTextControl As TextBox
  4.     ControlID = ControlID + 1
  5.     Set TextControl = Form1.Controls.Add("Vb.TextBox", "Text" & ControlID)
  6.     If (ControlID > 1) Then
  7.         Set PrevTextControl = Form1.Controls("Text" & (ControlID - 1))
  8.     Else
  9.         Set PrevTextControl = TextControl
  10.     End If
  11.     With TextControl
  12.         .Left = (PrevTextControl.Left + PrevTextControl.Width) + 10
  13.         .Top = 20
  14.         .Width = 50
  15.         .Height = 20
  16.         .Visible = True
  17.     End With
  18. End Sub
'================================================= =======
Method 3:

Using API only to create new textbox controls at run-time and sure you will work a lot to receive events and just to change the text in the textbox controls, you can use CreateWindows API Function to do that.

GOOD LUCK
Nov 17 '07 #3
@AHMEDYO
Hello sir i have used ur method 1 which is excellent. it lets me add a text box on runtime but i do not know a particular way to add the textboxes besides each other. I mean that if i have to add three text boxes using a command button ADD at runtime they get added behind each other. How can i resolve this using method 1.
Apr 13 '10 #4
@AHMEDYO
I got it!!.Theres absoluetly no problem with the code thank u.
Apr 13 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tom Rathbun | last post by:
This is probably simple but it has stumped me. I want to create objects at runtime for example: A program that would allow you to draw lines on a form. For each new line I would like to create a...
2
by: Patrick Marti | last post by:
Hi together I wish to create an object at runtime in the web. I get many good tips for how to do before two days by using the same Subject. So I got also the following link wich is showing...
3
by: Don Lee | last post by:
Hi All, i want to create a dynamic crosstab report. The method shown in http://support.microsoft.com/default.aspx?scid=kb;en-us;328320 is not a dynamic report as it require the user to manual...
1
by: pepsi330ml | last post by:
I need to create a crosstab report that does not need the user to know the total number to columns and manually add a new textbox and amend the VBA code. The VBA code should handle everything from...
3
by: Ricardo Corsi P. Cesar | last post by:
Hi, i looking for example in asp.net (VB) to make the RegularExpressionValidator in runtime in my code behind. I found some similars codes, but nothing in VB.. thanks!
3
by: RSB | last post by:
Hi Every one Having tuff time creating web controls Dynamically. All i am trying to do is read a table and generate a list of ASP TEXT Box. So how do i create this Control dynamically and where...
1
by: Bruno Pimentel Machado | last post by:
is it possible (how) to build a asp.net page on the fly? i.e.: I have a db with the controls I want to add to it: 1. TextBox - name "ABC" - Text "CDE" - Left 10 - Top - 30 2. Button - name "BT1" -...
1
by: Chris Dunaway | last post by:
I have a legacy application that I need to build a Windows Forms application to interface with it. The legacy application keeps its configuration information in INI style files. I wish to use a...
7
by: Edwin Martinez | last post by:
Hello I have a parent form but I want to create 4 forms that will be shown in a area inside the parent form when I click to buttons. +----------------------------+ | Parent Form ...
10
by: karan1981 | last post by:
Hi, I have a user control that has a textbox. This user control is placed in a form at runtime. This form gives a string to the user control and the textbox is to show this in multiple lines.(i...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
jinu1996
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...
0
tracyyun
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
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...

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.