GDI wrapping problems

DamnedGDI

New member
Joined
Aug 26, 2011
Messages
2
Programming Experience
10+
Hi.

Before I started using GDI+ I normally would code traditional GDI and I had the same problem in both GDI as well as GDI+. I am trying to fill a rectangle at the very bottom of the window, all the way at the bottom, a section there. The problem is that the rectangle gets wrapped and messed up, it almost seems like it have been drawed just a little bit outside boundaries. 60 percent of the filling gets wrapped down below the remaining 40%. I don't recall how I solved it using GDI, I think I used a function called SetBrushOrgEx to align the drawing first, then it worked (If I recall correctly, I may not recall correctly)

It happens when I fill rectangles, it happens when I draw bitmaps and it also happens when I fill gradient rectangles. Do I need to align something anywhere before drawing?

How can I solve this in GDI+ ?

To show you what I mean, look at this rather funny painting I made:

TZS5V.png
 
I am not at home right now, I cannot provide source code now, but I guarantee you it is not much source code to look at, we're talking somethig extremely tiny and simple. It would be more effective if you could post the two or three lines of code that is neccesary to do a successful rectangle-fill at the bottom of the screen, dont you think :nonchalance:

I had the exact same problem with GDI earlier and I actually solved it, I just can't remember exactly what I did to solve it, apparently the problem is transferrable to GDI+ as well.
 
I asked for your code because I cannot reproduce your problem.
Following code will draw a rectangle of 60 pixels high at the bottom of the form:

     Private Sub RectangleAtBottomOfForm()
        Using canvas = CreateGraphics()
            canvas.FillRectangle(
            Brushes.LimeGreen, 0, ClientSize.Height - 60, ClientSize.Width, 60)
        End Using
    End Sub



And this will draw an image at the bottom of the screen (image will be scaled):


    Private Sub BitMapAtBottom(ByVal image As Image)
        Dim scalingFactor As Single = Convert.ToSingle(ClientSize.Width / image.Width)
        Dim height As Single = image.Height * scalingFactor
        Dim rect As New RectangleF(0, ClientSize.Height - height, ClientSize.Width, height)
        Using canvas = CreateGraphics()
            canvas.DrawImage(image, rect)
        End Using
    End Sub

 
Back
Top