Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Windows WinForm
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 12-Mar-13 5:14am
Edited 12-Mar-13 5:15am
v2
Comments
joshrduncan2012 at 12-Mar-13 10:16am
   
Can you show us what you have so far? Where are you stuck in your code?
ThePhantomUpvoter at 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 at 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.
ThePhantomUpvoter at 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.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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
And use the ShowDialog method to display it.
  Permalink  
v2
Comments
vebi1000 at 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 at 12-Mar-13 11:16am
   
Answer updated
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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.
  Permalink  
Comments
vebi1000 at 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 at 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)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 575
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 369
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,476
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,917


Advertise | Privacy | Mobile
Web03 | 2.8.141223.1 | Last Updated 12 Mar 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100