usercontrol

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Maarten

    #1

    usercontrol

    hi all

    why should I use a usercontrol for ?
    does it have some advantages?

    thanks Maarten


  • J French

    #2
    Re: usercontrol

    On Sat, 6 Nov 2004 16:05:50 +0100, "Maarten" <gurkjaan@hotma il.com>
    wrote:
    [color=blue]
    >hi all
    >
    >why should I use a usercontrol for ?[/color]

    Most things graphical, and some things non graphical
    [color=blue]
    >does it have some advantages?[/color]

    Yes
    [color=blue]
    >thanks Maarten[/color]

    Best try writing one, they are very easy.

    Comment

    • Steve Gerrard

      #3
      Re: usercontrol


      "Maarten" <gurkjaan@hotma il.com> wrote in message
      news:418ce84f$0 $4340$ba620e4c@ news.skynet.be. ..
      | hi all
      |
      | why should I use a usercontrol for ?
      | does it have some advantages?
      |
      | thanks Maarten
      |

      A good way to start is to make a user control that contains one regular
      control, so you can define some special behavior for it. Try this in a
      new project:

      1. Click on Project menu, Add User Control
      2. On the user control, place one text box.
      3. Add the code below. Close the user control window.
      4. On Form1, place 2 or 3 of your new controls. Your control will appear
      last on the toolbox, and you can place them just like other controls.
      5. Run the program, and type stuff in the text boxes.
      6. Note that you can now use this control as many times as you like on
      different forms, without having to duplicate the color change code.

      ' User control code

      Private Sub Text1_Change()
      If InStr(1, Text1.Text, "red", vbTextCompare) Then
      Text1.ForeColor = vbRed
      Else
      Text1.ForeColor = vbBlack
      End If
      End Sub

      Private Sub UserControl_Res ize()
      With UserControl
      Text1.Move .ScaleLeft, .ScaleTop, .ScaleWidth, .ScaleHeight
      End With
      End Sub


      Comment

      • mayayana

        #4
        Re: usercontrol

        I think of a UC as a class with window properties.
        It's a great way to encapsulate API functions for
        another control or to use owner-drawn windows.
        Owner drawn windows are a pain in VB because
        they don't show up in the IDE. But if you associate an
        owner-drawn window with a UC you can tie things
        like Top, Left, Width, Height to the UC for easy
        GUI management of the window and you can also
        place the window on a form at "design time".
        So you might say it's a blank slate with all the
        conveniences of a VB component (visibility in
        the IDE, hWnd, dimensions, etc.).
        _______________ ______________

        mayayXXana1a@mi ndYYspring.com
        For return email remove XX and YY.
        _______________ ______________
        Maarten <gurkjaan@hotma il.com> wrote in message
        news:418ce84f$0 $4340$ba620e4c@ news.skynet.be. ..[color=blue]
        > hi all
        >
        > why should I use a usercontrol for ?
        > does it have some advantages?
        >
        > thanks Maarten
        >
        >[/color]


        Comment

        Working...