-1

I am trying to rename a button from a string. Sounds simple enough? Well I have scowered the internet and tried many things however I keep coming up with the same errors.

I have 2 forms and one class file. I am using object orientation to pass a string from a textbox to form1 where upon the "button1.Text" can be change passing it through my "Reference class" (I don't think it can be done any other way)

    private void button1_Click_1(object sender, EventArgs e)
    {
        Refclass Ref = new Refclass();
        String but1 = Ref.but1;

        String btn = "button1"; this.Controls[btn].Text = but1;
    }

I am sure this is probably wrong but I hope by this might be able to understand what I am trying to do. I am calling a string from the "Ref" class and calling the string "hell"

Needless to say I am either getting a debugging error and totally crashing visual studio or I get an error saying "Object reference not set to an instance of an object."

I know I am going wrong somewhere does anyone know where? Thank you.

skaffman
  • 398,947
  • 96
  • 818
  • 769
Marshal
  • 1,177
  • 4
  • 18
  • 30

1 Answers1

1

there is no need of create the object for class.if your class in same assembly.just call like this.

button1.text=ref.but1;

where but1 is a const string in that class.

joshua
  • 2,371
  • 2
  • 29
  • 58
  • This almost worked. It changed to nothing as in "". I think theres an issue with permissions now maybe the class is set to private. Another issue is I have no idea how to make a class you create inside a form; public. Thanks for your help though. – Marshal Feb 01 '12 at 12:38
  • you only have to declare that string as `public Const string`. don't bother for same assembly class's cause by default it's internal.so its accessible for you. otherwise you can declare class as public – joshua Feb 02 '12 at 06:37
  • you only have to declare that string as public Const string. dont be bother for same assembly class cause by default it is internal.so its accessible for you. otherwise you can declare class as public – joshua Feb 02 '12 at 06:37