none
c # red x Rendering a Windows Forms control RRS feed

  • Pergunta

  • Aleatoriamente quando tentamos retornar de uma tela de processamento para outra tela que é o menu principal da aplicação, a qual é desenhada através de controles interno do C# em tempo de execução (os quais foram customizados) um ou mais “X vermelho” aparecem na tela, seguidos por uma exceção de estouro de memória:

    ************** Texto de Exceção ************** System.OutOfMemoryException: Memória insuficiente.    em System.Drawing.Graphics.CheckErrorStatus(Int32 status)    em System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs, DrawImageAbort callback, IntPtr callbackData)    em System.Drawing.Graphics.DrawImage(Image image, Rectangle destRect, Int32 srcX, Int32 srcY, Int32 srcWidth, Int32 srcHeight, GraphicsUnit srcUnit)    em System.Windows.Forms.ControlPaint.DrawBackgroundImage(Graphics g, Image backgroundImage, Color backColor, ImageLayout backgroundImageLayout, Rectangle bounds, Rectangle clipRect, Point scrollOffset, RightToLeft rightToLeft)    em System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle, Color backColor, Point scrollOffset)    em System.Windows.Forms.Control.PaintBackground(PaintEventArgs e, Rectangle rectangle)    em System.Windows.Forms.Control.OnPaintBackground(PaintEventArgs pevent)    em System.Windows.Forms.ScrollableControl.OnPaintBackground(PaintEventArgs e)    em System.Windows.Forms.Control.PaintWithErrorHandling(PaintEventArgs e, Int16 layer)    em System.Windows.Forms.Control.WmPaint(Message& m)    em System.Windows.Forms.Control.WndProc(Message& m)    em System.Windows.Forms.ScrollableControl.WndProc(Message& m)    em System.Windows.Forms.Form.WndProc(Message& m)    em System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    em System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    em System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

    A linha de origem da exceção aponta ou para o formulário Designer ou na função InitializeComponent (que são geradas pelo Visual Studio). Tentamos forçar a aplicação a dar esse erro, navegando pelos menus mais rapidamente do que o próprio usuário faria, mas o erro acontece totalmente de forma aleatória, sem podermos identificar passos que o façam reproduzir.

    A causa raiz da exceção sempre aponta para o construtor do formulário e para a inicialização do componente.

    ENVIRONMENT: Windows Forms Application. C#. Visual Studio 2017. .Net Framework 4.8. Windows 10.

    namespace _TESOUREIROAPP.Views.Base

    Fonte principal:

    namespace _TESOUREIROAPP.Views.Base

    {

        partial class FrmBaseAPP

        {

            /// <summary>

            /// Required designer variable.

            /// </summary>

            private System.ComponentModel.IContainer components = null;

            /// <summary>

            /// Clean up any resources being used.

            /// </summary>

            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

            protected override void Dispose(bool disposing)

            {

                if (disposing && (components != null))

                {

                    components.Dispose();

                }

                base.Dispose(disposing);

            }

            #region Windows Form Designer generated code

            /// <summary>

            /// Required method for Designer support - do not modify

            /// the contents of this method with the code editor.

            /// </summary>

            private void InitializeComponent()

            {

                this.components = new System.ComponentModel.Container();

                this.timerHorario = new System.Windows.Forms.Timer(this.components);

                this.picGear = new System.Windows.Forms.PictureBox();

                this.lblUsuario = new System.Windows.Forms.Label();

                this.lblDataHora = new System.Windows.Forms.Label();

                this.lblClienteEData = new System.Windows.Forms.Label();

                this.lblAtmVersion = new System.Windows.Forms.Label();

                this.picBarrinha = new System.Windows.Forms.PictureBox();

                this.lblInstrucao = new System.Windows.Forms.Label();

                ((System.ComponentModel.ISupportInitialize)(this.picGear)).BeginInit();

                ((System.ComponentModel.ISupportInitialize)(this.picBarrinha)).BeginInit();

                this.SuspendLayout();

                //

                // timerHorario

                //

                this.timerHorario.Enabled = true;

                this.timerHorario.Interval = 30000;

                this.timerHorario.Tick += new System.EventHandler(this.timerHorario_Tick);

                //

                // picGear

                //

                this.picGear.BackColor = System.Drawing.Color.Transparent;

                this.picGear.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;

                this.picGear.Image = global::_TESOUREIROAPP.Properties.Resources.blue_loading_gif_transparent;

                this.picGear.Location = new System.Drawing.Point(496, 368);

                this.picGear.Name = "picGear";

                this.picGear.Size = new System.Drawing.Size(31, 31);

                this.picGear.TabIndex = 84;

                this.picGear.TabStop = false;

                this.picGear.Visible = false;

                //

                // lblUsuario

                //

                this.lblUsuario.BackColor = System.Drawing.Color.Transparent;

                this.lblUsuario.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                this.lblUsuario.ForeColor = System.Drawing.Color.Transparent;

                this.lblUsuario.Location = new System.Drawing.Point(842, 735);

                this.lblUsuario.Name = "lblUsuario";

                this.lblUsuario.Size = new System.Drawing.Size(170, 23);

                this.lblUsuario.TabIndex = 73;

                this.lblUsuario.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;

                //

                // lblDataHora

                //

                this.lblDataHora.BackColor = System.Drawing.Color.White;

                this.lblDataHora.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                this.lblDataHora.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(95)))), ((int)(((byte)(179)))));

                this.lblDataHora.Location = new System.Drawing.Point(917, 21);

                this.lblDataHora.Name = "lblDataHora";

                this.lblDataHora.Size = new System.Drawing.Size(95, 45);

                this.lblDataHora.TabIndex = 19;

                this.lblDataHora.Text = "HH:MM:SS";

                this.lblDataHora.TextAlign = System.Drawing.ContentAlignment.BottomLeft;

                //

                // lblClienteEData

                //

                this.lblClienteEData.BackColor = System.Drawing.Color.White;

                this.lblClienteEData.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                this.lblClienteEData.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(110)))), ((int)(((byte)(110)))));

                this.lblClienteEData.Location = new System.Drawing.Point(376, 14);

                this.lblClienteEData.Name = "lblClienteEData";

                this.lblClienteEData.Size = new System.Drawing.Size(524, 28);

                this.lblClienteEData.TabIndex = 85;

                this.lblClienteEData.Text = "Nome do Cliente, Dia da semana, dia do mês ano.";

                this.lblClienteEData.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

                //

                // lblAtmVersion

                //

                this.lblAtmVersion.BackColor = System.Drawing.Color.Transparent;

                this.lblAtmVersion.Font = new System.Drawing.Font("Microsoft Sans Serif", 9.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));

                this.lblAtmVersion.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(110)))), ((int)(((byte)(110)))), ((int)(((byte)(110)))));

                this.lblAtmVersion.Location = new System.Drawing.Point(376, 48);

                this.lblAtmVersion.Name = "lblAtmVersion";

                this.lblAtmVersion.Size = new System.Drawing.Size(524, 23);

                this.lblAtmVersion.TabIndex = 86;

                this.lblAtmVersion.Text = "Equipamento XXXX    VERSÃO x.x.x.x.xx";

                this.lblAtmVersion.TextAlign = System.Drawing.ContentAlignment.MiddleRight;

                //

                // picBarrinha

                //

                this.picBarrinha.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(95)))), ((int)(((byte)(179)))));

                this.picBarrinha.Location = new System.Drawing.Point(908, 21);

                this.picBarrinha.Name = "picBarrinha";

                this.picBarrinha.Size = new System.Drawing.Size(2, 50);

                this.picBarrinha.TabIndex = 88;

                this.picBarrinha.TabStop = false;

                //

                // lblInstrucao

                //

                this.lblInstrucao.AutoSize = true;

                this.lblInstrucao.Location = new System.Drawing.Point(374, 115);

                this.lblInstrucao.Name = "lblInstrucao";

                this.lblInstrucao.Size = new System.Drawing.Size(177, 13);

                this.lblInstrucao.TabIndex = 89;

                this.lblInstrucao.Text = "label que vai substituir o lblInstrucao";

                this.lblInstrucao.Visible = false;

                //

                // FrmBaseAPP

                //

                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

                this.BackColor = System.Drawing.Color.White;

                this.BackgroundImage = global::_TESOUREIROAPP.Properties.Resources.Perto_Cash_21;

                this.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;

                this.ClientSize = new System.Drawing.Size(1024, 768);

                this.Controls.Add(this.lblInstrucao);

                this.Controls.Add(this.lblClienteEData);

                this.Controls.Add(this.picBarrinha);

                this.Controls.Add(this.lblAtmVersion);

                this.Controls.Add(this.lblDataHora);

                this.Controls.Add(this.picGear);

                this.Controls.Add(this.lblUsuario);

                this.DoubleBuffered = true;

                this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;

                this.Name = "FrmBaseAPP";

                this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;

                this.Text = "frmBaseOp";

                this.TopMost = true;

                this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frmBaseOp_FormClosing);

                this.Load += new System.EventHandler(this.FrmBaseAPP_Load);

                this.Shown += new System.EventHandler(this.frmBaseOp_Shown);

                this.Click += new System.EventHandler(this.FrmBaseAPP_Click);

                ((System.ComponentModel.ISupportInitialize)(this.picGear)).EndInit();

                ((System.ComponentModel.ISupportInitialize)(this.picBarrinha)).EndInit();

                this.ResumeLayout(false);

                this.PerformLayout();

            }

            #endregion

            private System.Windows.Forms.Timer timerHorario;

            private System.Windows.Forms.Label lblUsuario;

            public System.Windows.Forms.PictureBox picGear;

            private System.Windows.Forms.Label lblDataHora;

            private System.Windows.Forms.Label lblClienteEData;

            private System.Windows.Forms.Label lblAtmVersion;

            private System.Windows.Forms.PictureBox picBarrinha;

            protected System.Windows.Forms.Label lblInstrucao;

        }

    }


    • Editado Kelly Pinho sexta-feira, 7 de agosto de 2020 19:05
    sexta-feira, 7 de agosto de 2020 18:27