Solved

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

Posted on 2004-10-20
10
1,960 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 48

Expert Comment

by:Mikal613
ID: 12358736
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 500 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

615 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