472,143 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

C# initializing new modal dialog box

This is a newbie question.

I want to open a new dialog box. I have a couple of text boxes in it that I want to initialize. However, I can't seem to access them from the class from where I am opening the dialog. For instance, I want to init the EditLatitude text box, but I get this compiler error:
System.Windows.Forms.Form does not contain a definition for EditLatitude.
Expand|Select|Wrap|Line Numbers
  1.       private void EditLocationButton_Click(object sender, EventArgs e)
  2.         {
  3.             Form newLocationForm = new NewLocation();
  4.             newLocationForm.EditLatitude = m_nString;
  5.             newLocationForm.ShowDialog();
  6.         }
  7.  
I tried making EditLatitude public, but that didn't help. How can I tie a member variable in to the text box such that it is accessible from my whole app?
May 22 '07 #1
7 9285
Plater
7,872 Expert 4TB
You remembered to add a .Text after your object right?
if you set your textbox to "public" you should have access to it, check to make sure it did not revert back to private
May 22 '07 #2
TRScheel
638 Expert 512MB
This is a newbie question.

I want to open a new dialog box. I have a couple of text boxes in it that I want to initialize. However, I can't seem to access them from the class from where I am opening the dialog. For instance, I want to init the EditLatitude text box, but I get this compiler error:
System.Windows.Forms.Form does not contain a definition for EditLatitude.

private void EditLocationButton_Click(object sender, EventArgs e)
{
Form newLocationForm = new NewLocation();
newLocationForm.EditLatitude = m_nString;
newLocationForm.ShowDialog();
}

I tried making EditLatitude public, but that didn't help. How can I tie a member variable in to the text box such that it is accessible from my whole app?

This seems like what you need:

Expand|Select|Wrap|Line Numbers
  1. partial class MyDialogForm
  2. {
  3. // The other members of the class
  4.  
  5. public string TheText
  6. {
  7. get { return MyTextBox.Text; }
  8. set { MyTextBox.Text = value; }
  9. }
  10. }
May 22 '07 #3
Yes, I did that too. It kind of appears from the error message that it thinks my text box is a member of System.Windows.Forms.Form, rather than of my dialog box:

'System.Windows.Forms.Form' does not contain a definition for 'EditLatitude'
May 22 '07 #4
This seems like what you need:

Expand|Select|Wrap|Line Numbers
  1. partial class MyDialogForm
  2. {
  3. // The other members of the class
  4.  
  5. public string TheText
  6. {
  7. get { return MyTextBox.Text; }
  8. set { MyTextBox.Text = value; }
  9. }
  10. }
Thanks. That does look like what I need. I fear the class that Visual Studio generated for me for the modal dialog form is screwed up, though. If I try to access the get_setLatitude property from outside the class, I get error CS0117: 'System.Windows.Forms.Form' does not contain a definition for 'get_setLatitude'.
Here is my class:
Expand|Select|Wrap|Line Numbers
  1. namespace CombineSimCSharp
  2. {
  3.     public partial class NewLocation : Form
  4.     {
  5.         public string get_setLatitude
  6.         {
  7.             get
  8.             {
  9.                 return EditLatitude.Text;
  10.             }
  11.             set
  12.             {
  13.                 EditLatitude.Text = value;
  14.             }
  15.         }
  16.         public NewLocation()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.     }
  21. }
  22.  
Sorry for the newbie questions, and I really do appreciate your help.
May 22 '07 #5
TRScheel
638 Expert 512MB
Thanks. That does look like what I need. I fear the class that Visual Studio generated for me for the modal dialog form is screwed up, though. If I try to access the get_setLatitude property from outside the class, I get error CS0117: 'System.Windows.Forms.Form' does not contain a definition for 'get_setLatitude'.
Here is my class:
Expand|Select|Wrap|Line Numbers
  1. namespace CombineSimCSharp
  2. {
  3.     public partial class NewLocation : Form
  4.     {
  5.         public string get_setLatitude
  6.         {
  7.             get
  8.             {
  9.                 return EditLatitude.Text;
  10.             }
  11.             set
  12.             {
  13.                 EditLatitude.Text = value;
  14.             }
  15.         }
  16.         public NewLocation()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.     }
  21. }
  22.  
Sorry for the newbie questions, and I really do appreciate your help.
Um this sounds dumb... but restart your computer.

It looks like a VS bug I have came across before where it wont recognize members of classes and the autofill needs to be smacked.

Because if EditLatitude AND that property are both public, then it should see it.
May 22 '07 #6
epoch
3
did you try to change this line
Form newLocationForm = new NewLocation()

to this:
NewLocation newLocationForm = new NewLocation()

???
May 25 '07 #7
Plater
7,872 Expert 4TB
did you try to change this line
Form newLocationForm = new NewLocation()

to this:
NewLocation newLocationForm = new NewLocation()

???
That is a HUGE catch, I missed it myself. I would say that is TOTALLY the issue. Your custom form is getting cast as a basic Form at creation.
May 25 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Patrick Lim | last post: by
2 posts views Thread by martin de vroom | last post: by
2 posts views Thread by Gilles T. | last post: by
2 posts views Thread by cassidyc | last post: by
3 posts views Thread by Earl Teigrob | last post: by
10 posts views Thread by Guadala Harry | last post: by
2 posts views Thread by sthrudel | last post: by
reply views Thread by Saiars | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.