473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Trouble with ShowDialog

Dom
I have a Main form called frmMain which appears when the program
starts, and a second form called frmUserName. frmMain has a button,
btnUserName. When you click it, I have this code:

frmUserName f = new frmUserName ();
f.ShowDialog(this);

For the next line, I expected to find f.txtUserName in the
IntelliSense window, but it's not there. In fact, noneof the controls
are there. Am I just caught in VB think?

Dom

May 10 '07 #1
3 1714
By default controls are private to a form. See the Modifiers property. You
could change this property for the control in question, but I don't think
that's very good practice. Instead, consider adding a parameter to the
form's constructor that receives a user name. That form's constructor would
then assign the received value to its textbox. You would instantiate your
form like this:

--
Brian Schwartz
FishNet Components
http://www.fishnetcomponents.com
Fish Grid .NET Light: Powerful Layouts for Small Datasets
"Dom" <do********@gmail.comwrote in message
news:11**********************@e51g2000hsg.googlegr oups.com...
>I have a Main form called frmMain which appears when the program
starts, and a second form called frmUserName. frmMain has a button,
btnUserName. When you click it, I have this code:

frmUserName f = new frmUserName ();
f.ShowDialog(this);

For the next line, I expected to find f.txtUserName in the
IntelliSense window, but it's not there. In fact, noneof the controls
are there. Am I just caught in VB think?

Dom

May 10 '07 #2
Dom,

Yes, you are thinking in VB.

By default, when adding controls to forms, the fields are added as
private. In the designer, you should go to the control and set the
visiblity (or accessiblity, it's something similar) from private to public.

However, I would say that this is a very, very bad idea from a design
standpoint. Rather, just expose properties that expose the details that you
are looking for and have the properties return them from the controls, if
you must.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dom" <do********@gmail.comwrote in message
news:11**********************@e51g2000hsg.googlegr oups.com...
>I have a Main form called frmMain which appears when the program
starts, and a second form called frmUserName. frmMain has a button,
btnUserName. When you click it, I have this code:

frmUserName f = new frmUserName ();
f.ShowDialog(this);

For the next line, I expected to find f.txtUserName in the
IntelliSense window, but it's not there. In fact, noneof the controls
are there. Am I just caught in VB think?

Dom

May 10 '07 #3
I'll assume that txtUserName is your TextBox? The fields are private
to the class. You can expose them as public, but this is not good
practice; a better approach is a public property to maintain
encapsulation, e.g.

public class frmUserName : ... {
public string UserName {
get {return txtUserName.Text;}
}
...
}

Nowyou should be able to access f.UserName; additionally, you might
want to ensure that this Form gets Dispose()d in a timely fashion:

string username;
using(frmUserName f = new frmUserName()) {
f.ShowDialog(this);
username = f.UserName;
}
// now use username

Marc

May 10 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Richard L Rosenheim | last post by:
I would like to detect when a form is invoked as the result of a ShowDialog call. Anyone have any ideas or suggestions on how to do that? TIA, Richard Rosenheim
2
by: Bill Burris | last post by:
When you crate a Windows application the wizard adds a line like: Application.Run( new MyMainForm() ); Out of curiosity I replaced this with: MyMainForm myForm = new MyMainForm();...
5
by: Josh Golden | last post by:
3 forms. form 1, when button clicked instantiates form 2 which opens but is not shown. form 2 instantiates form 3 as showdialog. form 3 finishes, raises an event that form 2 catches. during the...
4
by: Dennis Sjogren | last post by:
Greetings! First, I'm not 100% sure where to post this question. I use VB.NET for this project, but it's really a design question (a question on which method to use when solving this problem). ...
6
by: Samuel R. Neff | last post by:
I'm having weird results with a form that is already displayed modally (via ShowDialog) displaying a second form via ShowDialog. The last form is not modal even though it's called with ShowDialog....
1
by: No Sheds | last post by:
Hi I have an MDI application. I have a MDI child window within this application that shows another form using ShowDialog. This works fine, except that the final form shown with ShowDialog...
4
by: trialproduct2004 | last post by:
Hi all I am new to vb.net application. I am using showdialog property of form to display form. First time it is working properly. But next time it is giving me error that ' object reference not...
8
by: WvH | last post by:
Hi, When I create a new application, with just one button, then this code works as expected: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles...
5
by: Miro | last post by:
I will try my best to ask this question correctly. I think in the end the code will make more sence of what I am trying to accomplish. I am just not sure of what to search for on the net. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.