473,326 Members | 2,173 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,326 software developers and data experts.

Control is inaccessible

hi,

In C#.Net, if i have a form1 and i want to access one of the controls of
form2(eg a label) from Form1, it gives an error.
(Label1 is Inaccessible, due to its protection level)

However, i was able to do the same is vb.net.
How to get around with this inaccessibility. Do i have to create wrapper in
form2 everytime i want to access one of the control of form1.

TIA
Irfan


Oct 16 '06 #1
2 1566
Irfan <ir***@asc-ltd.co.ukwrote:
In C#.Net, if i have a form1 and i want to access one of the controls of
form2(eg a label) from Form1, it gives an error.
(Label1 is Inaccessible, due to its protection level)

However, i was able to do the same is vb.net.
How to get around with this inaccessibility. Do i have to create wrapper in
form2 everytime i want to access one of the control of form1.
Well, you *could* just make label1 public, but that's a bad idea in
terms of encapsulation.

What would often be better is to write a method in Form2 (which I hope
will have a more descriptive name by the time you've finished) which
changes the text of label1, or whatever it is you need to do from
form1.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Oct 16 '06 #2
thanks for the reply. I created a public method in form2 that updates its
labels.

Thanks Again
irfan

"Jon Skeet [C# MVP]" <sk***@pobox.comwrote in message
news:MP************************@msnews.microsoft.c om...
Irfan <ir***@asc-ltd.co.ukwrote:
>In C#.Net, if i have a form1 and i want to access one of the controls of
form2(eg a label) from Form1, it gives an error.
(Label1 is Inaccessible, due to its protection level)

However, i was able to do the same is vb.net.
How to get around with this inaccessibility. Do i have to create wrapper
in
form2 everytime i want to access one of the control of form1.

Well, you *could* just make label1 public, but that's a bad idea in
terms of encapsulation.

What would often be better is to write a method in Form2 (which I hope
will have a more descriptive name by the time you've finished) which
changes the text of label1, or whatever it is you need to do from
form1.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Oct 17 '06 #3

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

Similar topics

7
by: spam | last post by:
The following code does not compile: class X {}; class Y : private X {}; class Z : public Y { public: Z(X&) {} // problem here
2
by: Sunny | last post by:
Hi all, My dev platform: VS .net 2003, win2000pro, office 2000, MOD 2000, C#. Bellow you may read my posting in other group. According that issue, I have dig around and I'm wondering ... My...
17
by: e-mid | last post by:
i have a user control (say myUserControl) that inherits panel, i create some textboxes on myUserControl dynamically, then i create some myUserControls on the form dynamically with a loop . of...
1
by: Larry | last post by:
I have a VB background and am developing a new windows app in Csharp. I'm getting the error. 'inaccessible due to its protection level' I've added a TextBox1 and a Button1 to a form. I...
1
by: Thomas Barnet-Lamb | last post by:
I was wondering if anyone could give me some help with the following. Consider the code snippet: struct qqq{typedef qqq* pointer;}; template<class al> struct foo : public al { template...
3
by: Eric Sabine | last post by:
I've created a custom control (ascx) which contains a tree view, a drop down list, and a listbox. The custom control is included in a web form and at runtime, won't compile (I get the...
1
by: keithb | last post by:
I need help connecting an image button in a GridView control to an event handler. Using the OnCommand property results in the following error: Error 3...
3
by: chessitguy | last post by:
I have a simple Wizard page.aspx <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0" > <WizardSteps> <asp:WizardStep ID="WizardStep1" runat="server" Title="Main"> <Acme:Main...
15
by: Victor Bazarov | last post by:
Hello, Take a look at this program: ----------------------------------- class B { B(const B&); B& operator=(const B&); public: B(int);
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.