473,769 Members | 1,723 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

picture box question

rut
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the screen can
fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.
Nov 21 '05 #1
9 1888
You can create a graphics region using the CreateGraphics Method for the
picture box control and use the DrawString method to write text graphically.

As for text changing with background fading, I think you can change the
opacity of the control but I have not tried it


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the screen can fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.

Nov 21 '05 #2
rut
Any code samples illustrating this?

"One Handed Man ( OHM - Terry Burns )" wrote:
You can create a graphics region using the CreateGraphics Method for the
picture box control and use the DrawString method to write text graphically.

As for text changing with background fading, I think you can change the
opacity of the control but I have not tried it


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the screen

can
fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.


Nov 21 '05 #3
I refer you to the articles in the GDI+ FAQ explaining why you *shouldn't*
use CreateGraphics and how to correctly service the Paint event.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
You can create a graphics region using the CreateGraphics Method for the
picture box control and use the DrawString method to write text graphically.
As for text changing with background fading, I think you can change the
opacity of the control but I have not tried it


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the screen

can
fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.


Nov 21 '05 #4
perhaps you could answer the OP's question then and point specifically to
the reason one should not use CreateGraphics rather than referring me to
your own home page.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:em******** ******@TK2MSFTN GP11.phx.gbl...
I refer you to the articles in the GDI+ FAQ explaining why you *shouldn't*
use CreateGraphics and how to correctly service the Paint event.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
You can create a graphics region using the CreateGraphics Method for the
picture box control and use the DrawString method to write text

graphically.

As for text changing with background fading, I think you can change the
opacity of the control but I have not tried it


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the
screen can
fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.



Nov 21 '05 #5
Controls provide a paint event that is called at the end of their own paint
cycles. Handling this event and painting on the Graphics object provided
will ensure that whatever you paint is correctly timed to coincide with the
message driven architecture of Windows.

You can force the control to paint itself by calling the Invalidate method,
this initiates a paint cycle which will then kick off the Paint event where
you can do your own drawing.

For your own requirements you're a bit stuck because PictureBox doesn't do
internal double buffering and so invalidating the control at a rate that
would enable animation such as you require would also cause unacceptable
flickering. I don't think you'll get a good result with a transition engine
that writes over the contents of a PictureBox. PictureBox is a fairly
useless and much misused control anyway.

I would suggest creating a custom control to display an image and do the
transitions. Below my signature is a control I wrote for WellFormed that
does transitions. You may be able to modify that code to suit your purposes.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml

----------------------------------------------------------------------------
------------------

Imports System

Imports System.Componen tModel

Imports System.Drawing

Imports System.Drawing. Drawing2D

Imports System.Drawing. Imaging

Imports System.Threadin g

Imports System.Windows. Forms

Namespace WellFormed

'/ <summary>

'/ Summary description for ImageTransition Control.

'/ </summary>

Public Class ImageTransition Control

Inherits Control

Private t As System.Threadin g.Timer

Public Enum TransitionTypes

Fade

BarnDoor

Slide

Spin

Checker

Blinds

Iris

Spiral

End Enum 'TransitionType s

Private _transitionType As TransitionTypes = TransitionTypes .Fade

Public Property TransitionType( ) As TransitionTypes

Get

Return _transitionType

End Get

Set(ByVal Value As TransitionTypes )

_transitionType = value

End Set

End Property

Private _nHDivs As Integer = 3

Public Property HorizontalDivis ions() As Integer

Get

Return _nHDivs

End Get

Set(ByVal Value As Integer)

If value = 0 Then

value = 3

End If

_nHDivs = value

End Set

End Property

Private _nVDivs As Integer = 3

Public Property VerticalDivisio ns() As Integer

Get

Return _nVDivs

End Get

Set(ByVal Value As Integer)

If value = 0 Then

value = 3

End If

_nVDivs = value

End Set

End Property

Private _imageA As Image

Public Property ImageA() As Image

Get

Return _imageA

End Get

Set(ByVal Value As Image)

_imageA = value

End Set

End Property

Private _imageB As Image

Public Property ImageB() As Image

Get

Return _imageB

End Get

Set(ByVal Value As Image)

_imageB = value

End Set

End Property

Public Sub New()

