Results 1 to 7 of 7

Thread: HomeMade Title Bar [Resolved]

  1. #1

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    HomeMade Title Bar [Resolved]

    I'd like to implement a title bar using only a picturebox, how can I go about doing this? I've tried moving the form invoking the picturebox_mousemove event, but it gives a weird lag and kind of smears the form across the screen. The mousemove event also doesn't appear to be totally consistent either. I'm sure this has been done before, any pointers?
    Last edited by Nove; Mar 25th, 2005 at 10:12 PM.

  2. #2
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: HomeMade Title Bar

    I would use the MID() statement, like this.

    VB Code:
    1. Option Explicit
    2.   Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
    3.   Dim titlebar%
    4.   Dim title$
    5.   Dim z As Long
    6.   Dim ichange
    7.   Dim stitle$
    8.   Dim istart%, iend%
    9.   Dim endflag As Boolean
    10.  
    11. Private Sub Command1_Click()
    12.   If endflag = True Then
    13.     endflag = False
    14.   Else
    15.     endflag = True
    16.   End If
    17.   If endflag = False Then
    18.     istart = 1
    19.     Do While endflag = False
    20.       If istart + titlebar < Len(title) + 1 Then
    21.         stitle = Mid(title, istart, titlebar)
    22.       Else
    23.         ichange = Len(title) - istart
    24.         stitle = Mid(title, istart, ichange) & Mid(title, 1, titlebar - ichange)
    25.       End If
    26.       Label1.Caption = stitle
    27.       DoEvents
    28.       If istart < Len(title) Then istart = istart + 1 Else istart = 1
    29.       Sleep 200
    30.      Loop
    31.   End If
    32.    
    33.  
    34. End Sub
    35.  
    36. Private Sub Form_Load()
    37.  endflag = True
    38.  title = "This is a test.  This is only a test..." ' Bar is 10 characters
    39.  titlebar = 10
    40. End Sub

    It can be improved slightly, I just whipped it up.

  3. #3
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: HomeMade Title Bar

    Quote Originally Posted by Nove
    I'd like to implement a title bar using only a picturebox, how can I go about doing this? I've tried moving the form invoking the picturebox_mousemove event, but it gives a weird lag and kind of smears the form across the screen. The mousemove event also doesn't appear to be totally consistent either. I'm sure this has been done before, any pointers?
    If you're talking about moving borderless form then here is a sample:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Const WM_NCLBUTTONDOWN = &HA1
    4. Private Const HTCAPTION = 2
    5.  
    6. Private Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    7. Private Declare Function ReleaseCapture Lib "user32" () As Long
    8.  
    9. Private Sub pctTitlebar_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    10.     If Button = vbLeftButton Then
    11.         ReleaseCapture
    12.         SendMessageLong Me.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    13.     End If
    14. End Sub

  4. #4

    Thread Starter
    Fanatic Member Nove's Avatar
    Join Date
    Jul 2004
    Posts
    736

    Re: HomeMade Title Bar

    Thanks RhinoBull, works perfectly, and alot easier than I would've thought.

    Dglienna, I'm not quite sure what you were trying to do...

  5. #5
    Fanatic Member ZeBula8's Avatar
    Join Date
    Oct 2002
    Posts
    548

    Re: HomeMade Title Bar [Resolved]

    Code:
    Private Sub Form_Load()
    Picture1.BackColor = vbBlue
    Picture1.Move Me.ScaleLeft, Me.ScaleTop, Me.Width, 320
    End Sub

    and then use RhinoBulls's code to move it around

  6. #6

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: HomeMade Title Bar [Resolved]

    Somehow I got a scrolling marquee type thing out of that. It must be Friday, or something!

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