Error about outofmemoryexception of system. Drawing. drawing2d. lineargradientbrush

Source: Internet
Author: User

A friend in the group made the following code yesterday:

System.Drawing.Drawing2D.LinearGradientBrush brush=new System.Drawing.Drawing2D.LinearGradientBrush(new Point(1),new Point(1),Color.Red,Color.Green);

When the result is running, an outofmemoryexception occurs.

After repeated searches

The problem is found here.

Http://social.msdn.microsoft.com/Forums/en-US/Vsexpressvb/thread/6feb8768-6235-44b1-a8b0-463d23def481/

I found what was causing the error.

My function calcgradientstartstop didn't work correctly, my gstart and gstop values didn't change.
Now I changed it and it works.
The error was because gstart coordinates (0, 0) were the same as gstop coordinates (0, 0 ),
And that doesn't work well ..

But now I have another problem

I edited my filling sub like this (I'm now using global variables )..
Instead of gstart and gstop I now use global vars mgradientstart and mgradientstop:

Code block
Private Sub drawFill(ByVal e As System.Windows.Forms.PaintEventArgs)        Dim gStart As New PointF(0, 0)        Dim gStop As New PointF(0, 0)        If Me.cGradientFill Then            Me.calcGradientStartStop()            If Not (Me.mGradientStart.X = Me.mGradientStop.X) And Not (Me.mGradientStart.Y = Me.mGradientStop.Y) Then                Dim grdnt As New Drawing.Drawing2D.LinearGradientBrush(Me.mGradientStart, Me.mGradientStop, Me.mGradientColor1, Me.mGradientColor2)                e.Graphics.FillRegion(grdnt, Me.Region)            Else                MsgBox("Start and Stop Can't Have Same Value")            End If        Else            e.Graphics.FillRegion(New SolidBrush(Me.mBgColor), Me.Region)        End If    End Sub 

The problem is as follows:
Lineargradientbrush (new point (1), new point (1), color. Red, color. Green );

The points of the first two parameters of the constructor cannot be the same. Otherwise, an error is returned.

Recorded. It facilitates searching by others.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.