anhabib Posted November 9, 2004 Posted November 9, 2004 Hi i want to make labels dynamically. The method i designed is below now i want to give it a call like this labelarea(312, 344, 64, 40, " text here ", label1) for doing this i have to also write this line of code Dim label1 As New Label() which mean i have to know exactly the number of labels i want that is the problem i dont know the number is there any solution or can i make any are of variables with type label any idea people Public Sub labelarea(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal textValue As String, ByVal labels As Label) labels.Location = New System.Drawing.Point(x, y) labels.Name = "Label1" labels.Size = New System.Drawing.Size(width, height) labels.BorderStyle = BorderStyle.FixedSingle labels.Text = textValue labels.TextAlign = ContentAlignment.MiddleCenter Me.Controls.Add(labels) End Sub Quote
Moderators Robby Posted November 11, 2004 Moderators Posted November 11, 2004 you can declare the label before you actualy call the New... Dim label1 as Label labelarea(312, 344, 64, 40, " text here ", label1) Public Sub labelarea(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal textValue As String, ByVal labels As Label) labels = New Label labels.Location = New System.Drawing.Point(x, y) labels.Name = "Label1" labels.Size = New System.Drawing.Size(width, height) labels.BorderStyle = BorderStyle.FixedSingle labels.Text = textValue labels.TextAlign = ContentAlignment.MiddleCenter Me.Controls.Add(labels) End Sub Quote Visit...Bassic Software
Joe Mamma Posted November 11, 2004 Posted November 11, 2004 use factory patterns. factory the size, location and the actual label: Public function DetermineLabelSize(ByVal lbl as Label) as Size Dim sz as Size = new Size(0,0) ' if needed use the label parameter to determine the size, ' such as the length of the label text. return sz end function Public function DetermineLabelLocation(ByVal lbl as Label) as Point Dim pt as Point = new Point(0,0) ' if needed use the label parameter to determine the position, ' such as the length of the label text. return pt end function Public Function CreateLabel(ByVal textValue As String) as Label 'instance a Label dim lbl as label = new Label() 'Dont worry about the name, if you reference the 'control by name, you are doing things wrong 'Setup the display: lbl.BorderStyle = BorderStyle.FixedSingle lbl.Text = textValue lbl.TextAlign = ContentAlignment.MiddleCenter 'determine the next location lbl.Location = DetermineLabelLocation(lbl) 'determine the next Size lbl.Size = DetermineLabelSize(lbl) 'return the Label return lbl end function Function LabelsFromStringArray(byval s() as String) Dim i as integer for i = LBound(s) to UBound(s) Me.Controls.Add(CreateLabel(s(i))) next i end function Quote Joe Mamma Amendment 4: The right of the people to be secure in their persons, houses, papers, and effects, against unreasonable searches and seizures, shall not be violated, and no warrants shall issue, but upon probable cause, supported by oath or affirmation, and particularly describing the place to be searched, and the persons or things to be seized. Amendment 9: The enumeration in the Constitution, of certain rights, shall not be construed to deny or disparage others retained by the people.
anhabib Posted November 11, 2004 Author Posted November 11, 2004 thanks guys the solution really helped and it was simple Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.