DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 15 of 15

Thread: forms are a nasty cludge

  1. #1
    will Guest

    forms are a nasty cludge



    >Nope I don't think so. Although I am not against the idea, I think it make
    >sense only in few occassions. Moreever, I think this behaviour (visual inheritance
    >as it is called) is accidental and not much thought is given to it.
    >Further, IMO inheritance of windows form will be most misused. When u create
    >form in vs.net, it goes something like class MyForm : inherits System.windows.Forms.form
    >.... Now, in most of applications, most of forms are going to be dialogs
    >and I simply don't know why they have to be kind of form. It will be most
    >appropriate for dialog classes to contain form rather than inherit from

    it.
    >
    >-Vinay
    >


    Your thinking in terms of forms and classes as distinct entities in a design
    is one of the things I always disliked about VB. In my opinion forms should
    always have been classes. In fact I would have been happy if Microsoft threw
    away the visual component of VB altogether. It just gets in the way of well
    structured, reusable code. What people tend to do is manually put buttons,labels
    and other controls onto the form at design time, when they should be writing
    code that does it programatically at runtime. For instance it is much cleaner
    to load label captions from a string resource file than have the captions
    'hardcoded' into the form. In fact all the visual designer was good for was
    dropping instances of the controls you wanted onto it (in any old place),
    because programatically creating controls was not always easy in past versions
    of VB. Everything else like sizing and positioning should be done programatically
    at runtime. In a class. Theres no need for forms at all. They are just an
    annoying little cludge! But wait I hear you scream, what about events. Again
    VB pretty much forced you to hardcode these into the form. But no more. In
    .NET you can create eventhandlers dynamically at runtime. Good!

    Try coding a VB.NET application entirely in a text editor like VIM (improved
    VI). You'll be surprised how quick and easy it is. Who needs a Visual IDE?








  2. #2
    Dave Guest

    Re: forms are a nasty cludge


    "will" <williamfleming@hotmail.com> wrote:
    In fact all the visual designer was good for was
    >dropping instances of the controls you wanted onto it (in any old place),
    >because programatically creating controls was not always easy in past versions
    >of VB. Everything else like sizing and positioning should be done programatically
    >at runtime. In a class. Theres no need for forms at all. They are just an
    >annoying little cludge! But wait I hear you scream, what about events. Again
    >VB pretty much forced you to hardcode these into the form. But no more.

    In
    >.NET you can create eventhandlers dynamically at runtime. Good!
    >

    Actually, just for the record, it's also pretty easy to add controls dynamically
    in VB5/6:
    Me.Controls.Add "VB.Label", "lblTemp"
    If you want to respond to events, you just need a class which subclasses
    the control in question and insert code in the class's event handlers. This
    is actually a cleaner alternative to control arrays in VB6 (and upgrades
    to .NET a lot better than control arrays).

    But we've all seen apps where controls seem to be placed very inappropriately
    (due to some slight bug in dynamic placement code) - actually seeing what
    you're designing isn't all that bad after all...


  3. #3
    Phil Weber Guest

    Re: forms are a nasty cludge

    > Actually, just for the record, it's also pretty easy to add
    > controls dynamically in VB5/6: Me.Controls.Add


    Dave: I think that's VB6 only. VB5 still required the use of control arrays.
    --
    Phil Weber



  4. #4
    Dave Guest

    Re: forms are a nasty cludge


    "Phil Weber" <pweber@nospam.fawcette.com> wrote:
    > > Actually, just for the record, it's also pretty easy to add
    > > controls dynamically in VB5/6: Me.Controls.Add

    >
    >Dave: I think that's VB6 only. VB5 still required the use of control arrays.
    >--
    >Phil Weber
    >
    >

    You're right - I guess since VB6 had such a long run that it just seemed
    like a couple of versions...


  5. #5
    will Guest

    Re: forms are a nasty cludge


    >
    >But we've all seen apps where controls seem to be placed very inappropriately
    >(due to some slight bug in dynamic placement code) - actually seeing what
    >you're designing isn't all that bad after all...
    >


    OK I was speaking slightly tongue in cheek I admit visual designers are
    not necesarily evil. Guess it comes down to individual preference, and how
    you use them. As for bugs in dynamic placement code, I could reply we've
    also all seen apps where you resize the explorer (treeview/listview) form
    and the listview stays the same size, creating an ugly empty gray area of
    form. Someone just dropped the listview onto the form and it never occurred
    to them they needed to write resize code. Yuck!





  6. #6
    Michael Culley Guest

    Re: forms are a nasty cludge

    Is it just me or is the built in Dock/Align method not up to scratch. I find
    I can't get them to do what I want, give up and write it code.

    --
    Michael Culley
    www.vbdotcom.com


    "will" <w@hotmail.com> wrote in message
    news:3daf8d15$1@tnews.web.devx.com...
    >
    > >
    > >But we've all seen apps where controls seem to be placed very

    inappropriately
    > >(due to some slight bug in dynamic placement code) - actually seeing what
    > >you're designing isn't all that bad after all...
    > >

    >
    > OK I was speaking slightly tongue in cheek I admit visual designers are
    > not necesarily evil. Guess it comes down to individual preference, and how
    > you use them. As for bugs in dynamic placement code, I could reply we've
    > also all seen apps where you resize the explorer (treeview/listview) form
    > and the listview stays the same size, creating an ugly empty gray area of
    > form. Someone just dropped the listview onto the form and it never

    occurred
    > to them they needed to write resize code. Yuck!
    >
    >
    >
    >




  7. #7
    Vinay Guest

    Re: forms are a nasty cludge


    "will" <williamfleming@hotmail.com> wrote:
    >
    >Your thinking in terms of forms and classes as distinct entities in a design
    >is one of the things I always disliked about VB.


    Perhaps we r talking different things.... I was/am not saying and thinking
    that forms should not be classes. Even in VB6, I did not treat form as different
    entity, rather I treat is as COM component that can be instantiated as many
    times and so on....
    The point I was making was I disagree with ur point in ur original post that
    sited forms inheritance to be good example of reusability. I was rather saying
    form inheritance is going to be a great example of misuse of inheritance
    and reason being VS.NET forms designer. I would have preffered a designer
    that would produce dialog box code similar to perhaps MFC in which dialog
    box is a class with necessary & limited interface, that uses form internally
    and not inherit from it.

    >What people tend to do is manually put buttons,labels
    >and other controls onto the form at design time, when they should be writing
    >code that does it programatically at runtime. For instance it is much cleaner

    ......
    >Try coding a VB.NET application entirely in a text editor like VIM (improved
    >VI). You'll be surprised how quick and easy it is. Who needs a Visual IDE?
    >
    >


    Hey, I did that.... I used framework SDK along with my favourite text editor
    (editplus) for about 4-5 months before switching to VS.NET.
    And I agree with u, I didn't like the code VS.NET Forms designer produces,
    its simply ugly. However, one thing where visual disigner is more productive
    is placement and sizing of controls and I talking lots of controls. I found
    its very difficult to judge placement and size of controls in fixed sized
    dialogs without visual aid. In case of resizable layouts, going by code is
    faster.

    -Vinay.



  8. #8
    Phil Weber Guest

    Re: forms are a nasty cludge

    > Is it just me or is the built in Dock/Align method not up
    > to scratch. I find I can't get them to do what I want, give
    > up and write it code.


    Michael: I haven't had any trouble with it. What are you having difficulty
    doing?
    --
    Phil Weber



  9. #9
    Mike Mitchell Guest

    Re: forms are a nasty cludge

    On 17 Oct 2002 18:04:09 -0700, "Dave" <dave_doknjas@yahoo.ca> wrote:

    >You're right - I guess since VB6 had such a long run that it just seemed
    >like a couple of versions...


    Hey, why the past tense? Oh, sorry, of course you mean its run came to
    an end when Microsoft discontinued it! <g>

    MM

  10. #10
    Dave Guest

    Re: forms are a nasty cludge


    Mike Mitchell <kylix_is@yahoo.co.uk> wrote:
    >On 17 Oct 2002 18:04:09 -0700, "Dave" <dave_doknjas@yahoo.ca> wrote:
    >
    >>You're right - I guess since VB6 had such a long run that it just seemed
    >>like a couple of versions...

    >
    >Hey, why the past tense? Oh, sorry, of course you mean its run came to
    >an end when Microsoft discontinued it! <g>
    >
    >MM


    Well, you're right - Microsoft has discontinued it. Not *officially* of course
    - but since there's no upgrade path for most real-world apps it's discontinued
    to me. I'll continue to use VB6 for my 50,000+ line apps where I don't have
    the luxury of finding & correcting the hundreds of screw-ups that the Upgrade
    Wizard generates (dropping lines of code, making a mess of control arrays,
    adding inappropriate object references, ...) & I also don't have the luxury
    of rewriting from scratch. I can do this for my puny apps (< 50,000 lines
    of codes).


  11. #11
    Michael Culley Guest

    Re: forms are a nasty cludge

    Hi Phil,

    Say I have a command button that I want to stick to the RHS of a form. As
    the form's width is reduced the command button moves to the left, but when
    it gets to a certain point, say 20 pixels from the left it should stop
    moving. Paste the code below into a blank VB6 form to see what I am after.

    --
    Michael Culley
    www.vbdotcom.com


    Private mCommand As CommandButton

    Private Sub Form_Load()
    Set mCommand = Me.Controls.Add("VB.CommandButton", "Command1")
    mCommand.Caption = "Command1"
    mCommand.Width = 3000
    mCommand.Visible = True
    End Sub

    Private Sub Form_Resize()
    mCommand.Move Cut(Me.ScaleWidth - 105 - mCommand.Width, 105),
    Cut(Me.ScaleHeight - 105 - mCommand.Height, 105)
    End Sub

    Private Function Cut(Value As Single, MinValue As Single) As Single
    Cut = IIf(Value < MinValue, MinValue, Value)
    End Function



  12. #12
    Phil Weber Guest

    Re: forms are a nasty cludge

    > Say I have a command button that I want to stick to the RHS
    > of a form. As the form's width is reduced the command button
    > moves to the left, but when it gets to a certain point, say 20
    > pixels from the left it should stop moving.


    Michael: Here's how I would handle that in VB.NET:

    ' In InitializeComponent...
    ' Anchor button to right-hand side of form
    Me.btnOK.Anchor = System.Windows.Forms.AnchorStyles.Right

    ' Prevent button from moving less than 20 pixels
    ' from left edge of client area
    Me.MinimumSize = New System.Drawing.Size_
    (Me.ClientSize.Width - btnOK.Left + 20, 0)

    --
    Phil Weber



  13. #13
    iGadget Guest

    Re: forms are a nasty cludge

    "Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in message
    news:3db3611c$1@tnews.web.devx.com...
    > Hi Phil,
    >
    > Say I have a command button that I want to stick to the RHS of a form. As
    > the form's width is reduced the command button moves to the left, but when
    > it gets to a certain point, say 20 pixels from the left it should stop
    > moving. Paste the code below into a blank VB6 form to see what I am after.


    I think the decision as to what happens when there is insufficient room to
    display a control is yours, and not .NETs.
    To display a form with a command button on the rightmost border, I would
    have thought it was wrong to allow the form to be shrunk smaller than the
    button, so I would restrict the minimum width of the form to be (for
    example) the button width+20 pixels.
    The .NET approach is to allow you to specify the Anchor point as being the
    right form edge, so the control will always go left as long as you drag
    left. To suggest that the system should monitor its contents, and change the
    anchor to the left edge when the form gets too small is assuming that
    everyone wants that feature. Why does your code not shrink the width of the
    button when the form is too narrow? It doesn't make sense to chop off the
    right hand side either.
    If you want to modify the Anchor functionality of the form, then you can
    probably create your own form class that does it the way you want it to, and
    even use all the existing properties (or add your own of 'AutoLeftLimit' or
    whatever).

    Cheers,
    iGadget

    > --
    > Michael Culley
    > www.vbdotcom.com
    >
    >
    > Private mCommand As CommandButton
    >
    > Private Sub Form_Load()
    > Set mCommand = Me.Controls.Add("VB.CommandButton", "Command1")
    > mCommand.Caption = "Command1"
    > mCommand.Width = 3000
    > mCommand.Visible = True
    > End Sub
    >
    > Private Sub Form_Resize()
    > mCommand.Move Cut(Me.ScaleWidth - 105 - mCommand.Width, 105),
    > Cut(Me.ScaleHeight - 105 - mCommand.Height, 105)
    > End Sub
    >
    > Private Function Cut(Value As Single, MinValue As Single) As Single
    > Cut = IIf(Value < MinValue, MinValue, Value)
    > End Function
    >
    >




  14. #14
    Michael Culley Guest

    Re: forms are a nasty cludge

    Phil, iGadget,

    What I want to do doesn't seem that unreasonable to me. I don't like
    restricting the size of the form because I think users should be able to
    make the form really small if they want to, its their computer. At least now
    I know it is not possible and I wasn't missing something.

    > To suggest that the system should monitor its contents, and change the
    > anchor to the left edge when the form gets too small is assuming that
    > everyone wants that feature.


    Not really, there could be some option like minimum pos or something. I'm
    not really suggesting they change it, I'm just saying I don't think it is up
    to the task in most situations.

    > If you want to modify the Anchor functionality of the form, then you can
    > probably create your own form class that does it the way you want it to,

    and
    > even use all the existing properties (or add your own of 'AutoLeftLimit'

    or
    > whatever).


    Nah, I just write code in the resize event like I always did :-) Easy and
    quick to do (if not tedious) and fully flexible.

    Outlook express is a fairly simple in the resizing department. Its just 4
    boxes in each corner of the window. I don't think this is possible with the
    ..net resizing.

    --
    Michael Culley
    www.vbdotcom.com



  15. #15
    iGadget Guest

    Re: forms are a nasty cludge

    "Michael Culley" <mculley@NOSPAMoptushome.com.au> wrote in message
    news:3db3abd4$1@tnews.web.devx.com...
    > Phil, iGadget,
    >
    > What I want to do doesn't seem that unreasonable to me. I don't like
    > restricting the size of the form because I think users should be able to
    > make the form really small if they want to, its their computer. At least

    now
    > I know it is not possible and I wasn't missing something.


    No, I'm not suggesting that your request is at all unreasonable, I'm just
    pointing out that there is no one set of attributes that meet all of the
    possible requirements of users, so it's less of it being 'not up to
    scratch', and more of it 'doing exactly what it says it will'

    > > To suggest that the system should monitor its contents, and change the
    > > anchor to the left edge when the form gets too small is assuming that
    > > everyone wants that feature.

    >
    > Not really, there could be some option like minimum pos or something. I'm
    > not really suggesting they change it, I'm just saying I don't think it is

    up
    > to the task in most situations.
    >
    > > If you want to modify the Anchor functionality of the form, then you can
    > > probably create your own form class that does it the way you want it to,

    > and
    > > even use all the existing properties (or add your own of 'AutoLeftLimit'

    > or
    > > whatever).

    >
    > Nah, I just write code in the resize event like I always did :-) Easy and
    > quick to do (if not tedious) and fully flexible.


    Yep, by far the easiest solution
    Mind you, it would be a fun exercise to write a form derivative that
    replaced the Align and Dock functionality

    > Outlook express is a fairly simple in the resizing department. Its just 4
    > boxes in each corner of the window. I don't think this is possible with

    the
    > .net resizing.


    It's quite achievable, but you have to add a few lines of code. I think the
    ..Dock and .Align properties avoid lots of coding in the majority of cases,
    but obviously not all

    Cheers,
    iGadget



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center