Question Access Settings and Resources from a linked module

Makandriaco

New member
Joined
Sep 17, 2019
Messages
3
Programming Experience
10+
In VB.Net, I have a module that I use for all my projects. I just add it as a link to the project and any changes are then compiled in any project that uses it.
In that module there is a sub that assigns the icon to the form, which is passed as parameter.

VB.NET:
Public Sub CommonProcedures(ByRef frmSender As Form)
    frmSender.Icon = My.Resources.FormIcon
End Sub
It will use My.Resources depending on which project we are using.

How can I do this same thing in C#?

When I use

C#:
public static void CommonProcedures(Form frmSender)
{
    frmSender.Icon = Properties.Resources.FormIcon;
}
It is asking for specifically include the namespace for the Resources.
 
You'll have to get the assembly that contains the form, then search its resources for "FormIcon".
 
Thank you but I think you are not getting the point. The class where that code is, is being used at many different projects, each of them with a different assembly. And I want to figure out a way of doing it in C#, because the VB one works perfectly. Of course, this is just a very simple one liner, but there are many functions in that module that I would like to reuse in different projects or solutions. So that when project A calls this function, it assigns its own FormIcon to the passed form. And when project B calls the same function is assigns a different FormIcon to the passed form.
 
I did get the point. That's why I said you have to get the assembly that contains the form or that of the calling code. Use something like Assembly.GetExecutingAssembly() or form.GetType().Assembly.
 
Another alternative is to look at your existing VB.NET code in a disassembler and try to see how VB implements the My feature.
 
Back
Top Bottom