CreateParams and XP - c#

I have searched it on internet and on stackoverflow as well but i haven't got any correct/reliable solution.
I want to remove flickering from one of my c# Windows Form.
So I have overriden CreateParams method in following manner
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
return cp;
}
}
This removes flicker from my Application when used in Vista, Windows 7 and 8. But in XP my controls are randomly changed. My checkboxes becomes invisible.
I have referred the stack over flow question this. But i cannnot use it as I dont have any MaximizeBox. This is happening in a used defined control !
Please suggest me a feasible solution

Related

Flickering in a Windows C# dev express

I have an Dev Express Windows Form Application and it has a massive amount of flicker, particularly on startup.
I applied this fix to it.
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return cp;
}
}
This code fix the flickering problem but it used 30-50 CPU Usages.
How to Fix this problem ?
Can you try setting DoubleBuffered = true for the Form? I am not sure it will work with DevExpress or not. You can find an MSDN topic for the same - How to: Reduce Graphics Flicker with Double Buffering for Forms and Controls
It also depends on what type of controls are on the form. DevExpress has many controls that have a .SuspendLayout() and .ResumeLayout() which prevent flickering and hang-ups while the specific control is being loaded.

Black flashbacks when resize wpf element host

I have a WPF UserControl that displayed in a Winform as Element Host.
When I change the screen size quickly or resize it I see a black flashbacks in the background until the UserControl comes to the appropriate size.
I read about it in several places.
All the places I read them talk it happens only in the UserControl Load and bring solutions accordingly.
One question I've seen talking about it happening on Resize. But the solution offered there is as well to Load.
Black background on resizing elementhost
I tried on Resize of the screen to perform the following: UserControl.CreateGraphics (); , it does not leaves black lines like the above answer said.
I guess it's because I used it in Resize and not on Load.
Besides, I could not find anything.
If anyone encountered this and found a solution I would love to answer.
We usually face flickering issues while developing windows application with forms having many controls on it. A very neat way to get rid of this flickering is double buffering the whole form and its child controls. However, this would not speed up the control painting but it will hold the screen for a while and just show the updated screen instead of flickering. To implement this we need to enable the WS_EX_COMPOSITED flag. Just add the following code to your form's code.
C#:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
// Turn on WS_EX_COMPOSITED
return cp;
}
}
VB .net:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.ExStyle = cp.ExStyle Or &H2000000
Return cp
End Get
End Property
What helped me in the end it following lines of code (in Winform):
protected override void OnResize(EventArgs e)
{
this.SuspendLayout();
base.OnResize(e);
this.ResumeLayout();
}

Controls not being drawn at the same time

I have a form which I'm bringing up using ShowDialog which contains a couple of text boxes, labels and a button. The problem I'm having is that the text boxes are being drawn before the form itself and the other controls are drawn.
I am overriding the OnPaint method I'm not sure if this could be causing the problem:
protected override void OnPaint(PaintEventArgs e)
{
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Black, ButtonBorderStyle.Solid);
base.OnPaint(e);
}
It's only a slight delay but it's visible and annoying. Thank you.
The form is double buffered by the way.
EDIT: I have pinpointed the issue to be the fact that the form does not have a FormBorderStyle. With the FormBorderStyle set to Sizable, this issue does not occur. However please note that having FormBorderStyle.None as my border style is necessary, so I have not found a solution yet.
Try adding this to the dialog box form:
protected override CreateParams CreateParams
{
get
{
// Activate double buffering at the form level. All child controls will be double buffered as well.
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return cp;
}
}

Flicker free TextBox

I have a simple Winforms multiline TextBox on my Form. Whenever I resize or move the TextBox its content starts to flicker madly. That looks very disgusting and might even cause epileptic seizure for some users ;-)
Is there a way to manipulate the redrawing process of the TextBox to get rid of the flickering?
I've found a working solution on the MSDN forums written by Hans Passant. The following code can be added to the form and will work for all child controls, too:
protected override CreateParams CreateParams {
get {
const int WS_EX_COMPOSITED = 0x02000000;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_COMPOSITED;
return cp;
}
}
afaik you can't control the resize mode of single controls on a form...
in my opinion you have 2 options:
find out why the flickering occurs - graphics driver issues?
set the ResizeRedraw property of the form to false
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.resizeredraw.aspx

Click-through in C# Form

I've created a semi-transparent form. I'd like for people to be able to click on the form area, and for form not handle the click. I'd like whatever is underneath the form to receive the click event instead.
You can do this with SetWindowLong:
int initialStyle = GetWindowLong(this.Handle, -20);
SetWindowLong(this.Handle, -20, initialStyle | 0x80000 | 0x20);
There are a few magic numbers in here:
-20 – GWL_EXSTYLE
Retrieves the extended window styles.
0x80000 – WS_EX_LAYERED
Creates a layered window.
0x20 – WS_EX_TRANSPARENT
Specifies that a window created with this style should not be painted until siblings beneath the window (that were created by the same thread) have been painted. The window appears transparent because the bits of underlying sibling windows have already been painted.
There are numerous articles all over the web on how to do this, such as this one.
The SetWindowLong in #Joey's answer can only make the form semi-transparent after showing the form on screen. If you call SetWindowLong in Form1_Load, the form will be opaque upon creation, and then quickly being changed to semi-transparent. This causes the users to see the non-semi-transparent form for a short moment upon launching the program. To prevent this, you can override CreateParams instead :
public partial class Form1 : Form
{
protected override CreateParams CreateParams
{
get
{
const int WS_EX_LAYERED = 0x80000;
const int WS_EX_TRANSPARENT = 0x20;
CreateParams cp = base.CreateParams;
cp.ExStyle |= WS_EX_LAYERED;
cp.ExStyle |= WS_EX_TRANSPARENT;
return cp;
}
}
}
The code above makes the form semi-transparent before showing the form on screen.
The solution above is similar to this post, which makes the form top-most instead.

Categories

Resources