Click here to Skip to main content
15,867,453 members
Home / Discussions / C#
   

C#

 
GeneralRe: Acquiring a property value Pin
Dave Kreskowiak20-Aug-13 13:49
mveDave Kreskowiak20-Aug-13 13:49 
GeneralRe: Acquiring a property value Pin
Blubbo26-Jul-13 1:49
Blubbo26-Jul-13 1:49 
GeneralRe: Acquiring a property value Pin
Dave Kreskowiak26-Jul-13 2:27
mveDave Kreskowiak26-Jul-13 2:27 
GeneralRe: Acquiring a property value Pin
Blubbo26-Jul-13 2:19
Blubbo26-Jul-13 2:19 
AnswerRe: Acquiring a property value Pin
PIEBALDconsult25-Jul-13 14:16
mvePIEBALDconsult25-Jul-13 14:16 
GeneralRe: Acquiring a property value Pin
Blubbo26-Jul-13 1:50
Blubbo26-Jul-13 1:50 
GeneralRe: Acquiring a property value Pin
Dave Kreskowiak26-Jul-13 2:35
mveDave Kreskowiak26-Jul-13 2:35 
AnswerRe: Acquiring a property value Pin
OriginalGriff25-Jul-13 21:39
mveOriginalGriff25-Jul-13 21:39 
Just to add to the other responses:

Your DeviceMonitor is a UserControl, which means that it is derived from Control (it has to be, otherwise it can't be displayed - even Form is derived from Control via a couple of other classes). That means it inherits (and you can access) all the properties of a Control in your class. But it doesn't work the other way...
C#
DeviceMonitor devMon = new DeviceMonitor();
Control deviceControl= devMon;
this.Controls.Add(deviceControl);
devMon contains a reference to your DeviceMonitor instance, so you can access all the properties and methods of the DeviceMonitor class via devMon:
C#
if (devMon.isConnected)
   {
   ...
   }
But deviceControl is a Control reference: it can contain a Control instance, or an instance of any class which is derived from Control, but it can only access the properties and methods of the Control class because that is the only class type it can guarantee that deviceControl contains. It is perfectly legal and correct to say:
C#
DeviceMonitor devMon = new DeviceMonitor();
Control deviceControl= devMon;
this.Controls.Add(deviceControl);
deviceControl = new TextBox();
So the compiler will not let you access a derived class property or method via the base class variable.

It's a bit like cars: a Car has four wheels and an engine, but a Ford Fiesta also has Cruise Control, which a Ford Model T doesn't. If you declare a variable as a Car, then you can't access myCar.CruiseControl because the Car may be a Model T.

BTW: You don't need to use the deviceControl in your code - you can use a derived class anywhere you can use the base class. So this will work as well:
C#
DeviceMonitor devMon = new DeviceMonitor();
this.Controls.Add(devMon);

The universe is composed of electrons, neutrons, protons and......morons. (ThePhantomUpvoter)

AnswerRe: Acquiring a property value Pin
Blubbo26-Jul-13 4:38
Blubbo26-Jul-13 4:38 
GeneralRe: Acquiring a property value Pin
PIEBALDconsult26-Jul-13 7:55
mvePIEBALDconsult26-Jul-13 7:55 
GeneralRe: Acquiring a property value Pin
Richard MacCutchan26-Jul-13 22:26
mveRichard MacCutchan26-Jul-13 22:26 
AnswerRe: Acquiring a property value Pin
coolcat22731-Jul-13 11:29
coolcat22731-Jul-13 11:29 
QuestionPower management hybernation is causing my application to hang ... Pin
turbosupramk325-Jul-13 2:50
turbosupramk325-Jul-13 2:50 
AnswerRe: Power management hybernation is causing my application to hang ... Pin
turbosupramk326-Jul-13 3:47
turbosupramk326-Jul-13 3:47 
Questionusing System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff25-Jul-13 0:55
professionalBillWoodruff25-Jul-13 0:55 
AnswerRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Dave Kreskowiak25-Jul-13 1:15
mveDave Kreskowiak25-Jul-13 1:15 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff25-Jul-13 21:48
professionalBillWoodruff25-Jul-13 21:48 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Dave Kreskowiak26-Jul-13 7:00
mveDave Kreskowiak26-Jul-13 7:00 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff30-Jul-13 4:57
professionalBillWoodruff30-Jul-13 4:57 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Dave Kreskowiak30-Jul-13 5:46
mveDave Kreskowiak30-Jul-13 5:46 
AnswerRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
Alan N25-Jul-13 4:27
Alan N25-Jul-13 4:27 
GeneralRe: using System.Diagnostics.Stopwatch in an Button_Click Event: unusual results in specific test case Pin
BillWoodruff25-Jul-13 21:13
professionalBillWoodruff25-Jul-13 21:13 
QuestionParamerterized OleDB Query Pin
gautamn199025-Jul-13 0:21
gautamn199025-Jul-13 0:21 
AnswerRe: Paramerterized OleDB Query Pin
Dave Kreskowiak25-Jul-13 1:17
mveDave Kreskowiak25-Jul-13 1:17 
GeneralRe: Paramerterized OleDB Query Pin
gautamn199025-Jul-13 19:28
gautamn199025-Jul-13 19:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.