auto update the mycode.cs to reflect changes in mycode.cs [Design]

hi, is that a way to automatically update (by pressing a button or click from menu) to update the "mycode.cs" file to reflect the changes we did in "mycode.cs [Design]", for example when changing button name, changing form name from Form1 to something else, or changing namespace or there is just no way to update them (i guess that is impossible, there should be a way)

anyone know maybe could share with me



Answer this question

auto update the mycode.cs to reflect changes in mycode.cs [Design]

  • Alexis Valle

    eg.
    you create a button named "btnSleep" in [Design] and double click it, in code section, you would get
    private void btnSleep_Click(object sender, EventArgs e)
    {
    System.Windows.Forms.MessageBox.Show("hello world!"); // i add this myself.
    }
    

    Ctrl + F5 to run it and you would see "hello world!"; then back to design form, rename the button to "btnOk", save them all.
    go to code section and you would see, nothing is updated!! it is ok, but the weird thing is, when you Ctrl + F5 to run it, it would build successfully and clicking "btnOk" now, (after we rename it) would yield "hello world!" too! ... i mean, how come
    if the code wasn't updated to reflect the changes, how come the output still get "hello world!" unless the compilation doesn't really follow what inside the code section.

    now i am really confused


  • Emilian

    hi shakalama, thanks for reply,
    i did notice the "pink square" you mentioned about, and try replace it. and it seems to me the studio doesn't reflect the changes in XYZ.designer.cs file.

    it just doesn't seem easy to change a button name or something else and get the event name to be same as the button name.

    and some time, the pink square just didn't show up. . and even if it show up, usually is after i type the name manually then only it suggest to replace. lmao.


  • nilsandrey

    hi,

    there are many ways to do that

    1) during changes:- in Mycode.cs change any method name in your example change btnsleep_click to anything you will notice a pink square at the end of the name put your mouse over it , it will show a button click that button it will give you options

    2) you can use replace: from your edit menu find a quick replace and click it it will open a dialog for you put the old name and the new name and start to replace

    hope this helps



  • DemianRulEZ

    mmmm

    i guess i understood now, the reflect will not work like that

    to change a variable name in your class you have to change the declaration of the variable nothing else

    for example

    1 - Button button1 = new Button();

    2 - buttn1.text ="something";

    if you changed button1 to btn , the reflect will change the button1 in the second line,

    but if you changed button1 in line two it will not affect line 1 at all

    so you can't creat an instance in the designer "button1" and change it to something else from the code view, you have to change the variable declaration

    hope this helps



  • auto update the mycode.cs to reflect changes in mycode.cs [Design]