如何在messagebox中显示文本框信息。 [英] how to display textbox information in messagebox.

查看:188
本文介绍了如何在messagebox中显示文本框信息。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我正在尝试在c#中创建GUI。我最近开始学习c#。我正在使用Windows应用程序。我有一个主窗体和几个用户控件。我有主要形式的开始按钮。当我点击那个按钮我想检查一个用户控件文本框值是对还是错。



所以当我点击那个按钮时我需要显示一条消息请验证传输量以及文本框,文本框的值和确定,取消按钮。



我试过messageBox.show,但我无法显示文本框及其来自用户控件的值。任何人都可以帮助我。我怎么能这样做。



提前谢谢,

Hi,

I am trying to create GUI in c#. I have started learning c# recently. I am using windows application from. I have one main form and several user controls. I have start button in main form. when i click that button i want to check one of the user control textbox value is right or wrong.

So when i click that button I need to display a message "please verify transfer volume" along with textbox, value of text box and ok, cancel buttons.

I have tried with "messageBox.show" but i am not able to display textbox and its value from user control. Can any one help me with that. how can i do it.

Thanks in advance,

推荐答案

基本上,你不应该这样做。

问题是用户控件应该是一个黑盒子 - 你的表单不应该告诉它的内容是什么,除了它公开曝光的项目。 br />


因此,您的UserControl需要提供一个属性来返回文本框内容,或者(可能更好)自己进行验证。



这里有一个提示描述:在两个表格之间传递信息,第2部分:儿童到父母 [ ^ ] - 它是基于表单的,但同样适用于UserControls。



我不想显示textbox.T在MessageBox.Show方法中,我试图在MessageBox.Show()方法中创建一个textBox,MessageBox.Show中的textBox应该包含用户控件中其中一个文本框的相同内容,如果我在MessageBox方法中更改它有改变那里。可能吗?





No.



你不能改变标准消息框 - 它们就是它们。

但是用你想要的所有功能创建你自己的消息很容易。只需创建一个新的表单,适当调整大小,并添加实际需要的按钮。

设置这些属性:

Basically, you shouldn''t do that.
The problem is that the usercontrol should be a "black box" - your form should not be able to tell what it''s content is, except for the items it publicly exposes.

So, either your UserControl needs to provide a property to return the textbox content or (possibly better) do the validation itself.

There is a Tip here which describes this: Transfering information between two forms, Part 2: Child to Parent[^] - it''s form based, but the same thing applies to UserControls as well.

"I don''t want to show textbox.Text in MessageBox.Show method, I am trying to create a textBox in MessageBox.Show() method, the textBox in MessageBox.Show should contain the same content of one of the textbox in user control and if i change in MessageBox method it has to change there. Is it possible?"


No.

You can''t change "standard" messageboxes - they are what they are.
But it''s pretty easy to create your own, with all the functionality you want. Just create a new form, size it appropriately, and add the buttons you actually need.
Set these properties:
FormBorderStyle = FixedToolWindow
ShowInTaskBar = False
StartPosition =  CenterScreen

并使用ShowDialog方法显示它。

And use the ShowDialog method to display it.


Hi Vebi,



我不相信你正在尝试实现的目标是可行的。

但是,如果你创建了自己的消息框表单,其上有文本盒子,标签和两个按钮然后你可以从那里工作,以达到理想的效果。



例如,



MyCustomMessageBox可以是一个在i上具有给定控件的表单已经。

然后给MyCustomMessageBox一个自定义的Show方法,或者一个自定义的Constructor,你传递要显示的值。

你给表单一个只读属性名为NewTextboxValue,它返回文本框中的值。



然后调用MyCustomMessageBox.Show并监视表单以便关闭。表单关闭后,使用新值更新初始文本框。
Hi Vebi,

I do not believe that what you are trying to achieve is possible in the approach you are taking.
However, if you create your own "message box" form which has on it a text box, a label and two buttons then you could work from that to achieve the desired affect.

For example,

MyCustomMessageBox could be a form that has the given controls on it already.
MyCustomMessageBox is then given either a custom "Show" method, or a custom Constructor into which you pass the values to be displayed.
You give the form a read only property called "NewTextboxValue" which returns the value in the text box.

You then called "MyCustomMessageBox.Show" and monitor the form for closing. Once the form closes update your initial textbox with the new value.


这篇关于如何在messagebox中显示文本框信息。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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