Vb.net 从另一个窗体使用rgb滑块更改按钮(文本框等)的背景色和前景色

Vb.net 从另一个窗体使用rgb滑块更改按钮(文本框等)的背景色和前景色,vb.net,Vb.net,所以,是的,我做了一个带有RGB滑块的表单,它会生成一种颜色,当我关闭这个表单时,我的r,g,b变量(整数)会被发送到我的另一个表单,用于更改所选按钮的颜色,这是我到目前为止得到的结果。。。(有些代码用法语表示红色,vert表示绿色,bleu表示蓝色,lbl表示标签,tb表示轨迹栏) 使用自定义事件 Public Class frmColorChange Public Property r As Integer Public Property g As Integer Public Pro

所以,是的,我做了一个带有RGB滑块的表单,它会生成一种颜色,当我关闭这个表单时,我的r,g,b变量(整数)会被发送到我的另一个表单,用于更改所选按钮的颜色,这是我到目前为止得到的结果。。。(有些代码用法语表示红色,vert表示绿色,bleu表示蓝色,lbl表示标签,tb表示轨迹栏)

使用自定义事件

Public Class frmColorChange
 Public Property r As Integer
 Public Property g As Integer
 Public Property b As Integer
 Public Event ColorChanged(r As Double, g As Double, b As Double)
Private Sub tbrouge_Scroll(sender As Object, e As EventArgs) Handles tbrouge.Scroll
 lblrouge.Text = tbrouge.Value
 prgb.BackColor = Color.FromArgb(tbrouge.Value, tbvert.Value, tbbleu.Value)
End Sub

Private Sub tbvert_Scroll(sender As Object, e As EventArgs) Handles tbvert.Scroll
 lblvert.Text = tbvert.Value
 prgb.BackColor = Color.FromArgb(tbrouge.Value, tbvert.Value, tbbleu.Value)
End Sub

Private Sub tbbleu_Scroll(sender As Object, e As EventArgs) Handles tbbleu.Scroll
 lblbleu.Text = tbbleu.Value
 prgb.BackColor = Color.FromArgb(tbrouge.Value, tbvert.Value, tbbleu.Value)
End Sub

Private Sub btn_ok_Click(sender As Object, e As EventArgs) Handles btn_ok.Click
 r = tbrouge.Value
 g = tbvert.Value
 b = tbbleu.Value
 'raise the event
 RaiseEvent ColorChanged(r, g, b)
 Me.Close()
End Sub
End Class
用法:

'on the calling form
Dim frm As New frmColorChanged
Addhandler frm.ColorChanged, AddressOf ColorChanged
frm.ShowDialog()


'event handler
Private Sub ColorChanged(r As Double, g As Double, b As Double)
  'use the variables to set the new color
End Sub
'on the calling form
Dim frm As New frmColorChanged
Addhandler frm.ColorChanged, AddressOf ColorChanged
frm.ShowDialog()


'event handler
Private Sub ColorChanged(r As Double, g As Double, b As Double)
  'use the variables to set the new color
End Sub