如何通过另一个表格图片框更改图片框的颜色 [英] How do I change color of picturebox choose by another form picturebox

查看:55
本文介绍了如何通过另一个表格图片框更改图片框的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何更改图片框的颜色选择另一个form2图片框

考虑我在我的form1中有四个图片框作为引导形式

现在我有第二个表格有四个带有不同颜色的图片盒的backcolored图片盒



如何运行应用程序

并点击图片框来自2填充

现在颜色必须由此提供



使用发送方式...



我尝试了什么:



How do i change color of picturebox choose by another form2 picturebox
consider i have four picture box in my form1 as boot form
now i have second form with four backcolored picturebox with differently colored picturebox

how when run the application
and click a picture-box from2 populates
now color has to be supplied by this

use the method sender...

What I have tried:

Dim jb As PictureBox = DirectCast(sender, PictureBox)
      jb.BackColor = form1.sender.backcolor

推荐答案

尝试以下步骤:



第1步:首先让我们从一个空白项目开始学习。

首先创建一个新项目并将其命名为y你需要。

项目加载后,继续执行第2步。



第2步:继续在项目中添加第二个表单。也许把这个表格称为frmColorPicker。在frmColorPicker上,为调色板添加所需的图片框数量,并将其BackColor属性设置为所需的颜色。

     - 双击任何PictureBoxes以显示代码编辑器。您会注意到它会调出PictureBoxes的Click Handler。

     - 在它所说的Private Sub Picturebox_Click ..... Handles ...

我们将告诉解析器这个Sub Procedure将通过附加用逗号分隔的每个对象名来处理多个对象的click事件

Try these steps:

Step 1: First off let us start with a blank project for learning purposes.
So start by creating a new project and name it what ever you want.
After the project loads, proceed to step 2.

Step 2: Go ahead and add a second form to your project. Maybe call this form frmColorPicker. On frmColorPicker, Add the number of pictureboxes you want for the color palette and set their BackColor properties to the desired colors.
    -Double click any of the PictureBoxes to bring up the Code Editor. You will notice that it will bring up the PictureBoxes's Click Handler.
    -On the line where it says Private Sub Picturebox_Click.....Handles...
we are going to tell the parser that this Sub Procedure will handle more than one object's click event by appending each object name separated by a comma
Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click '<--This is where we append the objects
    ActivePbox.BackColor = sender.backcolor
    Me.Close()
End Sub



     - 当我们在代码编辑器中时,请继续添加以下代码


    -Also while we are in the code editor, Go ahead and add the code below

Dim ActivePbox As PictureBox
Public Function SelectColor(PictureboxToChange As PictureBox)
    ActivePbox = PictureboxToChange
    Me.ShowDialog()
End Function



     - 在图片框的点击事件处理程序中添加上面点击事件处理程序的代码。



第3步:返回Form1。将您想要的图片框添加到表单中。

     - 双击其中一个图片框以打开代码编辑器。您将再次注意到click事件处理程序将在那里。继续按照您在步骤2中添加的其他图片框。

     - 这里我们将添加以下代码。


    -And add the code from the click event handler from above inside the picturebox's click event handler.

Step 3: Go back to Form1. Add the pictureboxes you want to the form.
    -Double click one of the pictureboxes to open the code editor. You will notice again that the click event handler will be there. Go ahead and append the other pictureboxes like you did in step 2.
    -Here we will add the following code.

frmColorPicker.SelectColor(sender)





---------------- -------------------------------------------------- ----------------

检查您的代码:

Form1代码应该看起来类似于以下代码:



----------------------------------------------------------------------------------
CHECK YOUR CODE:
Form1 code should look similar to the following code:

Public Class Form1

    Private Sub PictureBox1_Click(sender As System.Object, e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click, PictureBox3.Click, PictureBox4.Click
        frmColorPicker.SelectColor(sender)
    End Sub

End Class





frmColorPicker代码应类似于以下代码:



frmColorPicker code should look similar to the following code:

Public Class frmColorPicker
    Dim ActivePbox As PictureBox
    Public Function SelectColor(PictureboxToChange As PictureBox)
        ActivePbox = PictureboxToChange
        Me.ShowDialog()
    End Function

    Private Sub PictureBox1_Click(sender As Object, e As System.EventArgs) Handles PictureBox1.Click, PictureBox2.Click
        ActivePbox.BackColor = sender.backcolor
        Me.Close()
    End Sub
End Class





------------------- -------------------------------------------------- -------------

这有助于你做你想做的事吗?



----------------------------------------------------------------------------------
Does this help you to do what you are wanting?


这篇关于如何通过另一个表格图片框更改图片框的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