Click here to Skip to main content
15,887,596 members
Home / Discussions / C#
   

C#

 
GeneralRe: Changing textBox from Method Pin
ormonds21-Feb-19 16:48
ormonds21-Feb-19 16:48 
QuestionWHENTO Expect C# 8 to be released with Visual Studio and Default Interface Mathods (aka Multiple Inheritance). Pin
Member 1047477121-Feb-19 4:06
professionalMember 1047477121-Feb-19 4:06 
AnswerRe: WHENTO Expect C# 8 to be released with Visual Studio and Default Interface Mathods (aka Multiple Inheritance). Pin
Eddy Vluggen21-Feb-19 4:16
professionalEddy Vluggen21-Feb-19 4:16 
AnswerRe: WHENTO Expect C# 8 to be released with Visual Studio and Default Interface Mathods (aka Multiple Inheritance). Pin
Dave Kreskowiak21-Feb-19 5:03
mveDave Kreskowiak21-Feb-19 5:03 
AnswerRe: WHENTO Expect C# 8 to be released with Visual Studio and Default Interface Mathods (aka Multiple Inheritance). Pin
OriginalGriff21-Feb-19 5:14
mveOriginalGriff21-Feb-19 5:14 
QuestionEnabling Control from Method Pin
ormonds20-Feb-19 12:22
ormonds20-Feb-19 12:22 
AnswerRe: Enabling Control from Method Pin
Dave Kreskowiak20-Feb-19 14:04
mveDave Kreskowiak20-Feb-19 14:04 
AnswerRe: Enabling Control from Method Pin
OriginalGriff20-Feb-19 20:18
mveOriginalGriff20-Feb-19 20:18 
There are two types of "elements" that a class can have: static elements, and instance elements (where an element is a field, property, method, event, or delegate)

A static element is shared by all instances, and is accessed via the class name.
An instance element is unique to each different instance of the class and is accessed via the variable holding the instance reference.

Think about cars for a moment: all cars have a colour - but which colour it is depends on which specific car you are talking about. My car is black; your car is red; this car is green; that car is blue. Colour is an instance property of the Car class because you need to have a specific instance of a Car in order to ask the question "what colour is it?" - you can't say "what colour is a car?" because it's meaningless without saying which car you mean.
But cars have static properties as well: you can ask "how many wheels has a car?" because all cars have four wheels. (If it had two, it would be a motorbike, not a car)

And that's important, because if you want to affect a Car (start the engine for example) you have to be referring to a specific vehicle - and inside a static method you are not talking about any particular Car, you are talking about all cars, and it's just not going to work to sat "start the engine" and expect all cars engines to run.

So when you declare a static method, it can't access anything in your class that isn't also static.
You want to access a instance button, so you need to use a instance method by removing the keyword static from it;'s declaration, as Dave has said.

Does that make sense?
Sent from my Amstrad PC 1640
Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!

PraiseRe: Enabling Control from Method Pin
ormonds20-Feb-19 21:14
ormonds20-Feb-19 21:14 
GeneralRe: Enabling Control from Method Pin
OriginalGriff20-Feb-19 21:27
mveOriginalGriff20-Feb-19 21:27 
GeneralRe: Enabling Control from Method Pin
Richard MacCutchan21-Feb-19 1:05
mveRichard MacCutchan21-Feb-19 1:05 
QuestionRetrieve all comments in a worksheet using OpenXML Pin
Gli Invicibili18-Feb-19 18:29
Gli Invicibili18-Feb-19 18:29 
AnswerRe: Retrieve all comments in a worksheet using OpenXML Pin
Richard MacCutchan18-Feb-19 21:32
mveRichard MacCutchan18-Feb-19 21:32 
Question(Kinda SOLVED) Active Directory update (do I really need "Run As Administrator"?!) Pin
Super Lloyd18-Feb-19 13:11
Super Lloyd18-Feb-19 13:11 
QuestionOverridden OnPaint method not called on form Pin
pr1mem0ver17-Feb-19 22:37
pr1mem0ver17-Feb-19 22:37 
AnswerRe: Overridden OnPaint method not called on form Pin
OriginalGriff17-Feb-19 23:02
mveOriginalGriff17-Feb-19 23:02 
GeneralRe: Overridden OnPaint method not called on form Pin
pr1mem0ver17-Feb-19 23:47
pr1mem0ver17-Feb-19 23:47 
GeneralRe: Overridden OnPaint method not called on form Pin
OriginalGriff18-Feb-19 0:04
mveOriginalGriff18-Feb-19 0:04 
SuggestionRe: Overridden OnPaint method not called on form Pin
Ralf Meier18-Feb-19 0:08
mveRalf Meier18-Feb-19 0:08 
QuestionRe: Overridden OnPaint method not called on form Pin
Richard MacCutchan18-Feb-19 0:45
mveRichard MacCutchan18-Feb-19 0:45 
GeneralRe: Overridden OnPaint method not called on form Pin
pr1mem0ver18-Feb-19 3:11
pr1mem0ver18-Feb-19 3:11 
GeneralRe: Overridden OnPaint method not called on form Pin
Richard MacCutchan18-Feb-19 3:51
mveRichard MacCutchan18-Feb-19 3:51 
GeneralRe: Overridden OnPaint method not called on form Pin
pr1mem0ver18-Feb-19 10:31
pr1mem0ver18-Feb-19 10:31 
GeneralRe: Overridden OnPaint method not called on form Pin
Richard MacCutchan18-Feb-19 10:33
mveRichard MacCutchan18-Feb-19 10:33 
GeneralRe: Overridden OnPaint method not called on form Pin
Luc Pattyn18-Feb-19 12:13
sitebuilderLuc Pattyn18-Feb-19 12:13 

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.