SetStyle(Contro lStyles.AllPain tingInWmPaint Or ControlStyles.D oubleBuffer Or
ControlStyles.U serPaint Or ControlStyles.R esizeRedraw, True)

End Sub 'New

'Variables used in the timing system

Private _transitionTime As New TimeSpan(0, 0, 0, 1, 0)

Private _currentPercent age As Single = 0

Private _running As Boolean = False

Public Property TransitionTime( ) As Single

Get

Return CSng(_transitio nTime.TotalSeco nds)

End Get

Set(ByVal Value As Single)

_transitionTime = New TimeSpan(0, 0, 0, 0, CInt(1000 * value))

End Set

End Property

'The moment at which the transition begins

Private _startTime As DateTime

'Called to start the transition off

Public Sub Go()

t = New System.Threadin g.Timer(New TimerCallback(A ddressOf Tick), Nothing,
40, 40)

Me._currentPerc entage = 0

_running = True

_startTime = DateTime.Now

Invalidate()

End Sub 'Go

'Services the tick event and re-calculates the percentage done

Sub Tick(ByVal state As Object)

Dim ts As TimeSpan = DateTime.Now.Su btract(Me._star tTime)

_currentPercent age = CSng(100.0F / Me._transitionT ime.TotalSecond s *
ts.TotalSeconds )

If _currentPercent age > 100 Then

_currentPercent age = 100

End If

Invalidate()

End Sub 'Tick

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

If _imageA Is Nothing OrElse _imageB Is Nothing Then

Return

End If

Dim pth As GraphicsPath = Nothing

If _currentPercent age < 100 Then

e.Graphics.Draw Image(_imageA, Me.ClientRectan gle, 0, 0, _imageA.Width,
_imageA.Height, GraphicsUnit.Pi xel)

End If

Select Case Me.TransitionTy pe

Case TransitionTypes .Fade

If (True) Then

'This transition fades one image over the other

Dim ia As New ImageAttributes

Dim cm As New ColorMatrix

cm.Matrix33 = 1.0F / 255 * (255 * _currentPercent age / 100)

ia.SetColorMatr ix(cm)

e.Graphics.Draw Image(_imageB, Me.ClientRectan gle, 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel, ia)

ia.Dispose()

End If

Case TransitionTypes .BarnDoor

'has the effect of a barn door closing over the image

e.Graphics.Draw Image(_imageB, New Rectangle(0, 0, CInt(Me.Width *
_currentPercent age / 200), Me.Height), 0, 0, CInt(_imageB.Wi dth / 2),
_imageB.Height, GraphicsUnit.Pi xel)

e.Graphics.Draw Image(_imageB, New Rectangle(CInt( Me.Width - Me.Width *
_currentPercent age / 200), 0, CInt(Me.ClientR ectangle.Width *
_currentPercent age / 200), Me.ClientRectan gle.Height), CInt(_imageB.Wi dth /
2), 0, CInt(_imageB.Wi dth / 2), _imageB.Height, GraphicsUnit.Pi xel)

Case TransitionTypes .Iris

'use a path

pth = New GraphicsPath

'calculate the width and height of the ellipse

Dim w As Integer = CInt(Me.Width * 1.414F * _currentPercent age / 200)

Dim h As Integer = CInt(Me.Height * 1.414F * _currentPercent age / 200)

pth.AddEllipse( CInt(Me.Width / 2 - w), CInt(Me.Height / 2 - h), CInt(2 * w),
CInt(2 * h))

'use the path as a clipping region

e.Graphics.SetC lip(pth, CombineMode.Rep lace)

'Draw the image

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

pth.Dispose()

Case TransitionTypes .Checker

pth = New GraphicsPath

Dim cw As Integer = CInt(Me.Width * _currentPercent age / 100) / _nHDivs

Dim ch As Integer = Me.Height / _nVDivs

Dim row As Integer = 0

Dim y As Integer

For y = 0 To (Me.Height) - ch Step ch

Dim x As Integer

For x = 0 To (Me.Width) - (Me.Width / _nHDivs) Step Me.Width / _nHDivs

Dim rc As New Rectangle(x, y, cw, ch)

If (row And 1) = 1 Then

rc.Offset(Me.Wi dth / (2 * _nVDivs), 0)

End If

pth.AddRectangl e(rc)

If _currentPercent age >= 50 AndAlso (row And 1) = 1 AndAlso x = 0 Then

rc.Offset(-(Me.Width / _nHDivs), 0)

pth.AddRectangl e(rc)

End If

Next x

row += 1

Next y

Dim r As New [Region](pth)

e.Graphics.SetC lip(r, CombineMode.Rep lace)

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

r.Dispose()

pth.Dispose()

Case TransitionTypes .Slide

Dim mx As New Matrix(1, 0, 0, 1, Me.Width * _currentPercent age / 100 -
Me.Width, 0)

e.Graphics.Tran sform = mx

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

Case TransitionTypes .Spin

' calculate the degrees of spin

Dim degrees As Single = 360 * _currentPercent age / 100

'and the origin (center of the client area

Dim ofsX As Single = Me.Width / 2

Dim ofsY As Single = Me.Height / 2

'calculate the scale at which the image will be drawn

Dim Scale As Single = 1 * _currentPercent age / 100

'catering for zero's which will cause an exception

If Scale = 0 Then

Scale = 0.0001F

End If 'create a matrix with the scale and origin

Dim rm As New Matrix(Scale, 0, 0, Scale, ofsX, ofsY)

'do the spin

rm.Rotate(degre es, MatrixOrder.Pre pend)

'use the matrix

e.Graphics.Tran sform = rm

'draw the image

e.Graphics.Draw Image(_imageB, New Rectangle(-Width / 2, -Height / 2, Width,
Height), 0, 0, _imageB.Width, _imageB.Height, GraphicsUnit.Pi xel)

rm.Dispose()

Case TransitionTypes .Spiral

If _currentPercent age < 100 Then

Dim percentageAngle As Double = _nHDivs * (Math.PI * 2) / 100

Dim percentageDista nce As Double = Math.Max(Width, Height) / 100

pth = New GraphicsPath(Fi llMode.Winding)

Dim cx As Single = Width / 2

Dim cy As Single = Height / 2

Dim pc1 As Double = _currentPercent age - 100

Dim pc2 As Double = _currentPercent age

If pc1 < 0 Then

pc1 = 0

End If

Dim a As Double = percentageAngle * pc2

Dim last As New PointF(CSng(cx + pc1 * percentageDista nce * Math.Cos(a)),
CSng(cy + pc1 * percentageDista nce * Math.Sin(a)))

a = percentageAngle * pc1

While pc1 <= pc2

Dim thisPoint As New PointF(CSng(cx + pc1 * percentageDista nce *
Math.Cos(a)), CSng(cy + pc1 * percentageDista nce * Math.Sin(a)))

pth.AddLine(las t, thisPoint)

last = thisPoint

pc1+=0.1

a+=percentageAn gle/10

End While

pth.CloseFigure ()

e.Graphics.SetC lip(pth, CombineMode.Rep lace)

pth.Dispose()

End If

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

Case TransitionTypes .Blinds

Dim y As Integer

For y = 0 To _nHDivs - 1

Dim src As New Rectangle(0, y * (_imageB.Height / _nHDivs), _imageB.Width,
_imageB.Height / _nHDivs)

Dim drc As New Rectangle(0, y * (Height / _nHDivs), Width, CInt(Height /
_nHDivs * _currentPercent age / 100))

drc.Offset(0, Height / (_nHDivs * 2) - drc.Height / 2)

e.Graphics.Draw Image(_imageB, drc, src, GraphicsUnit.Pi xel)

Next y

End Select

If _currentPercent age = 100 Then

_running = False

If Not (t Is Nothing) Then

t.Dispose()

End If

t = Nothing

End If

MyBase.OnPaint( e)

End Sub 'OnPaint

End Class 'ImageTransitio nControl

End Namespace 'WellFormed
----------------------------------------------------------------------------
------------------


"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the screen can fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.

Nov 21 '05 #6
Considering that my own home-page contains nothing but free information for
both VB and C# users I didn't think you would mind. It's not as if I'm
trying to sell you anything. I know you have a particular aversion to
commercialism in these posts.

The article at http://www.bobpowell.net/creategraphics.htm explains in
detail when and how you should use CreateGraphics and the article at
http://www.bobpowell.net/picturebox.htm deals with why you shouldn't use the
PictureBox control in the manner you suggest.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in message
news:uo******** ********@TK2MSF TNGP10.phx.gbl. ..
perhaps you could answer the OP's question then and point specifically to
the reason one should not use CreateGraphics rather than referring me to
your own home page.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:em******** ******@TK2MSFTN GP11.phx.gbl...
I refer you to the articles in the GDI+ FAQ explaining why you *shouldn't*
use CreateGraphics and how to correctly service the Paint event.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"One Handed Man ( OHM - Terry Burns )" <news.microsoft .com> wrote in

message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
You can create a graphics region using the CreateGraphics Method for the picture box control and use the DrawString method to write text

graphically.

As for text changing with background fading, I think you can change the opacity of the control but I have not tried it


--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
> If I have a picturebox with a background image and I want to
>
> 1. Display text atop of the background and
> 2. Have transistions between text; ie, when the text changes, the

screen can
> fade out/in or have a windowblind type transition,etc.
>
> How do you create transitions in a picture box in conjunction with
> displaying text?
>
> (Using vb.net.



Nov 21 '05 #7
On Tue, 21 Sep 2004 15:27:33 +0100, One Handed Man ( OHM - Terry Burns )
wrote:
perhaps you could answer the OP's question then and point specifically to
the reason one should not use CreateGraphics rather than referring me to
your own home page.


The link to the GDI_FAQ which is in his sig, explains why not to use the
PictureBox and how to use an alternate method.

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.
Nov 21 '05 #8
Thanx for that.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Chris Dunaway" <"dunawayc[[at]_lunchmeat_sbcg lobal[dot]]net"> wrote in
message news:fp******** *************** *****@40tude.ne t...
On Tue, 21 Sep 2004 15:27:33 +0100, One Handed Man ( OHM - Terry Burns )
wrote:
perhaps you could answer the OP's question then and point specifically to the reason one should not use CreateGraphics rather than referring me to
your own home page.


The link to the GDI_FAQ which is in his sig, explains why not to use the
PictureBox and how to use an alternate method.

--
Chris

dunawayc[AT]sbcglobal_lunch meat_[DOT]net

To send me an E-mail, remove the "[", "]", underscores ,lunchmeat, and
replace certain words in my E-Mail address.

Nov 21 '05 #9
Thanks for answering that one Bob.

I was not being objectionable wrt your link, simply pointing out that a link
directly to the article would have been more efficient.

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
If U Need My Email ,Ask Me

Time flies when you don't know what you're doing

"Bob Powell [MVP]" <bob@_spamkille r_bobpowell.net > wrote in message
news:OR******** ******@TK2MSFTN GP14.phx.gbl...
Controls provide a paint event that is called at the end of their own paint cycles. Handling this event and painting on the Graphics object provided
will ensure that whatever you paint is correctly timed to coincide with the message driven architecture of Windows.

You can force the control to paint itself by calling the Invalidate method, this initiates a paint cycle which will then kick off the Paint event where you can do your own drawing.

For your own requirements you're a bit stuck because PictureBox doesn't do
internal double buffering and so invalidating the control at a rate that
would enable animation such as you require would also cause unacceptable
flickering. I don't think you'll get a good result with a transition engine that writes over the contents of a PictureBox. PictureBox is a fairly
useless and much misused control anyway.

I would suggest creating a custom control to display an image and do the
transitions. Below my signature is a control I wrote for WellFormed that
does transitions. You may be able to modify that code to suit your purposes.
--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml

-------------------------------------------------------------------------- -- ------------------

Imports System

Imports System.Componen tModel

Imports System.Drawing

Imports System.Drawing. Drawing2D

Imports System.Drawing. Imaging

Imports System.Threadin g

Imports System.Windows. Forms

Namespace WellFormed

'/ <summary>

'/ Summary description for ImageTransition Control.

'/ </summary>

Public Class ImageTransition Control

Inherits Control

Private t As System.Threadin g.Timer

Public Enum TransitionTypes

Fade

BarnDoor

Slide

Spin

Checker

Blinds

Iris

Spiral

End Enum 'TransitionType s

Private _transitionType As TransitionTypes = TransitionTypes .Fade

Public Property TransitionType( ) As TransitionTypes

Get

Return _transitionType

End Get

Set(ByVal Value As TransitionTypes )

_transitionType = value

End Set

End Property

Private _nHDivs As Integer = 3

Public Property HorizontalDivis ions() As Integer

Get

Return _nHDivs

End Get

Set(ByVal Value As Integer)

If value = 0 Then

value = 3

End If

_nHDivs = value

End Set

End Property

Private _nVDivs As Integer = 3

Public Property VerticalDivisio ns() As Integer

Get

Return _nVDivs

End Get

Set(ByVal Value As Integer)

If value = 0 Then

value = 3

End If

_nVDivs = value

End Set

End Property

Private _imageA As Image

Public Property ImageA() As Image

Get

Return _imageA

End Get

Set(ByVal Value As Image)

_imageA = value

End Set

End Property

Private _imageB As Image

Public Property ImageB() As Image

Get

Return _imageB

End Get

Set(ByVal Value As Image)

_imageB = value

End Set

End Property

Public Sub New()

SetStyle(Contro lStyles.AllPain tingInWmPaint Or ControlStyles.D oubleBuffer Or ControlStyles.U serPaint Or ControlStyles.R esizeRedraw, True)

End Sub 'New

'Variables used in the timing system

Private _transitionTime As New TimeSpan(0, 0, 0, 1, 0)

Private _currentPercent age As Single = 0

Private _running As Boolean = False

Public Property TransitionTime( ) As Single

Get

Return CSng(_transitio nTime.TotalSeco nds)

End Get

Set(ByVal Value As Single)

_transitionTime = New TimeSpan(0, 0, 0, 0, CInt(1000 * value))

End Set

End Property

'The moment at which the transition begins

Private _startTime As DateTime

'Called to start the transition off

Public Sub Go()

t = New System.Threadin g.Timer(New TimerCallback(A ddressOf Tick), Nothing,
40, 40)

Me._currentPerc entage = 0

_running = True

_startTime = DateTime.Now

Invalidate()

End Sub 'Go

'Services the tick event and re-calculates the percentage done

Sub Tick(ByVal state As Object)

Dim ts As TimeSpan = DateTime.Now.Su btract(Me._star tTime)

_currentPercent age = CSng(100.0F / Me._transitionT ime.TotalSecond s *
ts.TotalSeconds )

If _currentPercent age > 100 Then

_currentPercent age = 100

End If

Invalidate()

End Sub 'Tick

Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)

If _imageA Is Nothing OrElse _imageB Is Nothing Then

Return

End If

Dim pth As GraphicsPath = Nothing

If _currentPercent age < 100 Then

e.Graphics.Draw Image(_imageA, Me.ClientRectan gle, 0, 0, _imageA.Width,
_imageA.Height, GraphicsUnit.Pi xel)

End If

Select Case Me.TransitionTy pe

Case TransitionTypes .Fade

If (True) Then

'This transition fades one image over the other

Dim ia As New ImageAttributes

Dim cm As New ColorMatrix

cm.Matrix33 = 1.0F / 255 * (255 * _currentPercent age / 100)

ia.SetColorMatr ix(cm)

e.Graphics.Draw Image(_imageB, Me.ClientRectan gle, 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel, ia)

ia.Dispose()

End If

Case TransitionTypes .BarnDoor

'has the effect of a barn door closing over the image

e.Graphics.Draw Image(_imageB, New Rectangle(0, 0, CInt(Me.Width *
_currentPercent age / 200), Me.Height), 0, 0, CInt(_imageB.Wi dth / 2),
_imageB.Height, GraphicsUnit.Pi xel)

e.Graphics.Draw Image(_imageB, New Rectangle(CInt( Me.Width - Me.Width *
_currentPercent age / 200), 0, CInt(Me.ClientR ectangle.Width *
_currentPercent age / 200), Me.ClientRectan gle.Height), CInt(_imageB.Wi dth / 2), 0, CInt(_imageB.Wi dth / 2), _imageB.Height, GraphicsUnit.Pi xel)

Case TransitionTypes .Iris

'use a path

pth = New GraphicsPath

'calculate the width and height of the ellipse

Dim w As Integer = CInt(Me.Width * 1.414F * _currentPercent age / 200)

Dim h As Integer = CInt(Me.Height * 1.414F * _currentPercent age / 200)

pth.AddEllipse( CInt(Me.Width / 2 - w), CInt(Me.Height / 2 - h), CInt(2 * w), CInt(2 * h))

'use the path as a clipping region

e.Graphics.SetC lip(pth, CombineMode.Rep lace)

