Click here to Skip to main content
15,886,036 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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,
Posted
Updated 12-Mar-13 4:15am
v2
Comments
joshrduncan2012 12-Mar-13 10:16am    
Can you show us what you have so far? Where are you stuck in your code?
[no name] 12-Mar-13 10:17am    
First off it's MessageBox.Show as C# is case sensitive. What did you try? MessageBox.Show(yourtextbox.Text) should work for you.
vebi1000 12-Mar-13 10:24am    
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.
[no name] 12-Mar-13 10:35am    
Then you are creating your very own messagebox. You cannot do what you think you want to do (which is a very bad idea to begin with) with a standard message box.

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:
C#
FormBorderStyle = FixedToolWindow
ShowInTaskBar = False
StartPosition =  CenterScreen
And use the ShowDialog method to display it.
 
Share this answer
 
v2
Comments
vebi1000 12-Mar-13 10:31am    
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?
OriginalGriff 12-Mar-13 11:16am    
Answer updated
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.
 
Share this answer
 
Comments
vebi1000 12-Mar-13 10:37am    
Hi, Thanks for your clarification, I need a separate form with two buttons, textbox and label then i need to use "MyForm.ShowDialog()" to display that form and i need one property that will read textbox and update it in the old one.
Pheonyx 12-Mar-13 10:42am    
That should do what you are trying to achieve yes.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900