Creating a windows forms control with no (or minimal) GUI
-
I have created several ASP.NET server controls, but this is my first attempt at a control for Windows Forms. I need to build a control that has no visual component (for example, like an ImageList control). When I inherit from Control, it brings along a ton of properties and methods that I don't need or want (i.e. backcolor, font, anchor). What should I inherit from in order to create a control with no design time or visual properties? Just the properties and methods I dictate? -Todd Davis (toddhd@hotmail.com)
-
I have created several ASP.NET server controls, but this is my first attempt at a control for Windows Forms. I need to build a control that has no visual component (for example, like an ImageList control). When I inherit from Control, it brings along a ton of properties and methods that I don't need or want (i.e. backcolor, font, anchor). What should I inherit from in order to create a control with no design time or visual properties? Just the properties and methods I dictate? -Todd Davis (toddhd@hotmail.com)
Are you sure you want to create a control? Todd Davis wrote: no design time or visual properties? Just the properties and methods I dictate? Sounds like you just want to define your own class.
class ToddsClass{ public int ToddsInteger; public int ToddsMethod(int iFactor){ return(iFactor*this.ToddsInteger); } public ToddsClass(){ //a constructor this.ToddsInteger=1; } }
Or am I missing something? Bill -
Are you sure you want to create a control? Todd Davis wrote: no design time or visual properties? Just the properties and methods I dictate? Sounds like you just want to define your own class.
class ToddsClass{ public int ToddsInteger; public int ToddsMethod(int iFactor){ return(iFactor*this.ToddsInteger); } public ToddsClass(){ //a constructor this.ToddsInteger=1; } }
Or am I missing something? BillYup, you are right. I figured that out shortly after posting this. I had defined the class as a source code file, but we needed it to be a *.dll, and I got hung up on choosing Windows Forms Library from the new project wizard. I instead chose Class library, and now life is good... thanks! Never code when it is past your bedtime... :) -Todd Davis (toddhd@hotmail.com)
-
Yup, you are right. I figured that out shortly after posting this. I had defined the class as a source code file, but we needed it to be a *.dll, and I got hung up on choosing Windows Forms Library from the new project wizard. I instead chose Class library, and now life is good... thanks! Never code when it is past your bedtime... :) -Todd Davis (toddhd@hotmail.com)
If you want a component like the
ImageList
, however, that can interact with the designer, extend theComponent
class. Also, this has absolutely nothing to do with what kind of project you create. You are supposed to add classes to that and understand what's in the source file. A Windows Forms Application can contain all the same things a Windows Control Library can, and even an ASP.NET Web Application can, too, though a Windows Forms class won't do much good there. The difference is how the assemblies are built, whether they are self executing or loadable (among a few other differences in the PE/COFF header and where everything is located, etc.). Todd Davis wrote: Never code when it is past your bedtime... ...or before reading the documentation.Microsoft MVP, Visual C# My Articles