473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

images and saving time/space

Hi Guys

I have several images that will be used over and over again on different
forms in the same place, I have decided to create a control to save
space/time in development, I have create a control which inherits the panel
and added three panel control which host the 3 background images ( one to
the left the other to the right and one to fill the gap) now with this
control textboxes will be placed on these controls once they are added to
the intended form however when you get to this stage they seem to dissapear
when I move them to the front the repear they come to the from but have
inherited the background colour of the main form and not of my panels in my
control any ideas on how to get round this.
Thanks Mike.

Nov 21 '05 #1
21 1512
Nak
Hi Michael,

I've done this recently with my new free program (including source)
WTR - Web The Ripper 2. I'll highlight what I done before giving you the
link.

*Embed the image as a resource but use a PNG file if you want it alpha
blended into the background colour. I chose 15% alpha.
*In the Paint event of the panel control in the base form, do the
following,

~~~

Static pBmpBackdrop As Bitmap = getBackdrop(panStep.Width, panStep.Height,
panStep.BackColor)
Call e.Graphics.DrawImageUnscaled(pBmpBackdrop, 0, 0)

~~~

Private Function getBackdrop(ByVal iWidth As Integer, ByVal iHeight As
Integer, ByVal iBackColour As Color) As Bitmap
Dim pBmpAlpha As New Bitmap(iWidth, iHeight)
Dim pImgBack As Image =
getImageFromResource("fullnamespace.backdrop.png")
Dim pGraAlpha As Graphics = Graphics.FromImage(pBmpAlpha)
Call pGraAlpha.Clear(iBackColour)
Call pGraAlpha.DrawImage(pImgBack, New Rectangle(CInt((pBmpAlpha.Width /
2) - (pImgBack.Width / 2)), CInt((pBmpAlpha.Height / 2) - (pImgBack.Height /
2)), pImgBack.Width, pImgBack.Height), 0, 0, pImgBack.Width,
pImgBack.Height, GraphicsUnit.Pixel)
Call pGraAlpha.Dispose()
Return (pBmpAlpha)
End Function

Public Shared Function getImageFromResource(ByVal iKey As String) As Image
Dim pAssAssembly As [Assembly] = [Assembly].GetExecutingAssembly
Dim pStmInput As Stream = pAssAssembly.GetManifestResourceStream(iKey)
Dim pImgImage As Image = Image.FromStream(pStmInput, False)
Call pStmInput.Close()
Return (pImgImage)
End Function

~~~

Then compile your application and run it. You should see a picture
painted into the middle of the panel. One thing you will also want to do is
make the back colour of any labels, check boxes and radio buttons
Transparent. But *dont* use the web transparent, this had strange effects
for me. Instead you can call the following method from the derived class
(put it in the base class) upon loading it.

Protected Sub makeControlsTransparent()
Dim pCtlCurControl As Control
For Each pCtlCurControl In panStep.Controls
If (TypeOf (pCtlCurControl) Is Label) Then
CType(pCtlCurControl, Label).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is CheckBox) Then
CType(pCtlCurControl, CheckBox).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is RadioButton) Then
CType(pCtlCurControl, RadioButton).BackColor =
System.Drawing.Color.Transparent
End If
Next
End Sub

For a full working application as an example with very readable code,
goto my home page

http://www.members.lycos.co.uk/nickpatemanpwp/
^Click "My Own Software" > "WTR - Web The Ripper 2".

Nick.

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Hi Guys

I have several images that will be used over and over again on different
forms in the same place, I have decided to create a control to save
space/time in development, I have create a control which inherits the
panel and added three panel control which host the 3 background images (
one to the left the other to the right and one to fill the gap) now with
this control textboxes will be placed on these controls once they are
added to the intended form however when you get to this stage they seem to
dissapear when I move them to the front the repear they come to the from
but have inherited the background colour of the main form and not of my
panels in my control any ideas on how to get round this.
Thanks Mike.

Nov 21 '05 #2
Nak
Hi Michael,

I've done this recently with my new free program (including source)
WTR - Web The Ripper 2. I'll highlight what I done before giving you the
link.

*Embed the image as a resource but use a PNG file if you want it alpha
blended into the background colour. I chose 15% alpha.
*In the Paint event of the panel control in the base form, do the
following,

~~~

