hi,
using show/hide of frmBitmap to display a bitmap which is imported by form1 frmBitmap only displays an empty window and I found that frmBitmap's paint event is never thrown. That's why I'm using VisibleChanged event.
frmBitmap.Show(this) is called from form1's paint-event.
can anyone give some explanation on this problem or maybe a different approach?
thanks in advance
using show/hide of frmBitmap to display a bitmap which is imported by form1 frmBitmap only displays an empty window and I found that frmBitmap's paint event is never thrown. That's why I'm using VisibleChanged event.
frmBitmap.Show(this) is called from form1's paint-event.
C#:
public partial class frmBitmap : Form
{
public frmBitmap()
{
InitializeComponent();
BitmapOrigin = new Point(0,0);
}
private void frmBitmap_Paint(object sender, PaintEventArgs e)
{
if (Bitmap == null) return;
e.Graphics.DrawImage(Bitmap, BitmapOrigin);
}
private void frmBitmap_VisibleChanged(object sender, EventArgs e)
{
switch(this.Visible) {
case true :
ParentOrigin = new Point(Owner.Left + (Owner.Width >> 1), Owner.Top + (Owner.Height >> 1));
Graphics = this.CreateGraphics();
if (Bitmap.Width != this.Width || Bitmap.Height != this.Height) {
SetPositionAndSize();
}
Graphics.DrawImage(Bitmap, BitmapOrigin);
break;
case false :
Graphics.Clear(this.BackColor);
Graphics.Dispose();
break;
}
}
private void SetPositionAndSize()
{
this.Width = Bitmap.Width;
this.Height = Bitmap.Height;
this.Left = ParentOrigin.X - (this.Width >> 1);
this.Top = ParentOrigin.Y - (this.Height >> 1);
}
internal Bitmap Bitmap { get; set; }
internal Point ParentOrigin { get; set; }
private Graphics Graphics;
private Point BitmapOrigin;
}
can anyone give some explanation on this problem or maybe a different approach?
thanks in advance
Last edited by a moderator: