On https://learn.microsoft.com/ro-ro/dotne ... esktop-4.8 there are instructions on how to add a Windows forms custom control. In short, you have to choose "Add New Item" and then you can select "Custom Control". My goal is to subclass the TextBox control and add a few methods. But the option to add a Custom Control appears to be missing. I can add a "User Control" but that is not what I want. What should I do to be able to create a new Custom Control?
Sorry, but I think that you are mixing words :
A WinForm UserControl is the same (by functionnality) as VO CustomControl. This is what the UserControl template is offering.
You can imagine the UserControl as a panel, where you can drop severals Controls to create a more complex control. Fo eg, a IPAddressText that is composed by 4 TextBox.
If I read you correctly, you want to inherit from the TextBox control, so simply create a .prg file with the needed code for inheritance.
CLASS MyControl INHERIT System.Windows.TextBox
// Make your changes here
END CLASS
Build your app; go to the designer : MyControl should appear in the ToolBox.
Thank you for your reply. From what I find on the internet, a "User Control" is very different from a "Custom Control". A user control is a combination of existing controls on a window that you can then attach to a placeholder object. A custom control is a control derived from an existing control or derived from the generic Control class which makes it possible to create a new type of control. It seems that in C# both user and custom controls can be added as new items and I wonder why in X# you can only add a user control.
Sorry, but I think that you are mixing words :
A WinForm UserControl is the same (by functionnality) as VO CustomControl. This is what the UserControl template is offering.
You can image the UserControl as a panel, where you can drop severals Controls to create a more complex control. Fo eg, a IPAddressText that is composed by 4 TextBox.
If I read you correctly, you want to inherit from the TextBox control, so simply create a .prg file with the needed code for inheritance.
CLASS MyControl INHERIT System.Windows.TextBox
// Make you changes here
END CLASS
Build your app; go to the designer : MyControl should appear in the ToolBox.
Thank you for your reply. It seems that the solution you provided is missing something which makes it impossible to see how it is done. I downloaded the zip, unpacked it and double clicked on the solution. Not sure what I could have done wrong.
Strange things have been happening with my custom controls. I have created a class that inherits from (Winforms) TextBox that adds two access/assigns. I have put this control on a Windows Forms User Control window. Then when I edit this window later on and save it, I can't open it again because of an error "Invalid cast from 'System.Boolean' to 'XSharp._Usual'. Then what I find is that two resources have been created in the .resx file of the form, one for each access/assign. See the pictures below. I have tried to reproduce the problem in a new Winforms application, but was unsuccessful. Apparently there is something in my code that causes this behaviour but I have no idea what it is. I think the TextBox subclass code is correct, it is also below. What I would like to know is: under what circumstances are resources created from access/assigns? I know this is not supposed to happen in this case because they are not created in my test application. And when the resources are there, I can't open the form and vice versa. So I am very curious to know what triggers the creation of resources from access/assigns.
Just a (quick) guess : Have you typed your ACCESS/ASSIGN return values ?
The Designer is living in his own world, so he might know nothing about USUALs.
At first the return values were not typed. Then I typed them as can be seen in the code I included, but it makes no difference, I still have the same problems.
Just a (quick) guess : Have you typed your ACCESS/ASSIGN return values ?
The Designer is living in his own world, so he might know nothing about USUALs.