Static pBmpBackdrop As Bitmap = getBackdrop(panStep.Width, panStep.Height,
panStep.BackColor)
Call e.Graphics.DrawImageUnscaled(pBmpBackdrop, 0, 0)

~~~

Private Function getBackdrop(ByVal iWidth As Integer, ByVal iHeight As
Integer, ByVal iBackColour As Color) As Bitmap
Dim pBmpAlpha As New Bitmap(iWidth, iHeight)
Dim pImgBack As Image =
getImageFromResource("fullnamespace.backdrop.png")
Dim pGraAlpha As Graphics = Graphics.FromImage(pBmpAlpha)
Call pGraAlpha.Clear(iBackColour)
Call pGraAlpha.DrawImage(pImgBack, New Rectangle(CInt((pBmpAlpha.Width /
2) - (pImgBack.Width / 2)), CInt((pBmpAlpha.Height / 2) - (pImgBack.Height /
2)), pImgBack.Width, pImgBack.Height), 0, 0, pImgBack.Width,
pImgBack.Height, GraphicsUnit.Pixel)
Call pGraAlpha.Dispose()
Return (pBmpAlpha)
End Function

Public Shared Function getImageFromResource(ByVal iKey As String) As Image
Dim pAssAssembly As [Assembly] = [Assembly].GetExecutingAssembly
Dim pStmInput As Stream = pAssAssembly.GetManifestResourceStream(iKey)
Dim pImgImage As Image = Image.FromStream(pStmInput, False)
Call pStmInput.Close()
Return (pImgImage)
End Function

~~~

Then compile your application and run it. You should see a picture
painted into the middle of the panel. One thing you will also want to do is
make the back colour of any labels, check boxes and radio buttons
Transparent. But *dont* use the web transparent, this had strange effects
for me. Instead you can call the following method from the derived class
(put it in the base class) upon loading it.

Protected Sub makeControlsTransparent()
Dim pCtlCurControl As Control
For Each pCtlCurControl In panStep.Controls
If (TypeOf (pCtlCurControl) Is Label) Then
CType(pCtlCurControl, Label).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is CheckBox) Then
CType(pCtlCurControl, CheckBox).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is RadioButton) Then
CType(pCtlCurControl, RadioButton).BackColor =
System.Drawing.Color.Transparent
End If
Next
End Sub

For a full working application as an example with very readable code,
goto my home page

http://www.members.lycos.co.uk/nickpatemanpwp/
^Click "My Own Software" > "WTR - Web The Ripper 2".

Nick.

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Hi Guys

I have several images that will be used over and over again on different
forms in the same place, I have decided to create a control to save
space/time in development, I have create a control which inherits the
panel and added three panel control which host the 3 background images (
one to the left the other to the right and one to fill the gap) now with
this control textboxes will be placed on these controls once they are
added to the intended form however when you get to this stage they seem to
dissapear when I move them to the front the repear they come to the from
but have inherited the background colour of the main form and not of my
panels in my control any ideas on how to get round this.
Thanks Mike.

Nov 21 '05 #3
Cheers, after a bit of playing to get the result I wanted I have finally got
exactly what I was after

Thanks again

Mike.
"Nak" <a@a.com> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Hi Michael,

I've done this recently with my new free program (including source)
WTR - Web The Ripper 2. I'll highlight what I done before giving you the
link.

*Embed the image as a resource but use a PNG file if you want it alpha
blended into the background colour. I chose 15% alpha.
*In the Paint event of the panel control in the base form, do the
following,

~~~

Static pBmpBackdrop As Bitmap = getBackdrop(panStep.Width, panStep.Height,
panStep.BackColor)
Call e.Graphics.DrawImageUnscaled(pBmpBackdrop, 0, 0)

~~~

Private Function getBackdrop(ByVal iWidth As Integer, ByVal iHeight As
Integer, ByVal iBackColour As Color) As Bitmap
Dim pBmpAlpha As New Bitmap(iWidth, iHeight)
Dim pImgBack As Image =
getImageFromResource("fullnamespace.backdrop.png")
Dim pGraAlpha As Graphics = Graphics.FromImage(pBmpAlpha)
Call pGraAlpha.Clear(iBackColour)
Call pGraAlpha.DrawImage(pImgBack, New Rectangle(CInt((pBmpAlpha.Width
/ 2) - (pImgBack.Width / 2)), CInt((pBmpAlpha.Height / 2) -
(pImgBack.Height / 2)), pImgBack.Width, pImgBack.Height), 0, 0,
pImgBack.Width, pImgBack.Height, GraphicsUnit.Pixel)
Call pGraAlpha.Dispose()
Return (pBmpAlpha)
End Function

