I want to be able to set a gradient for the window background color without using a picture. I couldn’t find a way on the forums without using a picture.
What I really want to do is set a gradient for the window BackColor property on window open so I won’t have to repaint the window when it gets resized to prevent all the flickering than can occur.
I wrote this today using the gradient code example from @Christoph De Vocht here: https://forum.xojo.com/20988-gradients/0
Soft Declare Function GetDesktopWindow Lib "User32" () As Int32 Dim HWND As Int32 = GetDesktopWindow Soft Declare Function GetDC Lib "User32" (HWND As Integer) As Int32 Soft Declare Function DeleteDC Lib "GDI32" (hdc As Integer) As Int32 Soft Declare Function CreatePen Lib "GDI32" (fnPenStyle As Integer, nWidth As Integer, crColor As Color) As Int32 Soft Declare Function SelectObject Lib "GDI32" (HWND As Int32, DCDest As Int32) As Int32 Soft Declare Function DeleteObject Lib "GDI32" (HWND As Int32) As Boolean Soft Declare Function Rectangle Lib "GDI32" (HWND As Int32, nLeftRect As Integer, nTopRect As Integer, nRightRect As Integer, _ nBottomRect As Integer) As Boolean Const PS_SOLID = 0 dim i as integer dim y,samt,eamt as double dim intPen As Int32 dim c As Color dim intHandle As Int32 = GetDC(Handle) for i = 0 to h samt = 1 - (i / h) eamt = i / h c = rgb(_ (s.red * samt) + (e.red * eamt),_ (s.green *samt) + (e.green * eamt),_ (s.blue * samt) + (e.blue * eamt)_ ) intPen = CreatePen(PS_SOLID, 4, c) call SelectObject(intHandle, intPen) call Rectangle(intHandle, 0, 0 + i, w, 1 + i) call DeleteObject(intPen) next Call DeleteDC(HWND)
It works, you can set a gradient for the background of a window/control like this without a picture:
SetGBackColor(Window1.Handle, &cff0000, &c0000ff, Window1.Width, Window1.Height)
Of course I still have to call the method each time the window resizes.
Does anyone know a way to add a gradient using only the BackColor property of a window on open?
Thanks for any advice.