xsharp.eu • Winforms ViewCode does not open code
Page 1 of 2

Winforms ViewCode does not open code

Posted: Mon Aug 22, 2022 5:03 pm
by ic2
We have Winforms form, see MyWindow.prg with a toolbar with some buttons. I see that there's a right mouse menu option View code in the MyWindow.prg [Design].

The code behind of the buttons resides in a separate program MyWindowCode.prg. When I try View code the code file MyWindow.prg is opened and the cursor is placed on top. But that's not where my code is.

Now I have to open a Properties tab first, copy the name from (Design) and paste it in a solution wide Search box.

Is there something I can do to do that less time consuming?

Dick

Winforms ViewCode does not open code

Posted: Mon Aug 22, 2022 6:36 pm
by Fabrice
Hi Dick,
I think that "View Code" is not specific to the element you are on, it just open the file that contains the User-Code of the Form.
To jump to the code that replies to an event, either you doubleclick on the control, and it will open/create the method that replies to the default event, or you can go to the Properties panel, select the lightning icon (Event) then doubleclick on the corresponding event...it should jump to the code.

HTH,
Fab

Winforms ViewCode does not open code

Posted: Mon Aug 22, 2022 7:57 pm
by ic2
Hello Fabrice,

Unfortunately neither of these methods work. For some reason 1 of the (currently 4) toolbar button click methods resides in MyWindow.prg. The doubleclick (button or event) always opens that specific event while 3 of the events, residing in the separate MyWindowCode.prg never open (even though the name shows correctly in Click.)

It looks to me that if the code isn't in the windows with the same name as the Designer, X# is unable to find the code.

Dick

Winforms ViewCode does not open code

Posted: Mon Aug 22, 2022 9:32 pm
by robert
Dick,

The normal behavior (also for C#) is that the contents of the Form.prg and Form.designer.prg are merged into one logical codemodel and fed to the Window Editor. Each "CodeObject" in this CodeModel is marked with a property that indicates where it came from, so when saving the fields and methods are written back to the same file.

If you have code in another file then this is not included in this Codemodel and therefore the double click does not select it.
AFAIK this is also true for C#.

Robert

Winforms ViewCode does not open code

Posted: Tue Aug 23, 2022 10:10 am
by ic2
Hello Robert,
robert post=23447 userid=253 wrote: If you have code in another file then this is not included in this Codemodel and therefore the double click does not select it.
AFAIK this is also true for C#.
You are right; I tried it in C# and I see it doesn't work there either.

I'll add it to my growing list of things-that-get-worse-in-VS-compared-to-VO.

Dick

Winforms ViewCode does not open code

Posted: Tue Aug 23, 2022 10:32 am
by robert
Dick,
I can probably make it work. Can you create a GitHub ticket for this so I will not forget to look at this.

Robert

Winforms ViewCode does not open code

Posted: Tue Aug 23, 2022 10:03 pm
by ic2
Hello Robert,
robert post=23452 userid=253 wrote: I can probably make it work. Can you create a GitHub ticket for this so I will not forget to look at this.
It would be quite something that you would (again) fix something which Microsoft is unable to, or just don't care.

Kees informed me that he moved the code to a different program because of an earlier X# bug where he lost code in the code behind. This bug was fixed so personally I think I keep the program, but move the click event to the code behind program, calling the actual code in the separate program. So it would certainly be good if you can indeed fix it but I would give it low priority.

I have created a throw away Github account szh48002 to post a a GitHub ticket, #1103.

Dick

Winforms ViewCode does not open code

Posted: Wed Aug 24, 2022 7:08 am
by robert
Dick,
ic2 post=23462 userid=455 wrote:Hello Robert,
I have created a throw away Github account szh48002 to post a a GitHub ticket, #1103.
There is no ticket 1103 (anymore). If you have deleted your account then it has been deleted with it.

Robert

Winforms ViewCode does not open code

Posted: Wed Aug 24, 2022 9:01 am
by ic2
Hello Robert,

I didn't delete it. But it's Microsoft, so it is to be expected that it doesn't work.

Dick

Winforms ViewCode does not open code

Posted: Wed Aug 24, 2022 9:17 am
by robert
Dick,

I would not define that as "it does not work". Maybe it does not work as you would expect it.
If you delete an account, what should happen with the issues reported by that account?
Apparently, someone decided that since nobody else interacted with the issue, this issue was yours and yours only, so it should be deleted.
I think that makes perfect sense: "the right to be forgotten".

Robert