Skip to content

An exception occurred when adding an image to the BackgroundImage property  #3309

@Jessie-Zhang01

Description

@Jessie-Zhang01
  • .NET Core Version: .Net Core 5.0.100-preview.6.20269.24

  • Have you experienced this same bug with .NET Framework?:
    No

More Info:

  1. This issue cannot reproduce when adding pictures from the property window.
  2. This issue just reproduce when the BackgroundImageLayout property to Tile.
  3. This issue also can reproduce on .Net 3.1 and .Net 3.0.

Minimal repro:

  1. Create a winforms core project.
  2. Add a PropertyGrid and a Button in the Form designer, then bind button to propertygrid.
  3. Build and run this project.
  4. Set the BackgroundImageLayout property to Tile.
  5. Add an image to the BackgroundImage property.
    WindowsFormsApp5.zip

Expected behavior:
Picture added successfully.

Actual behavior:
An exception occurred when adding an image to the BackgroundImage property.
image

System.OutOfMemoryException
  HResult=0x8007000E
  Message=Out of memory.
  Source=System.Drawing.Common
  StackTrace:
   at System.Drawing.TextureBrush..ctor(Image image, WrapMode wrapMode) in /_/src/libraries/System.Drawing.Common/src/System/Drawing/TextureBrush.cs:line 42
   at System.Windows.Forms.ControlPaint.DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ControlPaint.cs:line 496
   at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintThemedButtonBackground(PaintEventArgs e, Rectangle bounds, Boolean up) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonStandardAdapter.cs:line 139
   at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintWorker(PaintEventArgs e, Boolean up, CheckState state) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonStandardAdapter.cs:line 247
   at System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintUp(PaintEventArgs e, CheckState state) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonStandardAdapter.cs:line 49
   at System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.Paint(PaintEventArgs pevent) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ButtonInternal/ButtonBaseAdapter.cs:line 55
   at System.Windows.Forms.ButtonBase.OnPaint(PaintEventArgs pevent) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs:line 1139
   at System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs:line 8784
   at System.Windows.Forms.Control.WmPaint(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs:line 12538
   at System.Windows.Forms.Control.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs:line 12949
   at System.Windows.Forms.ButtonBase.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/ButtonBase.cs:line 1310
   at System.Windows.Forms.Button.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Button.cs:line 389
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) in /_/src/System.Windows.Forms/src/System/Windows/Forms/Control.ControlNativeWindow.cs:line 120
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam) in /_/src/System.Windows.Forms/src/System/Windows/Forms/NativeWindow.cs:line 372
 
  This exception was originally thrown at this call stack:
    System.Drawing.TextureBrush.TextureBrush(System.Drawing.Image, System.Drawing.Drawing2D.WrapMode) in TextureBrush.cs
    System.Windows.Forms.ControlPaint.DrawBackgroundImage(System.Drawing.Graphics, System.Drawing.Image, System.Drawing.Color, System.Windows.Forms.ImageLayout, System.Drawing.Rectangle, System.Drawing.Rectangle, System.Drawing.Point, System.Windows.Forms.RightToLeft) in ControlPaint.cs
    System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintThemedButtonBackground(System.Windows.Forms.PaintEventArgs, System.Drawing.Rectangle, bool) in ButtonStandardAdapter.cs
    System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintWorker(System.Windows.Forms.PaintEventArgs, bool, System.Windows.Forms.CheckState) in ButtonStandardAdapter.cs
    System.Windows.Forms.ButtonInternal.ButtonStandardAdapter.PaintUp(System.Windows.Forms.PaintEventArgs, System.Windows.Forms.CheckState) in ButtonStandardAdapter.cs
    System.Windows.Forms.ButtonInternal.ButtonBaseAdapter.Paint(System.Windows.Forms.PaintEventArgs) in ButtonBaseAdapter.cs
    System.Windows.Forms.ButtonBase.OnPaint(System.Windows.Forms.PaintEventArgs) in ButtonBase.cs
    System.Windows.Forms.Control.PaintWithErrorHandling(System.Windows.Forms.PaintEventArgs, short) in Control.cs
    System.Windows.Forms.Control.WmPaint(ref System.Windows.Forms.Message) in Control.cs
    System.Windows.Forms.Control.WndProc(ref System.Windows.Forms.Message) in Control.cs
    ...
    [Call Stack Truncated]

Metadata

Metadata

Assignees

Labels

🪲 bugProduct bug (most likely)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions