Click here to Skip to main content
15,896,606 members
Home / Discussions / C#
   

C#

 
AnswerRe: Can classes be nested Pin
BillWoodruff6-Mar-19 19:37
professionalBillWoodruff6-Mar-19 19:37 
GeneralRe: Can classes be nested Pin
Ralf Meier7-Mar-19 0:08
mveRalf Meier7-Mar-19 0:08 
GeneralRe: Can classes be nested Pin
Brian_TheLion7-Mar-19 10:53
Brian_TheLion7-Mar-19 10:53 
GeneralRe: Can classes be nested Pin
Dave Kreskowiak7-Mar-19 11:50
mveDave Kreskowiak7-Mar-19 11:50 
GeneralRe: Can classes be nested Pin
BillWoodruff8-Mar-19 17:03
professionalBillWoodruff8-Mar-19 17:03 
GeneralRe: Can classes be nested Pin
Brian_TheLion9-Mar-19 18:50
Brian_TheLion9-Mar-19 18:50 
AnswerRe: Can classes be nested Pin
Richard Deeming6-Mar-19 21:46
mveRichard Deeming6-Mar-19 21:46 
QuestionCRTP in c#/.NET? Pin
pr1mem0ver6-Mar-19 13:19
pr1mem0ver6-Mar-19 13:19 
I found different solutions to this sort of CRTP problem previously... but can't think of a way around it this time.

The main form used by my current project allows for moving and resizing even when it doesn't have a border. I have seen other people ask about this particular need before (it seems like a fairly common need for custom forms) and I have developed a better solution than what I have seen for answers online. I would like to provide a more generic solution than the one I am using currently for myself and others if possible so hence... my asking this prerequisite question beforehand.

I am needing to create several "controls" in my current project that have this same exact behavior so I want to write an inheritable class for all of them. Simple enough... just write a template that derives from Control. The problem is that none of the derived classes will look and perform like their actual base class in every other way without some way to use a CRTP. It would be nice not to have to write separate base classes for all the seperate possible control types, including forms. Is there a way to write a generic class to cover all controls that one would want to use? Something that effectively does what this would do if this were c++? (I realize that the where statement is c# but there are ways to accomplish the same basic idea in c++).
C#
public class MovableControl<InheritedControl> : InheritedControl where InheritedControl : Control
{
	//...
}

In c# the above class definition doesn't compile because in .NET inheriting from a template parameter is not allowed (which is why I need an alternative solution.). Of course I will continue hunting on my own, or worst case, brute force it (by creating the separate classes) but I thought I would ask here in case someone already had an idea.
AnswerRe: CRTP in c#/.NET? Pin
BillWoodruff6-Mar-19 21:15
professionalBillWoodruff6-Mar-19 21:15 
GeneralRe: CRTP in c#/.NET? Pin
pr1mem0ver7-Mar-19 5:09
pr1mem0ver7-Mar-19 5:09 
GeneralRe: CRTP in c#/.NET? Pin
BillWoodruff7-Mar-19 7:00
professionalBillWoodruff7-Mar-19 7:00 
AnswerRe: CRTP in c#/.NET? Pin
Gerry Schmitz7-Mar-19 7:26
mveGerry Schmitz7-Mar-19 7:26 
GeneralRe: CRTP in c#/.NET? Pin
BillWoodruff8-Mar-19 17:16
professionalBillWoodruff8-Mar-19 17:16 
GeneralRe: CRTP in c#/.NET? Pin
pr1mem0ver11-Mar-19 16:55
pr1mem0ver11-Mar-19 16:55 
QuestionOnly Numeric Textbox ( Back Space is working ) Pin
Bayram Demirci6-Mar-19 1:31
Bayram Demirci6-Mar-19 1:31 
AnswerRe: Only numeric ( Back Space is working also ) Pin
OriginalGriff6-Mar-19 1:58
mveOriginalGriff6-Mar-19 1:58 
GeneralRe: Only numeric ( Back Space is working also ) Pin
Bayram Demirci6-Mar-19 2:32
Bayram Demirci6-Mar-19 2:32 
GeneralRe: Only numeric ( Back Space is working also ) Pin
OriginalGriff6-Mar-19 2:47
mveOriginalGriff6-Mar-19 2:47 
GeneralRe: Only numeric ( Back Space is working also ) Pin
pr1mem0ver6-Mar-19 13:29
pr1mem0ver6-Mar-19 13:29 
GeneralRe: Only numeric ( Back Space is working also ) Pin
Eddy Vluggen7-Mar-19 1:03
professionalEddy Vluggen7-Mar-19 1:03 
GeneralRe: Only numeric ( Back Space is working also ) Pin
pr1mem0ver7-Mar-19 4:54
pr1mem0ver7-Mar-19 4:54 
GeneralRe: Only numeric ( Back Space is working also ) Pin
Eddy Vluggen7-Mar-19 9:51
professionalEddy Vluggen7-Mar-19 9:51 
GeneralRe: Only numeric ( Back Space is working also ) Pin
BillWoodruff8-Mar-19 23:20
professionalBillWoodruff8-Mar-19 23:20 
AnswerRe: Only numeric ( Back Space is working also ) Pin
Dave Kreskowiak6-Mar-19 2:23
mveDave Kreskowiak6-Mar-19 2:23 
GeneralRe: Only numeric ( Back Space is working also ) Pin
Bayram Demirci6-Mar-19 2:56
Bayram Demirci6-Mar-19 2:56 

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.