How can I fix form suddenly hides and shows again
Here is what cause the issue
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
cp.Style &= ~0x02000000; // Turn off WS_CLIPCHILDREN
return cp;
}
}
I use this line of code so that form with background image loads faster and remove flickering issuer
Refer Following Code:
private const int CP_NOCLOSE_BUTTON = 0x200;
protected override CreateParams CreateParams
{
get
{
CreateParams myCp = base.CreateParams;
myCp.ClassStyle = myCp.ClassStyle | CP_NOCLOSE_BUTTON ;
return myCp;
}
}
You cant hide, but can disable it by above code.
Referance link:
http://www.codeproject.com/Articles/20379/Disabling-Close-Button-on-Forms
Related
When I scroll horizontally or vertically, the controls collapse with each other until I release the scroll bar and everything draws normally.
I already tried with DoubleBuffer and set style after InitializeComponent
SetStyle(ControlStyles.OptimizedDoubleBuffer |
ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint, true);
I also use:
private const int WM_HSCROLL = 0x114;
private const int WM_VSCROLL = 0x115;
protected override void WndProc(ref Message m)
{
if ((m.Msg == WM_HSCROLL || m.Msg == WM_VSCROLL)
&& (((int)m.WParam & 0xFFFF) == 5))
{
// Change SB_THUMBTRACK to SB_THUMBPOSITION
m.WParam = (IntPtr)(((int)m.WParam & ~0xFFFF) | 4);
}
base.WndProc(ref m);
}
But I'm still having the same problem. This is the normal behavior:
And this is when scrolling behavior:
UPDATE i find a solution but it just Reduces sharpness of that flicker solution
To handle the issue more efficient, please provide a simple demo to reproduce the issue.
And maybe you can try to override CreateParams.
protected override CreateParams CreateParams
{
get
{
if (Environment.OSVersion.Version.Major >= 6)
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
else
{
return base.CreateParams;
}
}
}
I wanted to add a nice shadow to my borderless form, and the best way I found to do it with minimal performance loss is to use DwmExtendFrameIntoClientArea. However, this seems to be causing Windows to draw a classic title bar over the window, but it is non-functional (ie. the glitch is merely graphical).
This is the code I am using:
int v = (int) DWMNCRENDERINGPOLICY.DWMNCRP_ENABLED;
NativeApi.DwmSetWindowAttribute(Handle, DwmWindowAttribute.NCRENDERING_POLICY, ref v, sizeof(int));
int enable = 0;
NativeApi.DwmSetWindowAttribute(Handle, DwmWindowAttribute.ALLOW_NCPAINT, ref enable, sizeof(int));
MARGINS margins = new MARGINS() {
leftWidth = 0,
topHeight = 0,
rightWidth = 0,
bottomHeight = 1
};
NativeApi.DwmExtendFrameIntoClientArea(Handle, ref margins);
I have tried setting ALLOW_NCPAINT to 1, and I even tried returning 0 when the window receives WM_NCPAINT without calling DefWndProc, but it made no difference.
Is there a way to resolve this weird issue while still using DwmExtendFrameIntoClientArea?
Big thanks to #Erik Philips, I have finally resolved the issue by following this answer's advice. The issue was in CreateParams:
/// <summary>
/// Gets the parameters that define the initial window style.
/// </summary>
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
if (!DesignMode) {
cp.ClassStyle |= (int) ClassStyle.DoubleClicks;
cp.Style |= unchecked((int) (WindowStyle.Popup | WindowStyle.SystemMenu | WindowStyle.ClipChildren | WindowStyle.ClipSiblings));
cp.ExStyle |= (int) ExtendedWindowStyle.Layered;
}
return cp;
}
}
The | had to be removed from cp.Style:
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
if (!DesignMode) {
cp.ClassStyle |= (int) ClassStyle.DoubleClicks;
cp.Style = unchecked((int) (WindowStyle.Popup | WindowStyle.SystemMenu | WindowStyle.ClipChildren | WindowStyle.ClipSiblings));
cp.ExStyle |= (int) ExtendedWindowStyle.Layered;
}
return cp;
}
}
This solved the issue, as apparently WinForms adds WS_BORDER by default to the class style, even if FormBorderStyle is later set to None.
I have developed a control for ToolTip and registered it as ToolTip with below codes,
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
param.ClassName = "tooltips_class32";
param.Style = unchecked(WindowMessages.WS_POPUP) | WindowMessages.TTS_ALWAYSTIP;
param.ExStyle |= WindowMessages.WS_EX_TOPMOST;
return param;
}
}
By default, the tooltip popup is enabled with Shadow.
How can i disable the default shadow of the ToolTip?
Regards,
Try to remove CS_DROPSHADOW flag from ClassStyle:
int CS_DROPSHADOW = 0x00020000;
{
...
param.ClassStyle &= ~CS_DROPSHADOW;
...
}
I have a form and it has tones of other controls(buttons, custom controls, labels, panel,gridview). You can guess i had flickering issue. I tried doublebuffering and it couldn't solve. Finally i tried this one:
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;
}
}
Flickering gone but my datagridview draws wrong. It shows CellBorders, BorderColors wrong. Actually this code has some issue with background images, lines, and other stuff. Why is that and how can it be fixed?
I know this question is a little old, but better late than never...
Here's a work-around to stop flickering when a user resizes a form, but without messing up the drawing of controls such as DataGridView. Provided your form name is "Form1":
int intOriginalExStyle = -1;
bool bEnableAntiFlicker = true;
public Form1()
{
ToggleAntiFlicker(false);
InitializeComponent();
this.ResizeBegin += new EventHandler(Form1_ResizeBegin);
this.ResizeEnd += new EventHandler(Form1_ResizeEnd);
}
protected override CreateParams CreateParams
{
get
{
if (intOriginalExStyle == -1)
{
intOriginalExStyle = base.CreateParams.ExStyle;
}
CreateParams cp = base.CreateParams;
if (bEnableAntiFlicker)
{
cp.ExStyle |= 0x02000000; //WS_EX_COMPOSITED
}
else
{
cp.ExStyle = intOriginalExStyle;
}
return cp;
}
}
private void Form1_ResizeBegin(object sender, EventArgs e)
{
ToggleAntiFlicker(true);
}
private void Form1_ResizeEnd(object sender, EventArgs e)
{
ToggleAntiFlicker(false);
}
private void ToggleAntiFlicker(bool Enable)
{
bEnableAntiFlicker = Enable;
//hacky, but works
this.MaximizeBox = true;
}
I found the trick to having nice smooth resizing and show my grid-lines, was to add an additional flag if my app is running under Windows XP or Windows Server 2003:
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000; // Turn on WS_EX_COMPOSITED
if (this.IsXpOr2003 == true)
cp.ExStyle |= 0x00080000; // Turn on WS_EX_LAYERED
return cp;
}
}
private Boolean IsXpOr2003
{
get
{
OperatingSystem os = Environment.OSVersion;
Version vs = os.Version;
if (os.Platform == PlatformID.Win32NT)
if ((vs.Major == 5) && (vs.Minor != 0))
return true;
else
return false;
else
return false;
}
}
This is code in VB.NET:
Protected Overrides ReadOnly Property CreateParams() As CreateParams
Get
Dim CP As CreateParams = MyBase.CreateParams
CP.Style = &HA0000
Return CP
End Get
And I want to convert it into C#. As per my assumption below is how the code in C# will look like. For the above code where CP.Style = &HA000, what should I put in
C# code. I have left it empty.
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.Style =
return cp;
}
}
You need:
CreateParams cp = base.CreateParams;
cp.Style = 0xA000;
return cp;
0x is the prefix for a hex integer literal in C#, instead of &H in VB.
Missing line:
cp.Style = 0xA0000;
protected override CreateParams CreateParams {
get {
CreateParams CP = base.CreateParams;
CP.Style = 0xa0000;
return CP;
}
}
Try this convertor