Initialize control dropped on form?
-
Hi. I'm new to C# and I'm trying to create C# implementations of Controls I did in Delphi in the past. In Delphi there is a flag 'csDesigning' that will be set in 'ComponentState' if you're in design mode. Using that I can do stuff like create a Guid String to get a unique program ID and the control can do stuff like File Mapping or whatever to share data between instances of the same app etc.. In C# I see something called 'DesignMode' but it seems like it's always false! Is there an easy way to set properties when a UserControl is dropped on a form that will be the same for all instances of the application? IOW, if I create a Guid String just using a constructor I'll get a different string for each app instance when I want the property values to be the same for all app instances, but be unique in each app where the control is used. This one has me baffled! TIA
-
Hi. I'm new to C# and I'm trying to create C# implementations of Controls I did in Delphi in the past. In Delphi there is a flag 'csDesigning' that will be set in 'ComponentState' if you're in design mode. Using that I can do stuff like create a Guid String to get a unique program ID and the control can do stuff like File Mapping or whatever to share data between instances of the same app etc.. In C# I see something called 'DesignMode' but it seems like it's always false! Is there an easy way to set properties when a UserControl is dropped on a form that will be the same for all instances of the application? IOW, if I create a Guid String just using a constructor I'll get a different string for each app instance when I want the property values to be the same for all app instances, but be unique in each app where the control is used. This one has me baffled! TIA
hi, Well at design time youi can set a default value to whatever property you are defining in your custom control. Here is the way to do that // Attribute applied to a property. [DefaultValue(false)] public new bool TabStop {... } and also you can use System.Windows.Forms.Design.ControlDesigner class to give the design time support to your control. Here you need to override the Initialize method to do all your custom setting of properties. Hope this helps you... regards, Aryadip. Cheers !! and have a Funky day !!
-
hi, Well at design time youi can set a default value to whatever property you are defining in your custom control. Here is the way to do that // Attribute applied to a property. [DefaultValue(false)] public new bool TabStop {... } and also you can use System.Windows.Forms.Design.ControlDesigner class to give the design time support to your control. Here you need to override the Initialize method to do all your custom setting of properties. Hope this helps you... regards, Aryadip. Cheers !! and have a Funky day !!
Wow! That's like, way too much work. All I'm trying to do is create a convenience where a component is dropped on a form and a unique string is generated to ID the app as a property of the component. I'm coding a simple instance component where the programmer can set the number of concurrent instances allowed to run on the same machine. In the Delphi version (s)he just has to drop it on the form and call one method on app startup. Looks like in C# I'll have to settle for a string property with a suggestive name( "GuidString" ) to hint that the programmer should use a Guid Generator utility to paste a unique string in this property. It works just as well but it's just cooler if it would fill in without the programmer's intervention. Unfortunately with C# if you use any contructor you get a different Guid every time the form is created, which is no good for my purpose. Oh well.. can't have everything I guess! :) Thanks for the info. I would have looked around for days only to find there ain't no easy way to do it! :)
-
Hi. I'm new to C# and I'm trying to create C# implementations of Controls I did in Delphi in the past. In Delphi there is a flag 'csDesigning' that will be set in 'ComponentState' if you're in design mode. Using that I can do stuff like create a Guid String to get a unique program ID and the control can do stuff like File Mapping or whatever to share data between instances of the same app etc.. In C# I see something called 'DesignMode' but it seems like it's always false! Is there an easy way to set properties when a UserControl is dropped on a form that will be the same for all instances of the application? IOW, if I create a Guid String just using a constructor I'll get a different string for each app instance when I want the property values to be the same for all app instances, but be unique in each app where the control is used. This one has me baffled! TIA
Just FYI after playing around for about 6 hours I hacked my way into a component that will initialize the way I want when dropped on a form. Maybe I'll work up a short article showing how 'cause it's definitely a feature that's very convenient. When my C# programming book arrives in the mail I'll consult that first of course. :)