CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2003
    Location
    Azerbaijan
    Posts
    74

    Custom code generation

    I am creating my own component, which is like TabControl.
    I created my own collecation class (PageCollection) and added the property of this type to component class.
    I also added additional properties, ActivePage and ActivePageIndex.
    Everything goes OK, but the order of statements of code inserted by designer is not what I really need.
    Code is generated in the following order:
    ActivePage, ActivePageIndex, ..., Pages

    But actually it must be as follows:
    Pages, ActivePage, ActivePageIndex

    The properties in InitializeComponent function appears in alphabetical order, how to override that order???

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    Re: Custom code generation

    Edit the InitializeComponent method and set the priorities you want.

    Simple eh ?

    If you open the form in the designer then it may re-arrange the order again, but most of the time it leaves the code alone so don't worry.

    Darwen.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: Custom code generation

    Reptile,

    if you're creating a component for other people to use the following should be of use. Code Generation

    By the sound of it the section Making Components Aware of Initialization is what you are after.

  4. #4
    Join Date
    Jun 2003
    Location
    Azerbaijan
    Posts
    74

    Re: Custom code generation

    I don't want to rearrange the order of elements each time I change the design of my form. Because if the order that code designer places the elements is not suitable, and I place them in the order I need, the next time form's design changes, the order changes too.

    Also I don't want to do this via code generation itself. Because the component I designed for C# and VB.NET will not be suitable for use in other .NET languages, if I don't implement them too.
    The code designer places properties' initialization in alphabetical order. So one of the simplest way is to name them in order they must be placed in code.
    But that's not the correctest way of that.
    So what is the simpler way of doing what I need to?
    Or do I really need to go through code generation?

  5. #5
    Join Date
    Dec 2003
    Location
    http://map.search.ch/zuerich.en.html
    Posts
    1,074

    Re: Custom code generation

    Why is the order important? To quote the article,
    the rule of thumb is to keep them modeless with respect to property sets. What that means is that users should be able to set properties in any order on an object and get the same results.
    .

    With respect to code generation, if it comes down to it, the article addresses this with CodeDom which is a) language independent and b) is used by the designers to generate the statements you're actually asking about!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured