473,834 Members | 1,882 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Collecti ons;
using System.Componen tModel;
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.Componen tModel.Containe r components = null;
UserControl1 uc;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeCompo nent();

//
// TODO: Add any constructor code after InitializeCompo nent call
//

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

this.SizeChange d += new EventHandler(On SizeChanged);
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
//
// Form1
//
this.AutoScaleB aseSize = new System.Drawing. Size(5, 13);
this.ClientSize = new System.Drawing. Size(292, 266);
this.Name = "Form1";
this.Text = "Form1";
this.WindowStat e = System.Windows. Forms.FormWindo wState.Maximize d;
}
#endregion

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

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

UserControl1.cs
------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Windows. Forms;
using System.Runtime. InteropServices ;

namespace transparant
{
public class UserControl1 : System.Windows. Forms.UserContr ol
{
private System.Componen tModel.Containe r components = null;
private Form3 frm;
public UserControl1()
{
// This call is required by the Windows.Forms Form Designer.
InitializeCompo nent();

// 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.Disp ose();
}
}
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 InitializeCompo nent()
{
//
// UserControl1
//
this.Name = "UserContro l1";
this.Size = new System.Drawing. Size(568, 360);
this.Click += new System.EventHan dler(this.UserC ontrol1_Click);

}
#endregion

protected override void OnPaint(PaintEv entArgs e)
{
//Image you can draw any bmp image.
Bitmap bmp = new Bitmap("C:\\med ical.bmp");
e.Graphics.Draw Image(bmp, 0, 0, this.Width, this.Height);
}
private void UserControl1_Cl ick(object sender, System.EventArg s e)
{
frm.Show();
}

}

Form3.cs
----------
using System;
using System.Drawing;
using System.Collecti ons;
using System.Componen tModel;
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.Componen tModel.Containe r components = null;

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

this.FormBorder Style = FormBorderStyle .None;
this.SizeChange d += new EventHandler(On SizeChanged);
CreatePicBox();

CreateChart();

this.BackColor = Color.Black;
this.Transparen cyKey = Color.Black;
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Disp ose();
}
}
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 InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
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.BackColo r = Color.Red;
picBox.MouseDow n += new MouseEventHandl er(OnMouseDown) ;
picBox.MouseMov e += new MouseEventHandl er(OnMouseMove) ;
picBox.MouseUp += new MouseEventHandl er(OnMouseUp);
picBox.Cursor = Cursors.SizeNWS E;
this.Controls.A dd(picBox);
}

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

}

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

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

this.Refresh();
}

}

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

}

private void OnSizeChanged(o bject sender, EventArgs args)
{
picBox.Location = new Point(Size.Widt h - 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(uc 2);
}

}
}

USerControl2.cs
-------------------
using System;
using System.Collecti ons;
using System.Componen tModel;
using System.Drawing;
using System.Data;
using System.Windows. Forms;

namespace transparant
{

/// <summary>
/// Summary description for UserControl2.
/// </summary>
public class UserControl2 : System.Windows. Forms.UserContr ol
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.Componen tModel.Containe r components = null;

public Image img;

public UserControl2()
{
// This call is required by the Windows.Forms Form Designer.
InitializeCompo nent();
// 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.Disp ose();
}
}
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 InitializeCompo nent()
{
//
// UserControl2
//
this.Name = "UserContro l2";
this.Size = new System.Drawing. Size(440, 320);

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

Pen pen = new Pen(Color.Yello w, 2);

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

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

}
}

Nov 16 '05 #1
2 8318
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 InitializeCompo nent() :

this.Background Image = new Bitmap("C:\\ima ge.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******@discu ssions.microsof t.com> wrote in message news:<66******* *************** ************@mi crosoft.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
1557
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 to be tranparent for the entire UserControl. I've set the UserControl's backstyle 0-transparent, but I got transparent regions displayd in gray! There is a solution?
7
31143
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 control on another form. All I want to see is the drawing and I want anything behind the drawing to show through. TransparencyKey and Opacity don't compile.
8
3200
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 when the control is painted or resized. When the control is drawn it draws also the items found in the collection. So far so good.... I have 3 questions which I'm unable to find a solution
8
10614
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 some controls that aren't rectangular and it won't be pretty if I end up with a grey rectangle behind each one. http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskGivingYourControlTransparentBackground.asp?frame=true
0
1387
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 alpha channel transparent one that windows xp's shell uses... is there any way to just keep the standard dotted rectangle one? because performance is slow when the transparent rectangle region is enabled with double buffering... but i cant find a way...
0
1637
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 to an icon. The control does nothing except show the icon. In the main windows form, on formload event, I declare and instantiate 30 user controls and give them various locations on the main form. The Problem(s):
1
3097
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 picture box set to an icon. The UserControl constructor sets SetStyle( ControlStyles.SupportTransparentBackColor, true); this.BackColor = Color.Transparent; The control does nothing except display the icon.
8
6391
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 any feasible solution, i need to use a checked listbox which also has same flickering problem on resize. Thanks & Regards
1
3584
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 window it's placed on resizes? Jeff
0
9800
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9651
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10557
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9340
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6961
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5802
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3085
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.