how to remove dropshadow in form? - c#

How to remove dropshadow effect which is enabled by CS_DropShadow because, shadow is always showing,
below is my code,
protected override CreateParams CreateParams
{
get
{
CreateParams value = base.CreateParams;
value.ExStyle |= WindowMessages.WS_EX_TOPMOST;
if (this.ShowShadow)
value.ClassStyle |= WindowMessages.CS_DROPSHADOW;
else
value.ClassStyle &= ~WindowMessages.CS_DROPSHADOW;
return value;
}
}
Help me resolve this.

Related

Flickering with transparent panel

I've created a simple program and now i'm in the stages of doing my designing. I've got a multiple Panels which i make visible / invisible to switch between "tabs" (EG. 1 panel for the login screen and 1 panel for the create account screen). Now i've made these panels invisible because i want them just as containers to be able to quickly move around controls and create buttons in.
My problem is that i've set my forms background image to a image i made in photoshop and whenever i switch between panels it flickers, whenever i just use a system color (white,black) this doesn't happen.
Is there any way for me to remove the flickering?
i've tried :
Setting double buffer to true
protected overrideing OnPaint, CreateBackground, and Createparam
my code is extremely basic :
private void btnNewAcc_Click(object sender, EventArgs e)
{
PanelNewAccount.Visible = true;
PanelLogin.Visible = false;
}
Try to setting the form property DoubleBuffered to true, in winforms the flickering usually happens because the GDI+ is trying to draw the control(s) a lot of times so DoubleBuffering you graphics should help in such cases
form.DoubleBuffered = true;
Thanks to Patrick i've solved my problem,
instead of using panels i'm using a TabControl and i assigned the same background to each tab.
Just as easy to add dynamic buttons as well.
Same features as panels but without the flickering.
#region .. Double Buffered function ..
public static void SetDoubleBuffered(System.Windows.Forms.Control c)
{
if (System.Windows.Forms.SystemInformation.TerminalServerSession)
return;
System.Reflection.PropertyInfo aProp = typeof(System.Windows.Forms.Control).GetProperty("DoubleBuffered", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
aProp.SetValue(c, true, null);
}
#endregion
#region .. code for Flucuring ..
protected override CreateParams CreateParams
{
get
{
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
#endregion
Even though i am late but if somebody else is also suffering from the same problem then this code fixed the flickering for me even though i dont know how it works.
I found it here.
Add the above code snippet in your program and in the contructor of your app add this line:
SetDoubleBuffered(YourPanelName);
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.ExStyle |= 0x02000000;
return cp;
}
}
code copy from codeproject solved my problem.

overriding CreateParams in a custom ListView has no effect?

I know that there are available Properties for ListView to change the common styles but I just want to test this. That is for example the View = View.LargeIcon applies the style LVS_ICON = 0 to the ListView or GridLines = true applies the style LVS_EX_GRIDLINES = 1 to the ListView. I would like to test with CreateParams. I think using GetWindowLong and SetWindowLong Win32 functions would be OK, but for convenience, as far as I know, CreateParams can change the style of a control. But this time with a ListView, I can't make it work, it has no effect at all, I wonder if ListView is a special case?. Here is my code:
public class CustomListView : ListView {
protected override CreateParams CreateParams {
get {
CreateParams cp = base.CreateParams;
cp.Style |= 3; //Apply LVS_LIST (View as List)
return cp;
}
}
}
Only LVS_EX_GRIDLINES = 1 makes some effect but the effect is not Grid lines are drawn on the ListView but the Border becomes thicker and looks like 3D-border. That's strange, most of other applies have not effect at all.
Could you explain it or at least give me some example which works? Again please don't give me any solution or code which uses GetWindowLong and SetWindowLong, just use CreateParams.
Thanks!
If it helps to explain how this works, this is handled internally by the ListView.UpdateExtendedStyles function, which gets called when one of the properties relating to an extended style is set.
Quoting from the relevant section on MSDN
Reflector disassembles the function as follows
protected void UpdateExtendedStyles()
{
if (base.IsHandleCreated)
{
int lparam = 0;
int wparam = 0x10cfd;
switch (this.activation)
{
case ItemActivation.OneClick:
lparam |= 0x40;
break;
case ItemActivation.TwoClick:
lparam |= 0x80;
break;
}
if (this.AllowColumnReorder)
{
lparam |= 0x10;
}
if (this.CheckBoxes)
{
lparam |= 4;
}
if (this.DoubleBuffered)
{
lparam |= 0x10000;
}
if (this.FullRowSelect)
{
lparam |= 0x20;
}
if (this.GridLines)
{
lparam |= 1;
}
if (this.HoverSelection)
{
lparam |= 8;
}
if (this.HotTracking)
{
lparam |= 0x800;
}
if (this.ShowItemToolTips)
{
lparam |= 0x400;
}
base.SendMessage(0x1036, wparam, lparam);
base.Invalidate();
}
}
EDIT
The reason you can't use CreateParams is because it's not relevant for a ListView see MSDN here - excerpt copied below

Password char for RichTextBox

I am using transparent custom control based on RichTextBox. Is there are any way to have password char support like in regular TextBox control.
It is simple to do, RTB actually implements support for password entry. It just isn't exposed in the .NET wrapper. Add a new class to your project and paste the code shown below. Compile. Drop the new control from the top of the toolbox onto your form.
using System;
using System.Windows.Forms;
class RichPassword : RichTextBox {
protected override CreateParams CreateParams {
get {
// Turn on ES_PASSWORD
var cp = base.CreateParams;
cp.Style |= 0x20;
return cp;
}
}
}
Yes there is a way. You would have to intercept key presses before they are drawn (look for PreviewKeyDown or similar events) and change them to asterisks(*). But you also need to implement logic to manage the real chars string.
Note I am in agreement with the Cody Gray comment.
string Value= "";
int richTextlent = 1;
private void richTextBox2_TextChanged(object sender, EventArgs e)
{
if(richTextBox2.Text.Length == richTextlent)
{
Value += richTextBox2.Text[0].ToString();
richTextBox2.Text = richTextBox2.Text.Remove(0, 1);
richTextBox2.Text += "*";
}
else
{
Value = "";
richTextBox2.Text = "";
}
richTextlent = richTextBox2.Text.Length + 1;
}
This has worked for me and solved the purpose.
Public Class RichPassword
Inherits RichTextBox
Private Const ES_PASSWORD = 32
Protected Overrides ReadOnly Property CreateParams As CreateParams
Get
Dim CP = MyBase.CreateParams
CP.Style = CP.Style Or 32
Return CP
End Get
End Property
End Class

"text" on the tree node when it is partially visible

How's the text(like below "Temporary ASP.NET") hovers directly over the tree node called? Any difference from tooltip?
Can it be controlled on visibility? e.g. do not display even when the node is partially visible.
pic: Windows Explorer
Thanks,
Yes, you can control this property, but not with a standard property.
If you override TreeView, and add a new CreateParams override, and add this code, then the tooltip won't appear:
protected override CreateParams CreateParams
{
get
{
CreateParams parms = base.CreateParams;
parms.Style |= 0x80; // Turn on TVS_NOTOOLTIPS
return parms;
}
}
Code found here

How to make a window have taskbar text but no title bar

How can I make my window not have a title bar but appear in the task bar with some descriptive text?
If you set the Form's .Text property then .net gives it a title bar, which I don't want.
this.ControlBox = false;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.ShowInTaskbar = true;
this.Text = "My title for task bar";
I've found a partial solution, to override CreateParams:
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
System.Windows.Forms.CreateParams cp = base.CreateParams;
cp.Style &= ~0x00C00000; // WS_CAPTION
return cp;
}
}
However this causes my window to be resized as if they have a title bar, ie it's taller than it should be. Is there any good solution to this?
In my case I have a Form with FormBorderStyle = FormBorderStyle.SizableToolWindow and the following CreateParams override did the trick (i.e. I now have a form without caption and without additional margin for the title, but it keeps the title in the task bar):
protected override System.Windows.Forms.CreateParams CreateParams
{
get
{
var parms = base.CreateParams;
parms.Style &= ~0x00C00000; // remove WS_CAPTION
parms.Style |= 0x00040000; // include WS_SIZEBOX
return parms;
}
}
One approach to look into might be to set the FormBorderStyle property of your Form to None (instead of FixedDialog).
The drawback to this approach is that you lose the borders of your window as well as the Titlebar. A result of this is that you lose the form repositioning/resizing logic that you normally get "for free" with Windows Forms; you would need to deal with this by implementing your own form move/resize logic in the form's MouseDown and MouseMove event handlers.
I would also be interested to hear about better solutions.
Just set the border style to None.
this.FormBorderStyle = FormBorderStyle.None;
Once you have removed the borders with the FormBorderStyle, as mentioned already, you can make it draggable fairly easily. I describe this at http://www.blackwasp.co.uk/DraggableBorderless.aspx.

Categories