如何使用代码从表单2中的表单1访问按钮。 [英] How do I access a button from form 1 in form 2 with code.

查看:116
本文介绍了如何使用代码从表单2中的表单1访问按钮。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很大的问题。最近我一直在为我的一个项目工作只是为了好玩。



我遇到了一个问题,基本上,让我切入追逐。 />


我有两种形式。表格1和表格2.



表格1有几个面板,其中一个面板称为formPanel1,形式为1.现在,我想要能够通过表单2中的按钮更改该面板的背景颜色(并且此面板处于表单1中)。问题是,它在form2中的代码中不存在,它只存在于表单1中。我想要能够改变表格1到表格2中某个面板的颜色。



请帮助,我真的想完成,这意味着很多。



[在此处输入图片说明] [1]



[1]:https://i.stack。 imgur.com/u7jpS.png - - 这是我目前的项目。



[1]:https://i.stack.imgur.com/atkgF。 png - - 这是我要改变颜色的面板。



[1]:https://i.stack.imgur.com/dpvb3.png - - 这是我要点击的按钮,以便更改表单1中该面板的颜色(此按钮的格式为2)



我有什么尝试过:



我尝试了很多东西。这确实包括其他网站。它们没有意义。



它们要么使用两种不同的东西,要么它们给出的代码对我的代码不起作用

I have a huge question. Recently I've been working on a project of mine just for fun.

I ran into a problem where, well basically, let me cut to the chase.

I have two forms. FORM 1, and FORM 2.

Form 1 has a couple panels, and one of those panels is called formPanel1, which is in form 1. Now, I want to be able to change the backcolor of that panel (and this panel is in form 1) through a button in form 2. The problem is, it doesn't exist in the code in form2, it only exist's in form 1. I want to be able to change the color of that certain panel in form 1 through form 2.

Please help, I really want to finish, it would mean LOTS.

[enter image description here][1]

[1]: https://i.stack.imgur.com/u7jpS.png - - This is my project so far.

[1]: https://i.stack.imgur.com/atkgF.png - - This is the panel I want to change color of.

[1]: https://i.stack.imgur.com/dpvb3.png - - This is the button I want to click in order to change the color of that panel in form 1 (this button is in form 2)

What I have tried:

I have tried many things. That does include other sites. They don't make sense.

They either use two different things, and the code they give doesn't work for my code

推荐答案

查看以下链接是否有帮助



c# - 如何访问另一个表单的表单控件? - 堆栈溢出 [ ^ ]



C#winform:从其他形式访问公共财产&静态和公共属性之间的区别 - 堆栈溢出 [ ^ ]
See if the below links help

c# - How to access a form control for another form? - Stack Overflow[^]

C# winform: Accessing public properties from other forms & difference between static and public properties - Stack Overflow[^]


这篇关于如何使用代码从表单2中的表单1访问按钮。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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