Public Shared Function getImageFromResource(ByVal iKey As String) As Image
Dim pAssAssembly As [Assembly] = [Assembly].GetExecutingAssembly
Dim pStmInput As Stream = pAssAssembly.GetManifestResourceStream(iKey)
Dim pImgImage As Image = Image.FromStream(pStmInput, False)
Call pStmInput.Close()
Return (pImgImage)
End Function

~~~

Then compile your application and run it. You should see a picture
painted into the middle of the panel. One thing you will also want to do
is make the back colour of any labels, check boxes and radio buttons
Transparent. But *dont* use the web transparent, this had strange effects
for me. Instead you can call the following method from the derived class
(put it in the base class) upon loading it.

Protected Sub makeControlsTransparent()
Dim pCtlCurControl As Control
For Each pCtlCurControl In panStep.Controls
If (TypeOf (pCtlCurControl) Is Label) Then
CType(pCtlCurControl, Label).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is CheckBox) Then
CType(pCtlCurControl, CheckBox).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is RadioButton) Then
CType(pCtlCurControl, RadioButton).BackColor =
System.Drawing.Color.Transparent
End If
Next
End Sub

For a full working application as an example with very readable code,
goto my home page

http://www.members.lycos.co.uk/nickpatemanpwp/
^Click "My Own Software" > "WTR - Web The Ripper 2".

Nick.

"Michael Turner" <fi*****@m-turner.co.uk> wrote in message
news:e7**************@tk2msftngp13.phx.gbl...
Hi Guys

I have several images that will be used over and over again on different
forms in the same place, I have decided to create a control to save
space/time in development, I have create a control which inherits the
panel and added three panel control which host the 3 background images
( one to the left the other to the right and one to fill the gap) now
with this control textboxes will be placed on these controls once they
are added to the intended form however when you get to this stage they
seem to dissapear when I move them to the front the repear they come to
the from but have inherited the background colour of the main form and
not of my panels in my control any ideas on how to get round this.
Thanks Mike.



Nov 21 '05 #4
Nak
Hi there,
Cheers, after a bit of playing to get the result I wanted I have finally
got exactly what I was after


Cool, I love doing that to panel controls now, it makes them look so
much nicer!

Nick.
Nov 21 '05 #5

"Nak" <a@a.com> wrote

Protected Sub makeControlsTransparent()
Dim pCtlCurControl As Control
For Each pCtlCurControl In panStep.Controls
If (TypeOf (pCtlCurControl) Is Label) Then
CType(pCtlCurControl, Label).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is CheckBox) Then
CType(pCtlCurControl, CheckBox).BackColor =
System.Drawing.Color.Transparent
ElseIf (TypeOf (pCtlCurControl) Is RadioButton) Then
CType(pCtlCurControl, RadioButton).BackColor =
System.Drawing.Color.Transparent
End If
Next
End Sub


FWIW compare with:

Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is Label _
OrElse TypeOf ctl Is CheckBox _
OrElse TypeOf ctl Is RadioButton _
Then
ctl.BackColor = Color.Transparent
End If
Next

....Works in all standard Windows forms! <g>

LFS

Nov 21 '05 #6
Nak
Hi Larry,
FWIW compare with:

Dim ctl As Control
For Each ctl In Me.Controls
If TypeOf ctl Is Label _
OrElse TypeOf ctl Is CheckBox _
OrElse TypeOf ctl Is RadioButton _
Then
ctl.BackColor = Color.Transparent
End If
Next


LOL, thats good point, I was written in a testing phase honest! ;-)

Nick.
Nov 21 '05 #7
To continue the discussion, here is another way to do that same task. While
Larry's routine would catch all contols, I went on the assumption that you
know which controls you want included in the group:

\\\
For Each ctr As Control In New Controls() {Label1, Checkbox1, RadioButton1}
ctr.BackColor = Color.Transparent
Next
///

One optimization would be to save the Control array at the module level to
avoid creating a new array each time a new Control is selected. If you have
other events that would need the array, then it would be advantageous to
keep such an array alive for the entire lifetime of the form....

