Advertisement
ASP_Volume3 Miscellaneous #51673

Dynamically Added Objects

This short, simple code allows the addition of objects into a container on another form (in this case a PicturBox). It can easily be modified to add the object to different locations by modifying the locations in the dynObject() function.

AI

Yapay Zeka Özeti: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.

Kaynak Kod
original-source
Dim WithEvents dynbutton As VB.CommandButton
Dim WithEvents dynLabel As VB.Label
Private Sub Form_Load()
 Form2.Show
 Form2.Top = Form1.Top
 Form2.Left = Form1.Left + Form1.Width
End Sub
Private Sub Command1_Click()
 Call dynObjects
End Sub
   
Public Sub dynObjects()
 'Define label location and properties
   Set dynLabel = Form2.Controls.Add("VB.label", "dynLabel", Form2.Picture1)
    dynLabel.Caption = "Dynamically added label!"
    dynLabel.Visible = True
    dynLabel.BorderStyle = 1
   
 'Define CommandButton location and properties
   Set dynbutton = Form1.Controls.Add("VB.commandbutton", "dynButton", Form1)
    dynbutton.Caption = "Dynamic Button"
    dynbutton.Visible = True
    dynbutton.Width = 1275
    dynbutton.Font = "MS Sans Serif"
 End Sub
Private Sub dynButton_click()
 MsgBox ("You have pressed a dynamically added button")
End Sub
Orijinal Yorumlar (3)
Wayback Machine'den kurtarıldı