Results 1 to 7 of 7

Thread: gradient in textbox

  1. #1

    Thread Starter
    Addicted Member Flip's Avatar
    Join Date
    Jun 2002
    Location
    Burke, VA
    Posts
    247

    gradient in textbox

    How can I draw a gradient in a textbox
    For example, horizontal fade from black to blue.
    Thanks.
    The "company" website My homepage: nerisoft.com
    scars heal but glory is forever

  2. #2
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    I just read your post, and I have a little idea that poped into my head right now.
    You can make a virtual text box. I'll explain:

    You take a PictureBox which in it you can draw anything you want.
    You put a label in the PictureBox. You use the Form_KeyDown to write into the virtual text box, I mean, adding text to the label.

    I Didn't tried it yet, because it just came up to me..
    I'll try it, and later I'll post the project.

    I hope I helped,
    Arie.
    Tip Of The Day: Fake it 'till you make it !

  3. #3
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Israel
    Posts
    636
    That's a sample of what I meant.
    I hope that's what you wanted.

    Arie.
    Attached Files Attached Files
    Tip Of The Day: Fake it 'till you make it !

  4. #4

    Thread Starter
    Addicted Member Flip's Avatar
    Join Date
    Jun 2002
    Location
    Burke, VA
    Posts
    247
    Thanks! Its a little glitchy when typing, but for my purposes, im just pasting text into it - so its perfect.
    The "company" website My homepage: nerisoft.com
    scars heal but glory is forever

  5. #5

    Thread Starter
    Addicted Member Flip's Avatar
    Join Date
    Jun 2002
    Location
    Burke, VA
    Posts
    247
    Woa...
    VB Code:
    1. While DoEvents And Running
    Why have I not heard of this before....
    cool code
    Last edited by Flip; Oct 5th, 2003 at 08:37 AM.
    The "company" website My homepage: nerisoft.com
    scars heal but glory is forever

  6. #6

    Thread Starter
    Addicted Member Flip's Avatar
    Join Date
    Jun 2002
    Location
    Burke, VA
    Posts
    247
    okay, maybe im just talking to myself but...

    I didnt get your code that made the gradient, so i looked up the GradientFillRect API in API-Guide, and applied and and it works a lot faster. Here's the example they gave:
    VB Code:
    1. Private Type TRIVERTEX
    2.     x As Long
    3.     y As Long
    4.     Red As Integer 'Ushort value
    5.     Green As Integer 'Ushort value
    6.     Blue As Integer 'ushort value
    7.     Alpha As Integer 'ushort
    8. End Type
    9. Private Type GRADIENT_RECT
    10.     UpperLeft As Long  'In reality this is a UNSIGNED Long
    11.     LowerRight As Long 'In reality this is a UNSIGNED Long
    12. End Type
    13.  
    14. Const GRADIENT_FILL_RECT_H As Long = &H0 'In this mode, two endpoints describe a rectangle. The rectangle is
    15. 'defined to have a constant color (specified by the TRIVERTEX structure) for the left and right edges. GDI interpolates
    16. 'the color from the top to bottom edge and fills the interior.
    17. Const GRADIENT_FILL_RECT_V  As Long = &H1 'In this mode, two endpoints describe a rectangle. The rectangle
    18. ' is defined to have a constant color (specified by the TRIVERTEX structure) for the top and bottom edges. GDI interpolates
    19. ' the color from the top to bottom edge and fills the interior.
    20. Const GRADIENT_FILL_TRIANGLE As Long = &H2 'In this mode, an array of TRIVERTEX structures is passed to GDI
    21. 'along with a list of array indexes that describe separate triangles. GDI performs linear interpolation between triangle vertices
    22. 'and fills the interior. Drawing is done directly in 24- and 32-bpp modes. Dithering is performed in 16-, 8.4-, and 1-bpp mode.
    23. Const GRADIENT_FILL_OP_FLAG As Long = &HFF
    24.  
    25. Private Declare Function GradientFillRect Lib "msimg32" Alias "GradientFill" (ByVal hdc As Long, pVertex As TRIVERTEX, ByVal dwNumVertex As Long, pMesh As GRADIENT_RECT, ByVal dwNumMesh As Long, ByVal dwMode As Long) As Long
    26. Private Function LongToUShort(Unsigned As Long) As Integer
    27.     'A small function to convert from long to unsigned short
    28.     LongToUShort = CInt(Unsigned - &H10000)
    29. End Function
    30. Private Sub Form_Load()
    31.     'KPD-Team 1999
    32.     'URL: [url]http://www.allapi.net/[/url]
    33.     'E-Mail: [email][email protected][/email]
    34.     'API uses pixels
    35.     Me.ScaleMode = vbPixels
    36. End Sub
    37. Private Sub Form_Paint()
    38.     Dim vert(1) As TRIVERTEX
    39.     Dim gRect As GRADIENT_RECT
    40.  
    41.     'from black
    42.     With vert(0)
    43.         .x = 0
    44.         .y = 0
    45.         .Red = 0&
    46.         .Green = 0& '&HFF&   '0&
    47.         .Blue = 0&
    48.         .Alpha = 0&
    49.     End With
    50.  
    51.     'to blue
    52.     With vert(1)
    53.         .x = Me.ScaleWidth
    54.         .y = Me.ScaleHeight
    55.         .Red = 0&
    56.         .Green = 0&
    57.         .Blue = LongToUShort(&HFF00& ) ' There is no space before the ), but VBForums was tuning it into a smilie
    58.         .Alpha = 0&
    59.     End With
    60.  
    61.     gRect.UpperLeft = 0
    62.     gRect.LowerRight = 1
    63.  
    64.     GradientFillRect Me.hdc, vert(0), 2, gRect, 1, GRADIENT_FILL_RECT_H
    65. End Sub
    I used this code to make a function that affected the picturebox.
    The "company" website My homepage: nerisoft.com
    scars heal but glory is forever

  7. #7
    Junior Member davism's Avatar
    Join Date
    Jan 2004
    Location
    Rotherham, UK
    Posts
    30
    I have made a program all you can do is paste your text onto the virtual text box. When the program loads it will automatically put the clipboard text onto the label after that clicking ctrl+c will paste your text onto the label.

    Davism
    Attached Files Attached Files

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