Can't draw in screen open event

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
kenko
Posts: 1
Joined: Fri Oct 24, 2014 3:00 am

Can't draw in screen open event

Post 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

opn
Posts: 1
Joined: Fri Mar 10, 2017 2:45 am

Re: Can't draw in screen open event

Post 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(); "

Post Reply