'************************************** ' Name: Create Random Control at Runtime ' ' Description:Create a label, commandbut ' ton, frame, textbox, hscrollbar, listbox ' , picturbox, shape, dirlistbox, filelist ' box, drivelistbox, vscrollbar, optionbut ' ton, line, checkbox, image or combobox r ' andomly with random height, width, top & ' left properties ' By: Max - Demian Net ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None ' 'Warranty: 'Code provided by Planet Source Code(tm) ' (http://www.Planet-Source-Code.com) 'as ' is', without warranties as to performanc ' e, fitness, merchantability,and any othe ' r warranty (whether expressed or implied ' ). 'Terms of Agreement: 'By using this source code, you agree to ' the following terms... ' 1) You may use this source code in per ' sonal projects and may compile it into a ' n .exe/.dll/.ocx and distribute it in bi ' nary format freely and with no charge. ' 2) You MAY NOT redistribute this sourc ' e code (for example to a web site) witho ' ut written permission from the original ' author.Failure to do so is a violation o ' f copyright laws. ' 3) You may link to this code from anot ' her website, provided it is not wrapped ' in a frame. ' 4) The author of this code may have re ' tained certain additional copyright righ ' ts.If so, this is indicated in the autho ' r's description. '************************************** 'Make a command1, try to make it smal & ' it the bottom right hand corner for best ' results. Private WithEvents txtDynamic As TextBox Private Sub Command1_Click() On Error Resume Next Dim RandomControl(1 To 18) As String Dim i As Integer Randomize RandomControl(1) = "VB.TextBox" RandomControl(2) = "VB.CommandButton" RandomControl(3) = "VB.Shape" RandomControl(4) = "VB.Label" RandomControl(5) = "VB.ListBox" RandomControl(6) = "VB.PictureBox" RandomControl(7) = "VB.Frame" RandomControl(8) = "VB.HScrollBar" RandomControl(9) = "VB.VScrollBar" RandomControl(10) = "VB.Image" RandomControl(11) = "VB.Line" RandomControl(12) = "VB.DirListBox" RandomControl(13) = "VB.DriveListBox" RandomControl(14) = "VB.FileListBox" RandomControl(15) = "VB.Timer" RandomControl(16) = "VB.ComboBox" RandomControl(17) = "VB.OptionButton" RandomControl(18) = "VB.CheckBox" i = Int((18 * Rnd) + 1) RandomTop = Int(Rnd * Me.Height) RandomLeft = Int(Rnd * Me.Width) RandomWidth = Int(Rnd * Me.Height) RandomText = Int(Rnd * 3200) Set RandDynamic = Controls.Add(RandomControl(i), "Rand" & RandomText) With RandDynamic .Visible = True .Text = "Demian Net" .Caption = "Demian Net" .BackColor = vbRed .Width = RandomWidth .Top = RandomTop .Left = RandomLeft End With End Sub