Understanding Bridge Pattern using .NET
page 7 of 13
by David Simmonds
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 47009/ 92

Renderers

Accepts a score passed to it in the RenderRating function.  It will take that score and use its own technique to render that score into a graphical image equivalent to the score.  When the end-user clicks on each group box (which contains a picture box) it creates a graphical image.

Listing 2

' Equivalent to Implementation in the Bridge pattern
Public MustInherit Class RatingRenderer
  Protected RatingPictureBox As PictureBox
  Protected RenderableImagesList As ImageList
  Protected RenderingGraphics As Graphics
  Public Sub New(ByVal RatingPicture As PictureBox, ByVal 
                                 ImageListToUse As ImageList)
    RatingPictureBox = RatingPicture
    RenderableImagesList = ImageListToUse
  End Sub
  Public Function ClearGraphicSurface()
    RenderingGraphics = RatingPictureBox.CreateGraphics
    RenderingGraphics.Clear(Color.FromKwnClr(KnownClr.Control))
  End Function
  ' Equivalent to Implement in the Bridge pattern
  Public MustOverride Function RenderRating(ByVal ScoreToRender 
                                                   As Integer)
End Class
' Equivalent to Concrete Implementation in the Bridge pattern
Public Class FaceRenderer               
       Inherits RatingRenderer
 
  Public Sub New(ByVal RatingPicture As PictureBox, ByVal 
                               ImageListToUse As ImageList)
      MyBase.New(RatingPicture, ImageListToUse)
  End Sub
  Public Overrides Function RenderRating(ByVal ScoreToRender As
                                                  Integer)
    ' Equivalent to Implement in the Bridge pattern
    ClearGraphicSurface()
    Dim GraphicWidth As Integer = 25
    Dim GraphicHeight As Integer = 25
    If ScoreToRender <> 0 Then
       RenderableImagesList.Draw(RenderingGraphics, 50, 0,
                GraphicWidth, GraphicHeight, ScoreToRender - 1)
    End If
  End Function
End Class

View Entire Article

User Comments

No comments posted yet.

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-13 11:11:02 AM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search