Results 1 to 9 of 9

Thread: [RESOLVED] How to set draw rectangle backstyle to opaque

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Resolved [RESOLVED] How to set draw rectangle backstyle to opaque

    The following code successfully creates a rectangle to be printed. The problem is that I need that rectangle to be opaque, but the created on is not. I have been trying to set the rectangle backstyle to opaque, with no success at all.

    I need some help to get it opaque.

    Thank you so much

    Nelson Calabria

    HTML Code:
    Dim AmortizableLblRect As New Rectangle
    Dim myPen As Drawing.Pen
    Dim drawBrush As New SolidBrush(Color.White)
    
    CurrentX = CantidadLblRect.Right + ancho + 3
    CurrentY = ConceptoTxtRect.Bottom + 5
    AmortizableLblRect = New Rectangle(CurrentX, CurrentY, AmortizableLblRect.Width, AmortizableLblRect.Height)
    myPen = New Drawing.Pen(Color.Black, 1)
    e.Graphics.FillRectangle(drawBrush, AmortizableLblRect)
    e.Graphics.DrawRectangle(myPen, AmortizableLblRect)

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to set draw rectangle backstyle to opaque

    remove...

    Code:
    e.Graphics.FillRectangle(drawBrush, AmortizableLblRect)

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set draw rectangle backstyle to opaque

    Hello .paul.:

    Appreciate your response. I removed the sentence you said, but it did not work.

    Thanks any way.

    Nelson Calabria

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set draw rectangle backstyle to opaque

    Hello .paul.:

    Appreciate your response. I removed the sentence you said, but it did not work.

    Thanks any way.

    Nelson Calabria

  5. #5
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to set draw rectangle backstyle to opaque

    Can you post a screenshot of how it appears and explain what you want to be different?
    If you draw a rectangle, and don't fill the rectangle with a solid color, it'll show a border with the background it's drawn on showing through the rectangle...

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to set draw rectangle backstyle to opaque

    If you want a semi-transparent background, use a color with an alpha channel less than 255.

    Dim c as color = color.fromargb(50, color.white.r, color.white.g, color.white.b)

    Creates a semi transparent white color

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set draw rectangle backstyle to opaque

    Hi .paul.,

    The draw rectangle is to be printed, as I said when I posted the thread. What I am trying to get is a printout of something like a group box, i.e. a rectangle and a label on its top side.

    Nelson

  8. #8
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,481

    Re: How to set draw rectangle backstyle to opaque

    here's an example... You'll have to change the coordinates and size and text.

    Code:
    Imports System.Drawing.Printing
    
    Public Class Form1
    
        Private WithEvents pd As New PrintDocument
        Private ppd As New PrintPreviewDialog
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            ppd = New PrintPreviewDialog
            ppd.Document = pd
            ppd.WindowState = FormWindowState.Maximized
            ppd.ShowDialog()
        End Sub
    
        Private Sub pd_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pd.PrintPage
            Dim leftOfGroupbox As Integer = 50
            Dim topOfGroupbox As Integer = 50
            Dim widthOfGroupbox As Integer = 200
            Dim heightOfGroupbox As Integer = 150
            Dim groupBoxText As String = "Groupbox Text"
    
            ''this section can be repositioned and resized by changing the 5 variables above
            ''******************************************************************************
            e.Graphics.FillRectangle(New SolidBrush(SystemColors.Control), New Rectangle(leftOfGroupbox, topOfGroupbox, widthOfGroupbox, heightOfGroupbox))
            ControlPaint.DrawBorder(e.Graphics, New Rectangle(leftOfGroupbox + 10, topOfGroupbox + 10, widthOfGroupbox - 20, heightOfGroupbox - 20), Color.DarkGray, ButtonBorderStyle.Solid)
            Dim sizef As SizeF = e.Graphics.MeasureString(groupBoxText, Me.Font)
            Dim r As New Rectangle(leftOfGroupbox + 25, topOfGroupbox, CInt(sizef.Width + 5), CInt(sizef.Height + 10))
            e.Graphics.FillRectangle(New SolidBrush(SystemColors.Control), r)
            Dim sf As New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center}
            e.Graphics.DrawString(groupBoxText, Me.Font, Brushes.Black, r, sf)
            ''******************************************************************************
    
            ControlPaint.DrawCheckBox(e.Graphics, New Rectangle(70, 80, 16, 16), ButtonState.Checked)
            e.Graphics.DrawString("Is this ok?", Me.Font, Brushes.Black, 100, 80)
        End Sub
    
    End Class

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Oct 2012
    Location
    Caracas, Venezuela
    Posts
    121

    Re: How to set draw rectangle backstyle to opaque

    Hi .paul.

    That was great.

    Thank you so much.

    Nelson

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width