C#如何更改form2上form3标签中的文本? [英] C# how to change text in a label on form3 from form2?

查看:71
本文介绍了C#如何更改form2上form3标签中的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里的第一篇文章,希望人们能够帮助我,我是C#的总菜鸟所以完全需要勺子喂食。所以让我设置到目前为止我所做的...



Form1是我的标题画面。

Form2是我的主要游戏界面,通过鼠标点击屏幕上的内容进行交互。

Form3设置为侧窗,有一个图片框和两个标签集起来。



所以..在表单2中我想点击一张图片,(这就像一个按钮,因为它有一个角色的图像在那里),我想要点击以3种方式对Form3进行更改...



在图片框中显示该人的面部图片,

一个标签显示该字符名称。

另一个标签显示我在代码中键入的任何文本以供显示。



Think有点像RPG,当你走到NPC并与他们交谈时,会弹出一个对话框,上面有他们的脸部图片,显示名字,然后是他们说的话。



我现在已经尝试了大约7个小时才弄清楚但是好吧......我不是一个戒烟的人但是我的耐心是在经过几个小时被困在同一件事上之后运行得非常低,所以对我如何的任何建议请以最简单的方式让我理解?



谢谢



什么我试过了:



我已经尝试了太多的YouTube指南和指南,网站列出来这里。

Hi, my first post here, hopefully people will be able to help me with this, i'm a total noob at C# so totally need spoon feeding. SO let me set up what I have done so far..

Form1 is my title screen.
Form2 is my main game screen where interactions are done via mouse clicking things on the screen.
Form3 is set up as a side window that has a picturebox and two labels set up.

so.. in form 2 i want to click a picture, (that's acting as a button cos it has an image of a character in there), and I want that click to make changes to Form3 in 3 ways...

Display the face picture of that person in the picture box,
The one label to display that characters name.
The other label to display any text I type in the code for it to display.

Think kinda like an RPG when you walk up to an NPC and talk to them, a dialogue box pops up with their face picture there, name displayed, and then whatever they say.

I've tried for about 7 hours now to figure it out but well.. i'm not one for quitting but my patience is running very low after many hours of being stuck on the same thing, so any suggestions on how I achieve this please in the easiest way possible for me to understand?

Thanks

What I have tried:

I've tried way too many YouTube guides and guides off websites to list here.

推荐答案

有几种方法要做到这一点,最简单的方法是在设计器上将表单上的控件设置为Public而不是Private,但这被认为是不好的做法。



你可以找到另一个解决方案这里:如何更改文字在Visual C#中另一个表单的文本框中? - 堆栈溢出 [ ^ ]
There are several ways to do it, the simplest is to make the controls on your forms Public instead of Private in the Designer, but this is considered bad practice.

You can find another solution here: How to change text in a textbox on another form in Visual C#? - Stack Overflow[^]


这篇关于C#如何更改form2上form3标签中的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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