Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Initialize control dropped on form?

Initialize control dropped on form?

Scheduled Pinned Locked Moved C#
csharpdelphidesignquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MilesAhead
    wrote on last edited by
    #1

    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

    A M 2 Replies Last reply
    0
    • M MilesAhead

      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

      A Offline
      A Offline
      Aryadip
      wrote on last edited by
      #2

      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 !!

      M 1 Reply Last reply
      0
      • A Aryadip

        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 !!

        M Offline
        M Offline
        MilesAhead
        wrote on last edited by
        #3

        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! :)

        1 Reply Last reply
        0
        • M MilesAhead

          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

          M Offline
          M Offline
          MilesAhead
          wrote on last edited by
          #4

          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. :)

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups