Transparent Picture and Rotating pictures

A

Andre Nogueira

Hi there.
I have one question... How can I create a bitmap (programmatically), paint
it to a picture box and have a transparent background?
I don't know what will be below the picturebox because the user can move it
around, so there could be a textbox, another picture, a button or nothing
below the picture box.
Setting the background color of the bitmap and of the picturebox to
color.transparent does not seem to work.

Another question... I want the user to be able to insert and rotate text.
Besides the problem of the transparent background, I have another. How can I
rotate the text so that the bitmap's dimentions (weight and height) are set
so that the rotated text fits inside?

Thank you in advance for your time.
André Nogueira
 
K

Ken Tucker [MVP]

Hi,

Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As
System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint

Dim bm As New Bitmap(PictureBox1.Width, PictureBox1.Height)

Dim g As Graphics = Graphics.FromImage(bm)

g.Clear(Color.Red)

g.TranslateTransform(PictureBox1.Width / 2, PictureBox1.Height / 2)

g.RotateTransform(45)

g.DrawString("Test", Me.Font, Brushes.White, 0, 0)

bm.MakeTransparent(Color.Red)

e.Graphics.DrawImage(bm, 0, 0)

End Sub


Ken
 
A

Andre Nogueira

Thank you for your reply!
However, I have two more problems...
What if the rotation isn't 45 degrees (how do I get the right height/width)
and what if the background is not a color but a picture?

Andre Nogueira
 
K

Ken Tucker [MVP]

Hi,

Take a look at the graphics classes measurestring method. Draw on a
copy of the bitmap.

Ken
 
A

Andre Nogueira

But the problem is that the user can click and drag the picture box anywhere
on the form... Like you can do in Powerpoint...
So the picture box with the text can be on top of the form itself, on top of
one image, on top of two images, on top of an image and other text...
Thank you anyway for your time and patience =)

Andre Nogueira
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top