{"id":4259,"date":"2014-03-30T09:33:19","date_gmt":"2014-03-30T09:33:19","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/interfacing-common-functionality-between-controls-collection-of-common-programming-errors\/"},"modified":"2014-03-30T09:33:19","modified_gmt":"2014-03-30T09:33:19","slug":"interfacing-common-functionality-between-controls-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/interfacing-common-functionality-between-controls-collection-of-common-programming-errors\/","title":{"rendered":"Interfacing common functionality between controls-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m not really sure how to ask this question. Suppose I have a class that needs to access certain properties of a Control (for example, Visible and Location). Perhaps I want to use the same class to access properties of another item that have the same name, but the class might not derive from Control. So I tried making an interface:<\/p>\n<pre><code>public interface IThumbnail {\n\n    bool    Visible     { get; set; }\n    int     Height      { get; set; }\n    int     Width       { get; set; }\n    Image   Image       { get; set; }\n    Point   Location    { get; set; }\n\n    event EventHandler Click;\n}\n<\/code><\/pre>\n<p>Note that, for example, PictureBox happens to implement this interface. However, because the class definition does not <em>say<\/em> that it implements IThumbnail, I can&#8217;t cast PictureBoxes to IThumbnails&#8211;I get an InvalidCastException at runtime. But why can&#8217;t the CLR &#8216;figure out&#8217; that PictureBox really does implement IThumbnail (it just doesn&#8217;t explicitly say it does).<\/p>\n<p>Also, what should I do to handle this situation? I want a way to access <em>some<\/em> of the PictureBox&#8217;s properties without having my class know it&#8217;s modifying a PictureBox.<\/p>\n<p>Thx, Sam<\/p>\n<p>PS- I&#8217;m a newbie to interface programming, so I apologize if this is a stupid q.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m not really sure how to ask this question. Suppose I have a class that needs to access certain properties of a Control (for example, Visible and Location). Perhaps I want to use the same class to access properties of another item that have the same name, but the class might not derive from Control. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4259","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4259","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4259"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4259\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4259"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4259"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4259"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}