In my solution, I have multiple Forms/Views and wanted to use global properties to set the basic form control properties (font name, size, color, etc).
The Designer.cs file is a partial class, which is obviously apart of the main partial class when you do "View Code." This is the class which inherits from "Form." So what I've done was created another class file which I call ViewMaster.cs, and inherit "Form" from that and set my ViewMaster class as the inherited class for my form.
MembershipView.cs
public partial class MembershipView : ViewMaster {
...
}
ViewMaster.cs
public class ViewMaster : Form {
public Font fontButton = new Font("Microsoft Sans Serif", 11F, FontStyle.Regular, GraphicsUnit.Point, 0);
public Font fontLabel = new Font("Microsoft Sans Serif", 11F, FontStyle.Regular, GraphicsUnit.Point, 0); // new Font("Arial", 18F, FontStyle.Regular, GraphicsUnit.Point, 0);
public Font fontGrid = new Font("Microsoft Sans Serif", 10F, FontStyle.Regular, GraphicsUnit.Point, 0);
public Size sizeButton = new Size(125, 28);
}
MembershipView.Designer.cs
partial class MembershipView {
...
this.label5.Font = fontLabel;
...
this.btnSearch.Font = fontButton;
...
}
Now this works when I click "Start" or "Start Debugging", although when I double click on the Form Viewer (MembershipView.cs in my case), I get errors like:
The variable 'fontLabel' is either undeclared or was never assigned.
The variable 'fontButton' is either undeclared or was never assigned.
The variable 'sizeButton' is either undeclared or was never assigned.
The variable 'fontGrid' is either undeclared or was never assigned.
I am able to hit "Ignore and Continue." at this point, although the size / font within the designer / form view 8.25, so it obviously doesn't read from my inherited properties. Again - it all works when I hit "Start."
Anyone have any suggestions to resolve this?
Thanks! Mike