'Draw the image

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

pth.Dispose()

Case TransitionTypes .Checker

pth = New GraphicsPath

Dim cw As Integer = CInt(Me.Width * _currentPercent age / 100) / _nHDivs

Dim ch As Integer = Me.Height / _nVDivs

Dim row As Integer = 0

Dim y As Integer

For y = 0 To (Me.Height) - ch Step ch

Dim x As Integer

For x = 0 To (Me.Width) - (Me.Width / _nHDivs) Step Me.Width / _nHDivs

Dim rc As New Rectangle(x, y, cw, ch)

If (row And 1) = 1 Then

rc.Offset(Me.Wi dth / (2 * _nVDivs), 0)

End If

pth.AddRectangl e(rc)

If _currentPercent age >= 50 AndAlso (row And 1) = 1 AndAlso x = 0 Then

rc.Offset(-(Me.Width / _nHDivs), 0)

pth.AddRectangl e(rc)

End If

Next x

row += 1

Next y

Dim r As New [Region](pth)

e.Graphics.SetC lip(r, CombineMode.Rep lace)

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

r.Dispose()

pth.Dispose()

Case TransitionTypes .Slide

Dim mx As New Matrix(1, 0, 0, 1, Me.Width * _currentPercent age / 100 -
Me.Width, 0)

e.Graphics.Tran sform = mx

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

Case TransitionTypes .Spin

' calculate the degrees of spin

Dim degrees As Single = 360 * _currentPercent age / 100

'and the origin (center of the client area

Dim ofsX As Single = Me.Width / 2

Dim ofsY As Single = Me.Height / 2

'calculate the scale at which the image will be drawn

Dim Scale As Single = 1 * _currentPercent age / 100

'catering for zero's which will cause an exception

If Scale = 0 Then

Scale = 0.0001F

End If 'create a matrix with the scale and origin

Dim rm As New Matrix(Scale, 0, 0, Scale, ofsX, ofsY)

'do the spin

rm.Rotate(degre es, MatrixOrder.Pre pend)

'use the matrix

e.Graphics.Tran sform = rm

'draw the image

e.Graphics.Draw Image(_imageB, New Rectangle(-Width / 2, -Height / 2, Width, Height), 0, 0, _imageB.Width, _imageB.Height, GraphicsUnit.Pi xel)

rm.Dispose()

Case TransitionTypes .Spiral

If _currentPercent age < 100 Then

Dim percentageAngle As Double = _nHDivs * (Math.PI * 2) / 100

Dim percentageDista nce As Double = Math.Max(Width, Height) / 100

pth = New GraphicsPath(Fi llMode.Winding)

Dim cx As Single = Width / 2

Dim cy As Single = Height / 2

Dim pc1 As Double = _currentPercent age - 100

Dim pc2 As Double = _currentPercent age

If pc1 < 0 Then

pc1 = 0

End If

Dim a As Double = percentageAngle * pc2

Dim last As New PointF(CSng(cx + pc1 * percentageDista nce * Math.Cos(a)),
CSng(cy + pc1 * percentageDista nce * Math.Sin(a)))

a = percentageAngle * pc1

While pc1 <= pc2

Dim thisPoint As New PointF(CSng(cx + pc1 * percentageDista nce *
Math.Cos(a)), CSng(cy + pc1 * percentageDista nce * Math.Sin(a)))

pth.AddLine(las t, thisPoint)

last = thisPoint

pc1+=0.1

a+=percentageAn gle/10

End While

pth.CloseFigure ()

e.Graphics.SetC lip(pth, CombineMode.Rep lace)

pth.Dispose()

End If

e.Graphics.Draw Image(_imageB, ClientRectangle , 0, 0, _imageB.Width,
_imageB.Height, GraphicsUnit.Pi xel)

Case TransitionTypes .Blinds

Dim y As Integer

For y = 0 To _nHDivs - 1

Dim src As New Rectangle(0, y * (_imageB.Height / _nHDivs), _imageB.Width,
_imageB.Height / _nHDivs)

Dim drc As New Rectangle(0, y * (Height / _nHDivs), Width, CInt(Height /
_nHDivs * _currentPercent age / 100))

drc.Offset(0, Height / (_nHDivs * 2) - drc.Height / 2)

