Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to draw a semi-transparent line on a picture control in VB6

Posted on 2004-10-20
10
Medium Priority
?
1,990 Views
Last Modified: 2012-06-27
I have a picture control which has a gradient filled background.

This picture control is to be used as the background (and container) of a gant-chart style calendar which is drawn on using VB code.

We draw on top of the picture, several vertical and horizontal lines; vertical lines seperate hours, and the horizontal ones seperate different resources which can be scheduled.

Currently, the lines are drawn in a single colour (actually, 2 colours for a 3D effect) but I want them to be drawn semi-transparent, so that the gradient fill colour is shown through the line. This should allow for a more realistic 3D effect.

The whole application is already working, so please dont suggest re-writing in .Net etc as at this stage it is not possible.

Obviously, using the 2 colours and a single coloured / non-gradient background looks fine, but it looks much nicer with a gradient fill, and our clients have requested it.

Many thanks,

Sam
0
Comment
Question by:SamEdney
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 1

Author Comment

by:SamEdney
ID: 12358192
To give you some idea of what I am trying to do.... this is the layout.

             1pm     2pm      3pm     4pm
-----------------------------------------------------
Res 1 |          |           |           |           |
-----------------------------------------------------
Res 2 |          |           |           |           |
-----------------------------------------------------
Res 3 |          |           |           |           |
-----------------------------------------------------
Res 4 |          |           |           |           |
-----------------------------------------------------
0
 
LVL 48

Expert Comment

by:Mikal613
ID: 12358484
why dont you make it in MSPaint and add that as your background image and then you can draw over that.
0
 
LVL 1

Author Comment

by:SamEdney
ID: 12358686
No can do. The screen does not always show the same number of resources, or days. It is totally customisable by the user. It has to be dynamic. Also, the gradient colour is definable.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 48

Expert Comment

by:Mikal613
ID: 12358736
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 2000 total points
ID: 12359213
You can use the flat GDI+ API to draw alpha blended lines in VB6.

Here are some references:

"Alpha Blending Lines and Fills"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdicpp/GDIPlus/usingGDIPlus/alphablendinglinesandfills.asp

Here is a comprehensive GDI+ sample project from psc.com
http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=37541&lngWId=1

And here is a GDI+ Type Library (used in the example below)
http://www.vbaccelerator.com/home/VB/Type_Libraries/GDIPlus_Type_Library/article.asp

And the example of drawing alpha lines on a picturebox:

'
'Add a reference to GDIPlus.tlb
'

Option Explicit

'Needed to close GDI+
Private token As Long

Private Sub Form_Load()
   ' Load the GDI+ Dll
   Dim GpInput As GdiplusStartupInput
   GpInput.GdiplusVersion = 1
   If GdiplusStartup(token, GpInput) <> Ok Then
      MsgBox "Error loading GDI+!", vbCritical
      Unload Me
   End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
   ' Unload the GDI+ Dll
   Call GdiplusShutdown(token)
End Sub


Private Sub Command1_Click()

    Dim graphics As Long, bitmap As Long
    Dim lngHeight As Long, lngWidth As Long
    Dim opaquePen As Long, semiTansPen As Long
    Dim stat As GpStatus
   
    ' Initialize the graphics class using Picture1.hDC
    stat = GdipCreateFromHDC(Picture1.hdc, graphics)
   
    ' Create 2 pens for line drawing, one solid, one with 50% alpha blending
    'ColorARGB takes: Alpha, Red, Green, Blue
    'The solid blue pen
    Call GdipCreatePen1(ColorARGB(255, 0, 0, 255), 15, UnitPixel, opaquePen)
   
    ' Has 50% alpha blending
    Call GdipCreatePen1(ColorARGB(128, 0, 0, 255), 15, UnitPixel, semiTansPen)
   
   
    ' Draw an opaque line over the image
    stat = GdipDrawLine(graphics, opaquePen, 0, 20, 300, 20)
   
    ' Draw the semi-transparent line over the image
    stat = GdipDrawLine(graphics, semiTansPen, 0, 40, 300, 40)
   
    ' Draw the same semi-transparent line, but with gamma correction
    stat = GdipSetCompositingQuality(graphics, CompositingQualityGammaCorrected)
    stat = GdipDrawLine(graphics, semiTansPen, 0, 60, 300, 60)
   
    ' Cleanup
    Call GdipDeletePen(opaquePen)
    Call GdipDeletePen(semiTansPen)
    Call GdipDeleteGraphics(graphics)
End Sub

Private Function ColorARGB(ByVal alpha As Byte, ByVal Red As Byte, ByVal Green As Byte, ByVal Blue As Byte) As Long
   Dim bytestruct As COLORBYTES
   Dim result As COLORLONG
   
   With bytestruct
      .AlphaByte = alpha
      .RedByte = Red
      .GreenByte = Green
      .BlueByte = Blue
   End With
   
   LSet result = bytestruct
   ColorARGB = result.longval
End Function

0
 
LVL 23

Expert Comment

by:Ioannis Paraskevopoulos
ID: 12366815
Why don't you draw a line and set its border style property to dot or dash?
0
 
LVL 28

Expert Comment

by:Ark
ID: 12409401
I suggest to draw smal pieces of vertical and horizontal 3D lines (say 3x10/10x3 pixels) in any graphics editor (MSPaint/PhotosShop etc). Then use AlphaBlend function from msimg32.dll to draw them blended on the BG one-by-one. See my sample at http://freevbcode.com/ShowCode.Asp?ID=1501 on using msimg32.dll
0
 
LVL 1

Author Comment

by:SamEdney
ID: 12656421
Wow. Looks as though the time for completing questions has decreased a bit! I still havent even tried this, so have no idea if it works. Will post back any info though. Thanks for the help so far....!
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question