:-))))

Cor
Nov 21 '05 #8
Nak
Hi Cor,
To continue the discussion, here is another way to do that same task.
While Larry's routine would catch all contols, I went on the assumption
that you know which controls you want included in the group: \\\
For Each ctr As Control In New Controls() {Label1, Checkbox1,
RadioButton1}
ctr.BackColor = Color.Transparent
Next
///
Tis all dynamic, it checks the form for controls of a specific type then
sets the back colour to transparent. It's all done in a base for and the
derived form calls the protected even on Load. This means I can add
controls at my hearts content and they will always look as desired.
One optimization would be to save the Control array at the module level to
avoid creating a new array each time a new Control is selected. If you
have
other events that would need the array, then it would be advantageous to
keep such an array alive for the entire lifetime of the form....


It's only called once anyay on Load. But I see what your getting at, I
just wanted a quick way to get all controls on my "wizard panel" derived
forms to be able to show the graphics drawn onto the panel. And this suited
the need perfectly. I would like to do type checking in a select block, but
I don't think this is possible is it? :-\

Anyway, cheers for the ideas Mr Cor, much appreciated.

Nick.
Nov 21 '05 #9

"Nak" <a@a.com> wrote
One optimization would be to save the Control array at the module level to
avoid creating a new array each time a new Control is selected. If you have
other events that would need the array, then it would be advantageous to
keep such an array alive for the entire lifetime of the form....


It's only called once anyay on Load.


Some might be surprised how Cor suddenly got very fluent in English....

http://groups.google.com/groups?selm...TNGP11.phx.gbl

<g>
LFS
Nov 21 '05 #10

"Cor Ligthert" <no************@planet.nl> wrote
To continue the discussion, here is another way to do that same task.


Did you debug your code?

:^P
LFS
Nov 21 '05 #11
Larry,

I hope you understand it was just for fun, I told in that thread that I was
always doing that way (There was no discussion about that between us), and
than I saw you did not do it here.

And there was nothing bad with showing that too Nick.

:-)

Cor
Nov 21 '05 #12
Larry,

I forgot, did you try that test I made?

Cor
Nov 21 '05 #13
>
Some might be surprised how Cor suddenly got very fluent in English....

Some have to do it with there English, some with the quality of what they
say.

Cor
Nov 21 '05 #14

"Cor Ligthert" <no************@planet.nl> wrote
I hope you understand it was just for fun,


What is so fun about offering a seemingly legitimate suggestion
that does not work?

LFS
Nov 21 '05 #15

"Cor Ligthert" <no************@planet.nl> wrote

I forgot, did you try that test I made?


No, that test was not going to be very informative.

What needs to be done is to bind an event that would not
get optimized out of the application (there was no code in
your event), and then unbind it.

After several iterations, the amount of time needed to
bind and unbind the event could be approximated.

That time has to be compared to calling the same event for
some number of calls, on a similar object that uses the
Handles keyword for the same event.

The figures obtained from that could be used to determine
approximately how many calls could be made to that event,
in the time it takes to bind and unbind the event.

I didn't have time to code that up today, maybe later
at the weekend....

LFS

Nov 21 '05 #16
Nak
Hi,
What is so fun about offering a seemingly legitimate suggestion
that does not work?


Well whether or works or not is a completely different story, because I
wasn't actually going to try it anyway. But isn't the group about sharing
and pooling of knowledge? My solution was made under the presumption that
you *didnt* know what controls you had on the form, that was why I was not
resorting to anything hard-coded.

Anyway, easy tiger! ;-)

Nick.
Nov 21 '05 #17

I now see, that you are writing a lot of words, from which I ask myself if
you do understand them yourself.

The test shows exactly how much time it takes adding and removing of an
event, from which you did not say, however with many words gave the
impression that it would consume a lot of effort from the system.

"Larry Serflaten" <se*******@usinternet.com>

"Cor Ligthert" <no************@planet.nl> wrote

I forgot, did you try that test I made?


No, that test was not going to be very informative.

What needs to be done is to bind an event that would not
get optimized out of the application (there was no code in
your event), and then unbind it.

After several iterations, the amount of time needed to
bind and unbind the event could be approximated.

That time has to be compared to calling the same event for
some number of calls, on a similar object that uses the
Handles keyword for the same event.

