Ultimate V

I am getting a "Compiler Error CS0122"

i cannot change the text of an item from another form.

how do i change the access level of the item so that it can be changed from an external form

i would like an MS professional only to answer this for me please.

because they know what they're doing

i have code below to show you what i have so far...

This bit of code below is from the external FORM called 'Stream_2007.addressChangeBox'

private void button1_Click(object sender, EventArgs e)

{

mainForm.address.Text = firstOctet.Text + "." + secondOctet.Text + "." + thirdOctet.Text;

}

This is my error: 'Stream_2007.mainForm.address' is inaccessible due to its protection level

Below is the code for the form: 'Stream_2007.mainForm'

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

///

///

namespace Stream_2007

{

public partial class mainForm : Form

{

public mainForm()

{

InitializeComponent();

}

//START// Channels A-D //

the code here as nothing to do with my problem

//END// Channels A-D //

///

///

///

//START// SatChannels A-D //

neither does this

//END// satChannels A-D //

// BOTH of the next two codes should be the same!!!

this too

// END OF BOTH

private void changeAddreButton_Click(object sender, EventArgs e)

{

new addressChangeBox().Show();

}

}

}

I am so very sorry to have to show all of this code, but i dont know where to insert the new access level code there should be.... i hope you can tell me




Re: Visual C# Express Edition Access Modifiers

TilakGopi

Hi,

have public static mainForm gvMF;// in mainForm class.

gvMF = this; //in form_load of mainForm

//and now you can use mainForm reference directly in any external class, and in your case ,it can be used as

private void button1_Click(object sender, EventArgs e)

{

mainForm.gvMF.address.Text = firstOctet.Text + "." + secondOctet.Text + "." + thirdOctet.Text;

}

This is bit simpler way and works fine.

Thanks,

Ch.T.Gopi Kumar.






Re: Visual C# Express Edition Access Modifiers

Ultimate V

sorry but it still says its protection level is too high

i think i put the code in the right place....look

private void button1_Click(object sender, EventArgs e)

{

mainForm.gvMF.addressMain.Text = firstOctet.Text + "." + secondOctet.Text + "." + thirdOctet.Text;

}

and in the mainForm too, see....

public partial class mainForm : Form

{

public static mainForm gvMF;

public mainForm()

{

InitializeComponent();

gvMF = this;

}






Re: Visual C# Express Edition Access Modifiers

TilakGopi

Hi,

sorry , i missed to specifying change the access specifier of addressMain ,make it access specifier as public or define a public property for it.

which is better out of these two

Well, mostly depends on your design ,since it first case (Making the control as public member)you are exposing the control out side,giving full access over the control .

In second case(Defining a property for the control to get/set it's text) ,you are just allowing the user to set and get the text of the control.

Thanks,

Ch.T.Gopi Kumar.






Re: Visual C# Express Edition Access Modifiers

Figo Fei - MSFT

Hi, Ultimate V

You want to access the item from one form to another in single assembly, right

If so, you don't need to create static member for this purpose, just passing the form instance can do.

see: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1405754&SiteID=1

If you have further problem please feel free to tell me.

Thanks






Re: Visual C# Express Edition Access Modifiers

TilakGopi

Hi Figo,

The solution you gave for this problem, was the one i used to follow earlier.But last time ,i got this idea,making the form1 reference as a static member in the form1 itself, so that all the public controls of the form1 class can be accessd from any form with out having need to pass the reference to each form in which you want to use Form1 public members.

Is it not a better way that passing reference to other form

What types of problems , we may face by making the static referecne of a form and using it

What is the effect of having a static reference for the same class in a class

Could you please clear above doubts

Thanks in advance.

Best Regards,

Ch.T.Gopi Kumar.






Re: Visual C# Express Edition Access Modifiers

Figo Fei - MSFT

Hi, TilakGopi

What I showed is just one method of implementing this function but not only method, of course.

If you could put a snippet code to make your implementation clearer, we could do further discussion.

Smile

Thank you.






Re: Visual C# Express Edition Access Modifiers

TilakGopi

Figo Fei - MSFT wrote:

Hi, TilakGopi

What I showed is just one method of implementing this function but not only method, of course.

If you could put a snippet code to make your implementation clearer, we could do further discussion.

Thank you.

Yes,

let us have the same problem solved in this thread.

In the mainForm , i have the same class reference , a public static one,initialized to 'this' in constructor.

public partial class mainForm : Form

{

public static mainForm gvMF;

public mainForm()

{

InitializeComponent();

gvMF = this;

}

in a child form button click,i'm accessing mainForm.gvMF and it's public memeber addressMain as follows..

private void button1_Click(object sender, EventArgs e)

{

mainForm.gvMF.addressMain.Text = firstOctet.Text + "." + secondOctet.Text + "." + thirdOctet.Text;

}

I hope this example is appropriate for my above questions to get answered.

Thanks & Best Regards,

Ch.T.Gopi Kumar.






Re: Visual C# Express Edition Access Modifiers

Figo Fei - MSFT

TilakGopi wrote:
In the mainForm , i have the same class reference , a public static one,initialized to 'this' in constructor.

public partial class mainForm : Form

{

public static mainForm gvMF;

public mainForm()

{

InitializeComponent();

gvMF = this;

}

in a child form button click,i'm accessing mainForm.gvMF and it's public memeber addressMain as follows..

private void button1_Click(object sender, EventArgs e)

{

mainForm.gvMF.addressMain.Text = firstOctet.Text + "." + secondOctet.Text + "." + thirdOctet.Text;

}

I hope this example is appropriate for my above questions to get answered.

Thanks & Best Regards,

Ch.T.Gopi Kumar.

Hi, TilakGopi

Since you've make the mainForm reference(gvMF) static and valuate it with this (an instance of mainForm class),

however, I can't see where is the constructor to create the instance! So it will not work.

Thanks






Re: Visual C# Express Edition Access Modifiers

TilakGopi

Thanks Figo,

for taking time to clear my doubts.

Best Regards,

Ch.T.Gopi Kumar






Re: Visual C# Express Edition Access Modifiers

Figo Fei - MSFT

You're welcome.

Also thanks for your contribution in this forum. Smile






Re: Visual C# Express Edition Access Modifiers

TilakGopi

I'm enjoying much my participation in these forums,

First of all, i have to say thanks for MicroSoft , for providing these forums.

It's 'the best' way, one can share knowledge and learn new things.

And thanks to you guys for guiding me professionally into the right directions with your appropriate answers.

Best Regards,

Ch.T.Gopi Kumar.






Re: Visual C# Express Edition Access Modifiers

Ultimate V

Hi, Figo Fei

I am sorry but i have no clue what your guys are talking about.

you posted the link, http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=1405754&SiteID=1

but i dont understand a word said in there

could you edit the code i posted with the changes, or tell me so i know exactly what to add and where

i just started to learn C# and i dont know much about the syntax let alone a "form instance" or any of that stuff

the only thing Visual C# has done to help me throught my chrisis' is the IntelliSence feature " I love it!"

"Help" doesnt do much in VCSharp

the exact probelem is:::

mainForm & addressChange ARE two different forms in my project.

When i click on a button in the"changeAddress" form, specific text in the "mainForm" should change and then close the "changeAddress" dialog box

thanks! and i know you guys are trying to help, i just dont understand quite yet...






Re: Visual C# Express Edition Access Modifiers

Figo Fei - MSFT

Hi, UItimate V

In mainForm.cs file(mainForm class definition):

Code Snippet

public partial class mainForm : Form
{

public System.Windows.Forms.TextBox textBox1;

void Pop_addressChange()

{

addressChange form = new addressChange(this);

form.ShowDialog();

}

//......

}

In addressChange.cs (addressChange class definition):

Code Snippet

public partial class addressChange : Form
{

private mainForm FormRef;

public addressChange(mainForm form)
{
InitializeComponent();
FormRef = form;
}

private void button1_Click(object sender, EventArgs e)

{

FormRef.textBox1.Text = "hello";

//in this way access the textBox1 in mainForm

this.Close(); //close the addressChange form

}

//......

}

In mainForm, put the Pop_addressChange() method into where you would like to generate the addressChange form.

In addressChange form, click the button1 change the text of textBox in mainForm to "Hello" and close the addressChange form.

Note: pay attention to the RED words.

If you have further problem, please feel free to let me know.

Thanks