0

我正在用 c# 制作一个 Windows 窗体应用程序,并为这个应用程序创建屏幕键盘,我对此有一些问题,因为我不知道如何做一些事情。

我有的

  • 带有少量文本框和少量富文本框的 Form1。
  • panel1 带有丰富的文本框和 5 个按钮(A、B、C、DEL、ENTER)。

我想要的是?

  • 每次我单击任何文本框或任何丰富文本框时,我都希望 panel1 出现。
  • 我希望我单击的文本框中的文本显示在 panel1 上的富文本框中。
  • 当我单击 panel1 上的“ENTER”按钮时,我希望将 panel1 上的richtextbox 中的文本传输到我之前单击过的文本框。(当然 panel1 会在那之后隐藏)。

当我点击文本框或richtextbox(我使用过“Enter”事件)时,我已经让panel1显示出来,当我点击它上的“ENTER”按钮时,panel1将隐藏。每次我单击文本框或 Richtextbox 时是否有任何其他方式显示 panel1 而无需为每个事件编码“Enter”事件?

现在最困难的部分是将文本从表单传输到面板,反之亦然。要从单击的文本框中传输文本,我只是在“Enter”事件中添加了一行代码:

文本框1.文本 = 富文本框1.文本;

将文本从richtextbox1 传输回文本框是我的主要问题......我有解决方案,但我正在寻找一个正确和简单的解决方案......我的解决方案太笨拙和复杂......

将在这里解释我在寻找什么: 例如,如果 int 可以记住数字和 string 可以记住文本。我想要一些可以记住我上次点击的文本框的东西。我希望你能明白我的意思。

我的英语不是我的主要语言,所以如果你不能理解任何东西,请回复,我会尽力解释。

感谢大家的时间。

4

1 回答 1

0

I would do these:

  1. Create a base user control that derives from Textbox (if you'll be using only textboxes) or from a Control if there will be more than the textboxes used.

  2. Handle the "Enter" event just as you do now in that base class.

  3. Create the class that will derive from the EventArgs class and that will store a value of yout control. Let's call it "TextboxArgs" for now.

  4. In the base user control, create an event and raise it in the "Enter" handler that you have and use a "TextboxArgs" class form step 3 to pass the text as the event argument.

  5. Subscribe to this event in your panel so it will react properly.

Now, just use this base user control that you have for each textbox and it will raise an event and pass it's value as an argument. Panel will respond to it. If you do it that way then you won't need any additional coding no matter how many textboxes you add.

于 2013-10-26T23:08:32.397 回答