V
VB Novice Hendri
Guest
I to save changes made in DataBound Labels via a TextBox, By clicking on a Label the text apears in the TextBox where changes can be made to it.
Some of the code I use is shown below.
Dim recipeSelected As String = TitleListBox.SelectedItem.ToString()
Dim result = recipesLst.Where(Function(x) x.RecipeName = recipeSelected).FirstOrDefault()
'Form1.TextBox1.Text = result.ID.ToString()
'Recipe Name Label
Dim TitleFontStyle As FontStyle = FontStyle.Bold + FontStyle.Italic
Dim TitleFont As New System.Drawing.Font("Comic Sans MS", 14, TitleFontStyle)
Dim RecipeNameLabel As New Label()
With RecipeNameLabel
.AutoSize = True
.MaximumSize = New Size(370, 100)
.MinimumSize = New Size(370, 10)
.TextAlign = ContentAlignment.MiddleCenter
.Text = result.RecipeName
If TestModeCheckBox.Checked = True Then
.BackColor = Color.Gold
Else
.BackColor = Color.Transparent
End If
.Font = TitleFont
.Location = New Point(75, 50)
End With
Controls.Add(RecipeNameLabel)
RecipeNameLabel.Parent = Form1
X = RecipeNameLabel.Left
Y = RecipeNameLabel.Bottom + 10
AddHandler RecipeNameLabel.Click, AddressOf ContentLabel_Click
'Comment Label
Dim CommentLabel As New Label()
With CommentLabel
.AutoSize = True
.MaximumSize = New Size(200, 150)
.MinimumSize = New Size(150, 10)
.TextAlign = ContentAlignment.MiddleLeft
.Text = result.Comment
If TestModeCheckBox.Checked = True Then
.BackColor = Color.Gold
Else
.BackColor = Color.Transparent
End If
.Font = New System.Drawing.Font("Comic Sans MS", 8)
.Location = New Point(X, Y)
End With
Controls.Add(CommentLabel)
CommentLabel.Parent = Form1
X = CommentLabel.Left
Y = CommentLabel.Bottom
AddHandler CommentLabel.Click, AddressOf ContentLabel_Click
'Quantity Label
Dim QuantityLabel As New Label()
With QuantityLabel
.AutoSize = True
.MaximumSize = New Size(360 - CommentLabel.Width, 150)
.MinimumSize = New Size(360 - CommentLabel.Width, 10)
.TextAlign = ContentAlignment.BottomRight
.Text = result.Quantity
If TestModeCheckBox.Checked = True Then
.BackColor = Color.Gold
Else
.BackColor = Color.Transparent
End If
.Font = New System.Drawing.Font("Comic Sans MS", 8)
.Location = New Point(445 - QuantityLabel.Width, CommentLabel.Bottom - QuantityLabel.Height)
End With
Controls.Add(QuantityLabel)
QuantityLabel.Parent = Form1
AddHandler QuantityLabel.Click, AddressOf ContentLabel_Click
Private Sub ContentLabel_Click(sender As Object, e As EventArgs)
currentLabel = DirectCast(sender, Label)
InputTextBox.Text = currentLabel.Text
End Sub
Continue reading...
Some of the code I use is shown below.
Dim recipeSelected As String = TitleListBox.SelectedItem.ToString()
Dim result = recipesLst.Where(Function(x) x.RecipeName = recipeSelected).FirstOrDefault()
'Form1.TextBox1.Text = result.ID.ToString()
'Recipe Name Label
Dim TitleFontStyle As FontStyle = FontStyle.Bold + FontStyle.Italic
Dim TitleFont As New System.Drawing.Font("Comic Sans MS", 14, TitleFontStyle)
Dim RecipeNameLabel As New Label()
With RecipeNameLabel
.AutoSize = True
.MaximumSize = New Size(370, 100)
.MinimumSize = New Size(370, 10)
.TextAlign = ContentAlignment.MiddleCenter
.Text = result.RecipeName
If TestModeCheckBox.Checked = True Then
.BackColor = Color.Gold
Else
.BackColor = Color.Transparent
End If
.Font = TitleFont
.Location = New Point(75, 50)
End With
Controls.Add(RecipeNameLabel)
RecipeNameLabel.Parent = Form1
X = RecipeNameLabel.Left
Y = RecipeNameLabel.Bottom + 10
AddHandler RecipeNameLabel.Click, AddressOf ContentLabel_Click
'Comment Label
Dim CommentLabel As New Label()
With CommentLabel
.AutoSize = True
.MaximumSize = New Size(200, 150)
.MinimumSize = New Size(150, 10)
.TextAlign = ContentAlignment.MiddleLeft
.Text = result.Comment
If TestModeCheckBox.Checked = True Then
.BackColor = Color.Gold
Else
.BackColor = Color.Transparent
End If
.Font = New System.Drawing.Font("Comic Sans MS", 8)
.Location = New Point(X, Y)
End With
Controls.Add(CommentLabel)
CommentLabel.Parent = Form1
X = CommentLabel.Left
Y = CommentLabel.Bottom
AddHandler CommentLabel.Click, AddressOf ContentLabel_Click
'Quantity Label
Dim QuantityLabel As New Label()
With QuantityLabel
.AutoSize = True
.MaximumSize = New Size(360 - CommentLabel.Width, 150)
.MinimumSize = New Size(360 - CommentLabel.Width, 10)
.TextAlign = ContentAlignment.BottomRight
.Text = result.Quantity
If TestModeCheckBox.Checked = True Then
.BackColor = Color.Gold
Else
.BackColor = Color.Transparent
End If
.Font = New System.Drawing.Font("Comic Sans MS", 8)
.Location = New Point(445 - QuantityLabel.Width, CommentLabel.Bottom - QuantityLabel.Height)
End With
Controls.Add(QuantityLabel)
QuantityLabel.Parent = Form1
AddHandler QuantityLabel.Click, AddressOf ContentLabel_Click
Private Sub ContentLabel_Click(sender As Object, e As EventArgs)
currentLabel = DirectCast(sender, Label)
InputTextBox.Text = currentLabel.Text
End Sub
Continue reading...