c# - Modify Windows Forms Control from another Project -
i have control lbldate
in user control mainscreen
. modify in method in class date
, in project aowlibrary
. can't reference because aowlibrary dependent of first project.
i tried make lbldate static compiler kept throwing errors @ me, , have public property date can't seem access:
public label labeldate { { return lbldate; } set { lbldate = value; } }
in class date, need public method calculatedate modify text property of lbldate
public static void calculatedate() { gamedate = month.tostring() + "/" + displayday.tostring() + "/" + year.tostring(); // labeldate.text = gamedate; // need }
also, can't access lbldate in other controls in same project.
so, general idea need keep track of in scope. there lot of ways go doing want do, of them rely on objects referencing each other in ways may not quite understand yet. don't worry-- has work through @ point.
the reason compiler complained when tried make member static because label not static. being tied single instance of mainscreen, has no meaning in static context, definition scope without inherent reference particular mainform.
your date class is, of course, totally different context, too, non-static members have access instance of date. there isn't path between these 2 contexts until create it. static route have worked (look singleton pattern: idea being store first , instance of class statically , refer elsewhere) not design. other ways passing date instance of mainscreen (preferably through interface) or labeldate itself. of these 2 pieces need talk.
however, suggest think game state being stored. in library or consuming assembly? if former, might want think creating complete guiless model of data needs stored , manipulated in library class , consume ready-made data as-is in main application. other alternative model lives in main application, , calls library necessary. in case should stick asking library answers (or @ listening events in library) , not expecting reach application on own (whether or provide information).
in figuring out how find scope management issues easier handle. little bit of architecture can go long way.
but if little overwhelming, don't stress much. sounds doing fun, great way learn. you'll come against issues , either hit on design or not-so-good one, either way you're wrestling important concepts , come away better it.
Comments
Post a Comment