473,378 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Transparent UserControl Flickers when Form get resized

Hi,

1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image.
2) In the UserControl1 i am showing one transparent form (form3) when ever user preseed left mouse button.
3) The form3 has one transparent user control (usercontrol2) that paints circles. That measn the circles will show on top the usercontrol1 image.
4) The form3 border style is none. So to resize the form, programaticlly i am resizing the form.
5) I have created one PictureBox (picBox) right bottom of the form3. Using this picture box user can resize the form3.
6) When resizing the form3, the controls on the form3 flikkers.

Can you please tell me what could be the problem. I have listed the full code, can you please see my code and give me solution.

This iam struggling for three foure days.. please reply the solution.

Form1.cs
-----------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace transparant
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
UserControl1 uc;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

//
// TODO: Add any constructor code after InitializeComponent call
//

uc = new UserControl1();
uc.Location = this.Location;
uc.Size = this.Size;
this.Controls.Add(uc);

this.SizeChanged += new EventHandler(OnSizeChanged);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (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()
{
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}
#endregion

/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}

private void OnSizeChanged(object sender, EventArgs args)
{
uc.Size = this.Size;
}
}
}

UserControl1.cs
------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace transparant
{
public class UserControl1 : System.Windows.Forms.UserControl
{
private System.ComponentModel.Container components = null;
private Form3 frm;
public UserControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();

// TODO: Add any initialization after the InitForm call

frm = new Form3();
frm.Location = new Point(200,200);
frm.Size = new Size(400,400);
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component 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()
{
//
// UserControl1
//
this.Name = "UserControl1";
this.Size = new System.Drawing.Size(568, 360);
this.Click += new System.EventHandler(this.UserControl1_Click);

}
#endregion

protected override void OnPaint(PaintEventArgs e)
{
//Image you can draw any bmp image.
Bitmap bmp = new Bitmap("C:\\medical.bmp");
e.Graphics.DrawImage(bmp, 0, 0, this.Width, this.Height);
}
private void UserControl1_Click(object sender, System.EventArgs e)
{
frm.Show();
}

}

Form3.cs
----------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace transparant
{
/// <summary>
/// Summary description for Form3.
/// </summary>
public class Form3 : System.Windows.Forms.Form
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

private PictureBox picBox;
private bool bDrag = false;
private Point prevPoint;
private Chart chart;
public Form3()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

this.FormBorderStyle = FormBorderStyle.None;
this.SizeChanged += new EventHandler(OnSizeChanged);
CreatePicBox();

CreateChart();

this.BackColor = Color.Black;
this.TransparencyKey = Color.Black;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(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.Size = new System.Drawing.Size(300,300);
this.Text = "Form3";
}
#endregion

private void CreatePicBox()
{
picBox = new PictureBox();
picBox.Size = new Size(10,10);
picBox.BackColor = Color.Red;
picBox.MouseDown += new MouseEventHandler(OnMouseDown);
picBox.MouseMove += new MouseEventHandler(OnMouseMove);
picBox.MouseUp += new MouseEventHandler(OnMouseUp);
picBox.Cursor = Cursors.SizeNWSE;
this.Controls.Add(picBox);
}

private void OnMouseDown(object sender, MouseEventArgs args)
{
picBox.Capture = true;
bDrag = true;
prevPoint = new Point(args.X, args.Y);

}

private void OnMouseMove(object sender, MouseEventArgs args)
{
Point pt = new Point(args.X, args.Y);

if (bDrag)
{
this.Cursor = Cursors.SizeNWSE;
int width = this.Size.Width;
int height = this.Size.Height;
width += (args.X - prevPoint.X);
height += (args.Y - prevPoint.Y);
this.Size = new Size(width, height);

this.Refresh();
}

}

private void OnMouseUp(object sender, MouseEventArgs args)
{
bDrag = false;
picBox.Capture = false;

}

private void OnSizeChanged(object sender, EventArgs args)
{
picBox.Location = new Point(Size.Width - 10, Size.Height - 10);
uc2.Size = new Size(Size.Width, Size.Height - 50);
}

UserControl uc2;
private void CreateChart()
{
uc2 = new UserControl2();
uc2.Location = this.Location;
Controls.Add(uc2);
}

}
}

USerControl2.cs
-------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Windows.Forms;

namespace transparant
{

/// <summary>
/// Summary description for UserControl2.
/// </summary>
public class UserControl2 : System.Windows.Forms.UserControl
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;

public Image img;

public UserControl2()
{
// This call is required by the Windows.Forms Form Designer.
InitializeComponent();
// TODO: Add any initialization after the InitForm call

}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}

#region Component 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()
{
//
// UserControl2
//
this.Name = "UserControl2";
this.Size = new System.Drawing.Size(440, 320);

}
#endregion
protected override void OnPaint(PaintEventArgs e)
{
int x = 210;
int y = 160;
int width = 30;
int height = 30;

Pen pen = new Pen(Color.Yellow, 2);

//Brush brush = new SolidBrush(Color.FromArgb(60, Color.Red));
//e.Graphics.FillRectangle(brush, 0, 0, this.Width, this.Height);

for(int i = 0; i < 5; i++)
{
e.Graphics.DrawEllipse(pen, x, y, width, height);
x -= 30;
y -= 30;
width += 60;
height += 60;
}
}

}
}

Nov 16 '05 #1
2 8281
Actually i have shown you the overall scenario of my project.
Like you said i can create a memory bitmap and draw it in UserControl1. But the problem is in my project the
userControl1 will be Third party control, whcih is developed in unmanaged code, Thay are drawing images in their
usercontrol, On top of that i have to show my transparent form.

So creating memory bitmap and drawing in userControl1 is now ruled out.

Can you please suggest me, is there any possiblity to do in Form3 and userControl2.

"pindlebot" wrote:
You probably don't want to be reopening and reading in the bmp in OnPaint in UserControl1, that will slow it down. When you resize a window it will need to paint the window again (infact even as you drag it bigger it will repaint may times as you go). It might be a performance issue.

You could also try painting the circles onto an offscreen bitmap and then drawing it to the screen in one go, that might be faster. Just remember not to create the bitmaps in OnPaint

//in constructor

//allocate memory for bitmaps

//draw vectors to bitmap
//in OnPaint

//display bitmap

Nov 16 '05 #2
Hi Jaikumar.

You're handling way too many repaints here.

1) In UserControl1.cs, remove everything in the OnPaint handler, and
add this line in the constructor, after InitializeComponent() :

this.BackgroundImage = new Bitmap("C:\\image.bmp");

2) Change the logic of UserControl2 so that when created, it creates
an image in memory with the chart; put a picturebox on UserControl2,
and specify its background image as the image you've just created.
Don't handle any OnPaint events there, let the framework do it for
you.

That should do the trick.

Michel

"Jaikumar" <Ja******@discussions.microsoft.com> wrote in message news:<66**********************************@microso ft.com>...
Hi,

1) I have created one windows application, In the main form ( form1) i have added one usercontrol (usercontrol1), In that user control i am drawing one image.
2) In the UserControl1 i am showing one transparent form (form3) when ever user preseed left mouse button.
3) The form3 has one transparent user control (usercontrol2) that paints circles. That measn the circles will show on top the usercontrol1 image.
4) The form3 border style is none. So to resize the form, programaticlly i am resizing the form.
5) I have created one PictureBox (picBox) right bottom of the form3. Using this picture box user can resize the form3.
6) When resizing the form3, the controls on the form3 flikkers.

Can you please tell me what could be the problem. I have listed the full code, can you please see my code and give me solution.

This iam struggling for three foure days.. please reply the solution.

Nov 16 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: jojo | last post by:
I' d like to develop an active x UserControl, using VB6, with transparent background. The user control will contains an image control. When load GIF image with transparent parts I want that parts ...
7
by: Chuck | last post by:
I am working in C# 2003. Can anyone tell me how to make a user control transparent. VS help doesn't help. What I want to do is draw on a user control during design time and then place the...
8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
8
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making...
0
by: Brian Henry | last post by:
I am trying to do a owner drawn list view in detail mode, when i inherited the list view into a new custom control then turned on double buffering all the sudden the selection rectangle is the...
0
by: FredC | last post by:
I'm using VS C#.Net 2003. I built a simple windows form app. with the following attributes: - has a BackgroundImage set to a jpeg I built a very simple user control that contains a picture box set...
1
by: FredC | last post by:
I'm using VS 2003, C#.Net 2003. I built a simple windows form app. with the following attributes: - has a BackgroundImage set to a jpeg I built a very simple user control that contains a...
8
by: nirdeshonline | last post by:
Hi, I have added a simple listbox in windows form under c# 2.0. It contains a collection of approx 10 strings as list items. Now when i resize the form whole listbox flickers. Please tell me...
1
by: Jeff | last post by:
..NET 2.0 I've added a custom UserControl onto a form. When I resize the form the UserControl doesn't resize. What property do I need to set on the UserControl so it automatically resizes if the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.