Page 1 of 1

Can't draw in screen open event

Posted: Thu Oct 30, 2014 11:00 pm
by kenko
I use DrawTest() to draw two rectangles on screen, they can't be displayed when using Screen1_Opened(), but it can in Button_Click().

here is the source code,

namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;


public partial class Screen1
{
void DrawTest()
{
System.Drawing.Pen myPen, myPen1;
myPen = new System.Drawing.Pen(System.Drawing.Color.Red);
myPen1 = new System.Drawing.Pen(System.Drawing.Color.Green, 2);
Graphics formGraphics = this.CreateGraphics();
formGraphics.DrawRectangle(myPen, 52, 52,40, 50);
formGraphics.DrawRectangle(myPen1,50,50,100,150);
myPen.Dispose();
myPen1.Dispose();

formGraphics.Dispose();
}

void Screen1_Opened(System.Object sender, System.EventArgs e)
{
DrawTest();
}

void Button_Click(System.Object sender, System.EventArgs e)
{
DrawTest();
}
}
}

Does someone know how it is?

Thanks.
kenko

Re: Can't draw in screen open event

Posted: Fri Mar 10, 2017 2:54 am
by opn
The screen is refreshed just after the Screen_Opened event. causing the form to be cleared. So whatever You maually place on the screen with this event will be cleared. You can see the same behaviour if you implement this code, in your button script, just after drawing. "this.Refresh(); "