e.Graphics.Draw Image(_imageB, drc, src, GraphicsUnit.Pi xel)

Next y

End Select

If _currentPercent age = 100 Then

_running = False

If Not (t Is Nothing) Then

t.Dispose()

End If

t = Nothing

End If

MyBase.OnPaint( e)

End Sub 'OnPaint

End Class 'ImageTransitio nControl

End Namespace 'WellFormed
-------------------------------------------------------------------------- -- ------------------


"rut" <ru*@discussion s.microsoft.com > wrote in message
news:20******** *************** ***********@mic rosoft.com...
If I have a picturebox with a background image and I want to

1. Display text atop of the background and
2. Have transistions between text; ie, when the text changes, the screen

can
fade out/in or have a windowblind type transition,etc.

How do you create transitions in a picture box in conjunction with
displaying text?

(Using vb.net.


Nov 21 '05 #10

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

Similar topics

1
2588
by: Simone Winkler | last post by:
Hello, I don't know if my question is out of topic...so I apologize if I am. I use the coppermine picture gallery for my web (actually I want to use it but the server doesn't seem to have GD running but I will beg them to activate it). How can I actually find out if GD is installed? I tried to use phpinfo() and I searched for a GD entry, but no one was there, so can I be sure, that GD isn't installed? (Because the admins of the...
10
9509
by: Chris Coho, Jr. | last post by:
Ok, I'll explain the whole problem because there may be several ways to solve this and hopefully someone knows one. What I'm doing is creating a specialty template editor, similar to say a corel draw (but for specific uses). What I need to be able to do is import graphics and text and then move them around the background until they are where I want them and then export it out as an image file. The problem is that I need to be able to...
4
2184
by: DraguVaso | last post by:
Hi, In my application I receive a Byte Stream (Dim bytFile() As Byte) which contains a jpeg-picture, which I want to display in a picturebox. I want to display it directly from the bytfile() without first writing it to a file and than reading it. Does anybody knows how to do this?
6
9482
by: John Ortt | last post by:
Hi there everyone, I have a part info form which has a faded image of our company logo as a background. I want to replace the faded image with a bright red warning image on items which have run out of purchasing cover. I am nearly there, the only problem is that the code below only changes the image background for text and combo-box backgrounds, it doesn't apply it to the whole form.
4
2971
by: Andre Nogueira | last post by:
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...
2
2474
by: zheng | last post by:
ÇçÌì I have a word document and it has a picture object, I want save the picture object as other single picture file by C# program. I have a idea, by clipboard, copy the picture to clipboard, and then save as a file from clipboard, it is work well in application,but don't work in a web application. how can I to do? and are there other ideas to save the picture object in web application? help me !!
14
5576
by: hamil | last post by:
I am trying to display an image in a picture box. The image is a group 4 fax black and white image of a piece of sheet music. The original resolution is 300 X 300 dpi. I want to have the picture box as large as possible so I can view the scanned image on my computer screen. At run time, I want to be able to view different files by changing the image file name property. I thought the picture box could be setup so that the image would be...
17
12070
by: merrily | last post by:
Read in one forum the question someone asked after successfully (sort of) installing Picture It 2000 on new computer with Vista. Will this person or any other help me accomplish this install on Vista, please. I tried installing Picture It and it seemed to do so. I got no error messages but it sure took a long time. Then when I tried to open the program it said "access denied" adding that I needed 30 meg of disk space (implying I didn't)...
46
10098
by: OldBirdman | last post by:
What a mess this question is. I have spent 2 weeks trying to make it concise and clear, and I can't. I do not have the vocabulary for the question. I cannot even TITLE it correctly. Here is my best effort. Conditions: 80,000+ pictures (These are pictures of birds, ID by Species, Sex, Age, etc. (If known)) Hierarchy of folders: Continent->Country->State(if India, Mexico, USA, Canada, & Australia) (No state for other countries) I am...
8
2255
by: Jonathan Sachs | last post by:
I'm trying to compose a list of items, each of which consists of text that wraps around a picture at the left margin. The examples I have seen tell me to do it like this: <p><img src="xxxx.jpg" align="left" width=nn height=nn>zzz zzzzz zz zzzzz...</p> In my case, since the wrapped text includes a headline, I assume I am supposed to do this:
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10211
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8870
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7408
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3958
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3561
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.