Member Avatar

So I been stuck with this problem for quite a few days. Since I used as my first language C# is quite difficult for me.

In when you needed to refer to a different control on a different forum you would write something like Form1.Mainmenu etc

In C# you write, I don't know!:'(

So here is the problem. I have made a text-editor with one form (called Editor). Now I want to make the second form which will be the options form. (called Options)

From the Options form I want to be able to access the controls on Editor and change their backcolor text, and other things etc. I also want to be able use code from Editor.

Now here is the code I want. I made a method called Void InstalledFonts()

void InstalledFonts()

            InstalledFontCollection fonts = new InstalledFontCollection();

            for (int i = 0; i < fonts.Families.Length; i++)


(OK so for those who don't know what this code is doing it basically get a list of system fonts and putting them in to a comboBox when the program loads. )

I want to use this same code in the Options form as well. How can I refer to it? I don't want to retype it, I heard cut and paste is the sworn enemy of a programmer :icon_cheesygrin:

I hope someone understands and can help me out here.

Having one form directly change the appearance of another form is bad OO design. It couples the forms tightly. You should pass back information to the form so it can change itself.

That said, by default C# controls are private. If you click on the control and look in the Design section of the properties you'll see a 'Modifier' parameter set to 'private'. You can make this 'public' and it will act like the VB form. This, too, is bad design as you should make properties to access the controls :)

As for the repeated code, create a helper class to hold the methods. Call the methods to get the data you need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.