The figures obtained from that could be used to determine
approximately how many calls could be made to that event,
in the time it takes to bind and unbind the event.

I didn't have time to code that up today, maybe later
at the weekend....

LFS


Nov 21 '05 #18
I see a typo, which every beginner in VBNet sees directly. I have seen more
people in this newsgroup, who wants with that, give the idea that the
complete sample is a wrong solution. Luckily, it shows to regulars who see
those messages after a while what kind of persons that are.

More persons are telling when they see a typo from somebody else, that the
solution is wrong. However, most of us have done with that kind of people
and qualified them on the level they act.

Somebody, with not only limited knowledge, points on the error with no more
words than needed and is a little bit ashamed that he does it, because it is
a little bit childish.

In making a solution as Nick did, is the first challenge making the solution
from which the first goal is that it works. When needed than it can be
optimized, however in many cases is that useless spending time of the
programmer looking at the 20/80 rule.

By instance have I seen Nick given a sample in past, from which he self
wrote afterwards (when he made a test program, because the problem was more
general discussed and more solutions where made), that his solution was
"sloppy". However, he gave an answer that did work and nobody criticised him
because of his answer.

You see this easy criticizing mostly with beginners, although some never
learn that productivity is important and that gaining a byte is mostly penny
wise and pound-foolish.

Cor

"Larry Serflaten" <se*******@usinternet.com>
....

"Cor Ligthert" <no************@planet.nl> wrote
I hope you understand it was just for fun,


What is so fun about offering a seemingly legitimate suggestion
that does not work?

LFS

Nov 21 '05 #19

"Cor Ligthert" <no************@planet.nl> wrote
I see a typo, which every beginner in VBNet sees directly. I have seen more
people in this newsgroup, who wants with that, give the idea that the
complete sample is a wrong solution. Luckily, it shows to regulars who see
those messages after a while what kind of persons that are.


OK, Cor, have your fun, but plan on doing it without me. There are plenty here
that will take my posts at face value, and not try to read their own meanings into
what I write. You post whatever you think will work, and I will do the same....

LFS

Nov 21 '05 #20

OK, Cor, have your fun, but plan on doing it without me. There are plenty
here
that will take my posts at face value, and not try to read their own
meanings into
what I write. You post whatever you think will work, and I will do the
same....

Sorry, I don't understand this, can you explain this too me?

Cor
Nov 21 '05 #21

"Cor Ligthert" <no************@planet.nl> wrote
Sorry, I don't understand this, can you explain this too me?


It means keep up the good work....

LFS
Nov 21 '05 #22

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Lovely Angel For You | last post by:
Dear Friends Hope you all doing great. I have this problem. When I try to save any ASP page, I get the message that "The page will not save correctly". Even though I go ahead and when I go...
1
by: Mr. Orange | last post by:
I've found this might not really be possible to do with js, but I'm not really versed enough in it to know for sure. I have a web cam saving an image to a server, "cam.jpg". The cam replaces...
6
by: Michael Rozdoba | last post by:
Am I going nutty or did the Firefox WebDeveloper toolbar display all images referenced within a page, via Information -> View Page Information -> Media? With 0.8 &...
8
by: Chris Beall | last post by:
I'm struggling with how to handle, on a web page, images that contain text that the user must be able to read. Examples: tombstone photos, photos or scans of historic documents (handwritten or...
18
by: Andrew Christiansen | last post by:
Hey all. The images I create in photoshop with semi-transparent pixels (for instance in Photoshop text with a dropshadow with a transparent canvas) I've been saving in PNG format and then using...
0
by: Michael Turner | last post by:
Hi Guys I have several images that will be used over and over again on different forms in the same place, I have decided to create a control to save space/time in development, I have create a...
6
by: NutsAboutVB | last post by:
Hello, I am a .NET programmer and I have a JPEG image file (from digital camera) of about 109 KB's in size, when I open it and save it (without making any alterations at all, just going to File...
6
by: Eddie | last post by:
Hi all, I am displaying a number of reports, and giving the users an option to display them on the web or download them to Excel. If they want the Excel file, I just use the PHP header command...
3
by: =?Utf-8?B?UiBSZXllcw==?= | last post by:
Hi! This discussion may help other programmers get a better idea of how to save uploaded images through a website. Why? Well currently, I save 3 versions of every uploaded image on my own...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.