Solved

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

Posted on 2004-10-20
10
1,869 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
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
 
LVL 48

Expert Comment

by:Mikal613
ID: 12358736
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 27

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

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…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

706 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now