Re: Creating new controls?!



Well, at first, thanx for answering. i found out how to create controls, now
i am missing the most important part!
How do i apply functions to them???

like click or change??? there is the code following that i have already
ready...

'=====================================
Option Explicit
Public Pic1


Private Sub cmdCreatePic_Click()
'these stay the same each time you access the code so they are just Dims
Dim H As Integer
Dim W As Integer
'these don't stay the same each time you access the code so they are Static
Static I As Integer
Static strName As String

'position of pic box
W = I + 375
H = I + 1135
'Making the Pic box

Set Pic1 = Form1.Controls.Add("VB.COMMANDBUTTON", "A" & strName, Form1)
'Comment out the line above and un-comment the line below for a textbox
' Set Pic1 = Form1.Controls.Add("VB.TEXTBOX", "B" & strName, Form1)
Pic1.Caption = "Test"
Pic1.Left = W
Pic1.Top = H
Pic1.Height = 375
Pic1.Width = 1135
Pic1.Visible = True

'making the pic box in a different location each time
I = I + 100

'Have to make the name of the pic box different each time other wise you get
an error
'Because there are ways you can minipulate the item added at run time using
the API
'Which include things like pic1_click() ..and you can respond to a click to
the new control
strName = strName + "B"

End Sub
'======================================
For not being accused by anyone, this is not my code!
I found it on www.planet-source-code.com

So, how can i add functions while creating them?
For being more exactly, i just want to drag them around and by clicking on
them, they should send their "name" to a textbox...
I thought of having already written the code but i cannot forecast how many
controls i will have to create each time...

Can you help me out?
Friendly,
JBK

Ï "J French" <erewhon@xxxxxxxxxx> Ýãñáøå óôï ìÞíõìá
news:44cf0133.1009869918@xxxxxxxxxxxxxxxxxxxxxxx
On Mon, 31 Jul 2006 17:02:36 +0300, <jbk@xxxxxxxx> wrote:

Hello,
can any one help me out here?
I would like to create a new textbox (or picbox,or whatever else) by
clicking on a command button...
but, i dont know how! :-)
also, i dont know if this would make any difference, these new controls
will
be draggable...(If this word exists)

Look into Control Arrays

Dragging is quite easy using APIs

Option Explicit

' Add a Textbox
' Move Textbox on MouseDown & Drag

Private Declare Function ReleaseCapture _
Lib "user32" () As Long
Private Declare Function SendMessage _
Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Any) As Integer
Const WM_NCLBUTTONDOWN = &HA1
Const HTCAPTION = 2

Public Sub MoveObject(hwnd As Long)
ReleaseCapture
SendMessage hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
End Sub

Private Sub Form_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
MoveObject Me.hwnd
End Sub


Private Sub Text1_MouseDown(Button As Integer, _
Shift As Integer, _
X As Single, _
Y As Single)
MoveObject Text1.hwnd
End Sub



.



Relevant Pages

  • Referencing a Subprocedures Name
    ... The trick is to iterate through all the controls, ... Sub PastReply ... checkboxes to the collection that hosts the classes. ... >which is textbox specific I can simply reference the ...
    (microsoft.public.excel.programming)
  • Re: how to add several HTML elements to the web page dynamically using
    ... Protected Sub Button1_Click ... Dim Textbox1 As New TextBox ... is there a way to read the state of de website which controls should be "active" ... The controls, I supoose can be added via the contenttemplate of the update panel, but what about the script can it be added to the page at runtime? ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: How To Use The Number Part Of A TextBox Name As A Variable
    ... This requested code would need to detect what the name of the sub is ... The same demo shows how to process any textbox only by supplying its number ... Private Sub TextBox1_Enter' similar ... exiting the control. ...
    (microsoft.public.excel.programming)
  • Re: How To Use The Number Part Of A TextBox Name As A Variable
    ... You don't need to know how many digits ... Private Sub tbx_Change ... The same demo shows how to process any textbox only by supplying its number ... Private Sub TextBox1_Enter' similar ...
    (microsoft.public.excel.programming)
  • Re: Best approach for Control control
    ... group one has two controls - visual mouse placement on two pictureboxes. ... needs to change a value in a textbox in group 3. ... e.g. change a textbox programmatically without it generating a change event. ... Private Sub Text1_Change ...
    (microsoft.public.vb.general.discussion)