Solved

Create a brush

Posted on 2010-08-25
14
582 Views
Last Modified: 2013-11-23
My question is, how to create a transparent bitmap on each control?
var 
MyBitmap: TBitmap;
Begin
MyBitmap:=TBitmap.Create;
MyBitmap := image1.Picture.Bitmap;

//this creates an image from image1
Form1.Brush.Bitmap:=MyBitmap;

//this creates an image too, but the image is new, it is not transparent with the form1 image
Memo1.Brush.Bitmap:=MyBitmap;

//this does not create an image, transparent with the form1
Button1.Brush.Bitmap:=MyBitmap;

Open in new window

form1
0
Comment
Question by:systan
  • 5
  • 3
  • 3
  • +1
14 Comments
 
LVL 13

Expert Comment

by:aflarin
Comment Utility
For labels you can just set Transparent property to True
0
 
LVL 13

Assisted Solution

by:aflarin
aflarin earned 50 total points
Comment Utility
I'm afraid for other controls you have to override their paint procedure
0
 
LVL 25

Expert Comment

by:epasquier
Comment Utility
yes, doing such transparent controls is not easy. You'll have to do it for each kind.

I'll see what I can find for some of them, I know there has been lots of work on that kind of subject.

In the meantime, there is something you do wrong, I know that it is not the subject but :

MyBitmap:=TBitmap.Create;
MyBitmap := image1.Picture.Bitmap;

You DON'T HAVE and MUST NOT create a bitmap to put in MyBitmap if it is to get it from Image1 the next line. By doing so, you are loosing the reference of the bitmap just created and some memory will leak.

simply :
MyBitmap := image1.Picture.Bitmap; (get the reference)
or :
MyBitmap:=TBitmap.Create;
MyBitmap.Assign(image1.Picture.Bitmap); (copy the content)
0
 
LVL 25

Expert Comment

by:epasquier
Comment Utility
0
 
LVL 25

Expert Comment

by:epasquier
Comment Utility
for richedit :

Richedit1.Brush.Style:=BsClear;
SetWindowLong(Form1.Richedit1.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT);

this ones have a unit for both TMemo (looks like the same as the first) and TEdit
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_20300214.html
0
 
LVL 14

Expert Comment

by:DragonSlayer
Comment Utility
Not directly relevant, but might do for an interesting read:
http://melander.dk/articles/alphasplash/
http://melander.dk/articles/alphasplash2
0
 
LVL 14

Author Comment

by:systan
Comment Utility
>>I'm afraid for other controls you have to override their paint procedure
I Need more research Aflarin

>>MyBitmap.Assign(image1.Picture.Bitmap); (copy the content)
>>Richedit1.Brush.Style:=BsClear;
>>SetWindowLong(Form1.Richedit1.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT);
I will Epasquier

DragonSlayer?
Alphablend?
Can this procedure applicable to my form? with the buttons, listboxes, tabmenus, labels will be alphablend to my form?  I think this is just like doing a transparent controls over the form? Isn't it?
Or this is just a few seconds alphablend then back to normal window?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 14

Assisted Solution

by:DragonSlayer
DragonSlayer earned 200 total points
Comment Utility
Not really... that's why I said it's not directly relevant, heh :-D

Back to your Q, aside from overriding Paint, you would also need to override the WM_ERASEBKGND message of the component... here's a sample:

http://delphicikk.atw.hu/listaz.php?id=1341&oldal=26
0
 
LVL 25

Accepted Solution

by:
epasquier earned 250 total points
Comment Utility
check the memo and edit sample, they both gives you the principles of what you have to look at.
0
 
LVL 14

Author Closing Comment

by:systan
Comment Utility
>>override the WM_ERASEBKGND message
I think this is also connected with what epasquier's comment_v

>>check the memo and edit sample, they both gives you the principles of what you have to look at.
Yes, I have that in mind when I see the code,  thanks epasquier.


Why wait,  this post is closed.
Thanks a lot friends, experts
0
 
LVL 14

Expert Comment

by:DragonSlayer
Comment Utility
Actually you do not have to award me some of the points... epasquier did a good enough job... I was just pointing out similar samples. I'm not into this for the points anyway :-D
0
 
LVL 13

Expert Comment

by:aflarin
Comment Utility
>> Actually you do not have to award me some of the points... epasquier did a good enough job

I agree at all. Great job, epasquier
0
 
LVL 14

Author Comment

by:systan
Comment Utility
Excuse me fellows,
But  I did what I want,   just like I did in some of my questions.
I'm not a gridy kind of person,  the point here is that you contributed, helped, as epaquier said "team work", so the rest of you shall have a share.   I am the one incharge if the comment is good for me or not,  so please understand the asker, me.


Thank you all
0
 
LVL 25

Expert Comment

by:epasquier
Comment Utility
Yes, Team Work !  I'm glad somebody in that last post heard the message how it was intended.
I have no complaints with your way of distributing points, I find it fair and only wish it would be always the same for all askers.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This video discusses moving either the default database or any database to a new volume.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

771 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

16 Experts available now in Live!

Get 1:1 Help Now