Application Title in Taskbar but not Titlebar - c#

This is a strange thing I'm doing, but how can I set the title of a winform form in the taskbar, but not in its titlebar?

A possible solution (it works fine for me) it's to override the CreateParams property and set the caption to be displayed in the taskbar:
protected override CreateParams CreateParams
{
get
{
new SecurityPermission(SecurityPermissionFlag.UnmanagedCode).Demand();
// Extend the CreateParams property of the Button class.
CreateParams cp = base.CreateParams;
// Update the button Style.
cp.Style &= ~0xC00000; //WS_CAPTION;
cp.Caption = PRODUCT_NAME;
return cp;
}
}
I hope that works for you,
Lisa

Okay, so my temporary work around is this:
At runtime/design-time, Clear the Text Property for the Form (Form1, or whatever form this applies to), and when the Minimize, or Hide() events are triggered, change the Text Property to display a Title. So, when the form is hidden or minimized, you won't be able to see the titlebar anyway, but you will be able to see the caption on the Taskbar! And when the Form is later maximized, or when the Form.WindowState == WindowState.Normal, then clear the Text Property again. :-)
I wonder if this is the approach MS took!?
Edit:
Okay, sweet, I've got some working code of yumminess:
If you're using Visual Studio, go to Design View, select the Form control, open the Properties Pane, click the Events Tab, then double-click the Resize event. The Code View should display. Inside the Resize() code that was just created, type this:
private void Form_Resize( object sender, System.EventArgs e )
{
if( this.WindowState == FormWindowState.Minimized )
this.Text "Some uber-awesome title.";
}
Step 2:
When you want to show/maximize the form again, simply edit the above so it looks like this:
private void Form_Resize( object sender, System.EventArgs e )
{
if( this.WindowState == FormWindowState.Minimized )
this.Text "Some uber-awesome title.";
else if(this.WindowState == FormWindowState.Normal || this.WindowState == FormWindowState.Maximized)
{
this.Text = String.Empty; // Or, you can use: this.Text = "";
}
}
However, this does not completely solve my problem yet. It still doesn't display the Title in the Taskbar when the Form is Visible to the user (because the Text property of the Titlebar is empty.

A workaround could be drawing your own form title bar. That way you won't need to change the actual title that's shown in Taskbar.

This question is about WPF rather than Winforms but it's applicable: Set a taskbar text different from the Window title in wpf

Related

Set taskbar icon of top level usercontrol (Winforms)

I have a top level (ie. acts like a window) UserControl (.NET 4.0) which I am using to simulate a custom form. I can easily set the title text and taskbar text like so:
public override string Text
{
get { return base.Text; }
set
{
base.Text = value
TitleText.Text = value;
}
}
Which sets both the title text and taskbar text:
Please note that the bar down the bottom of the image is my actual taskbar; I have installed an alternate shell
The problem I have come across is that I can't seem to set the taskbar icon of this UserControl as it has no overridable Icon property so I can't set the taskbar icon as I would with the text. Please also note that the icon shown in the UserControl is just a PictureBox containing an image.
So, in short I want to be able to do this:
But I can't do this as there is no Icon property for a UserControl:
public override Icon Icon
{
get { return base.Icon; }
set
{
base.Icon = value;
TitleBarIcon.Image = value.ToBitmap();
}
}
How can I change the taskbar icon?
Thanks in advance ;)
I am not sure if I got you right but I think you have to possibilites:
Either set the Icon of the ParentForm.
Or set the ApplicationIcon as described here: http://msdn.microsoft.com/en-us/library/339stzf7.aspx
EDIT:
As you are using a control as TopLevelControl you need to send the WM_SETICON during the creation of the control - as the form does!
Taken from the Form.CreateHandle:
Icon icon = this.Icon;
if (icon != null && this.TaskbarOwner.Handle != IntPtr.Zero)
{
UnsafeNativeMethods.SendMessage(this.TaskbarOwner, 128, 1, icon.Handle);
}

How to avoid screen flickering?

I am making a windows form application and mainly my screen is divided between 3 parts like
===========================================================================
Top panel (it doesn't flicker)
===========================================================================
|| || 'it has a panel & panel contains a table layout,this tabble layout'
|| || 'has a picture box and a label, picture & text of label is'
|| ||'changed on the click of side bar menu' (PROB: this flickers a lot)
||side bar ||==============================================================
||(doesn't ||'this part also has a panel and panel contains different table'
||flicker) ||'layouts and on the click of a menu, related table layout is shown and'
|| ||'some of the parts of table layout are created dynamically.'
|| ||
|| || (PROB: this flickers a lot)
|| ||
i searched a lot and found this solution everywhere and i tried this
public constructor()
{
InitializeComponent();
this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
this.DoubleBuffered = true;
DoubleBuffered = true;
SetStyle(ControlStyles.UserPaint |
ControlStyles.AllPaintingInWmPaint |
ControlStyles.ResizeRedraw |
ControlStyles.ContainerControl |
ControlStyles.OptimizedDoubleBuffer |
ControlStyles.SupportsTransparentBackColor
, true);
}
i also tried this
protected override CreateParams CreateParams
{
get
{
CreateParams handleParam = base.CreateParams;
handleParam.ExStyle |= 0x02000000; // WS_EX_COMPOSITED
return handleParam;
}
}
it changes the whole background of my screen to black color.
but still problem remains the same, can someone tell me how to solve this problem and where i am doing mistake ?
Thanks a lot in advance.
Without more to go on, my gut says that you are either adding a lot of data do those areas or there is a lot of resizing going on.
try this anywhere you update the screen ( adding rows to listviews/boxes/etc ) or resize the screen, or anything else that will cause the screen to redraw.
ex:
public void something_resize(object sender, EventArgs e)
{
try
{
this.SuspendLayout();
// Do your update, add data, redraw, w/e.
// Also add to ListViews and Boxes etc in Batches if you can, not item by item.
}
catch
{
}
finally
{
this.ResumeLayout();
}
}
Its important to put the ResumeLayout() call in the finally block, because if an exception occurs for w/e reason, you want your window to layout, regardless of what you do with the exception.

How to delete control boxes when maximized

I'm developing an application and I want it to be full screen. As I want to change between different screens, I created a MDIParent and some MDIChilds. But when I say that I want to see it full screen I have this screen:
I have set properties to:
Form border style: None
Windows state: Maximized
And I have:
Maximize box: False
Minimize box: False
control box: False
for both MDIParent and MDIChild. But I still have that control box showing...
How can I hide it??
You may be able to do this by overriding the Control.CreateParams method.
Check out the Window styles that you can apply.
Also check out the Window Class Styles that you can apply.
For example (not answering your question but showing you how to change window styles):
protected override CreateParams CreateParams
{
get
{
CreateParams param = base.CreateParams;
const int CS_DROPSHADOW = 0x00020000;
const int WS_CAPTION = 0xC00000;
param.ClassStyle = param.ClassStyle | CS_DROPSHADOW; // Turn on window shadow.
param.Style = param.Style & ~WS_CAPTION; // Turn off caption.
return param;
}
}

How can I change the text of an existing ToolTip control, in a PictureBox in my WinForm application?

I have a winform application which has a dynamic number (based on a database value) of PictureBoxes. Each P-Box has a Tooltip control.
How can I change the ToolTip Text without having any memory leaks? Right now, I've got the following code, but it's leaking memory => the previous ToolTip controls are not getting GC'd.
BTW, this is a background thread that is trying to update the main UI thread....
if (pictureBox == null || !pictureBox.IsHandleCreated) {
continue;
}
Action setTooltipAndImage = () => {
var toolTip = new ToolTip();
GameServer tempGameFile = gameServer;
toolTip.SetToolTip(pictureBox, string.Format(...));
pictureBox.Image = Resources.RedButton;
};
if (pictureBox.InvokeRequired) {
pictureBox.Invoke(setTooltipAndImage);
} else {
setTooltipAndImage();
}
As I said - this works but it's leaking.
Anyone have any suggestions?
Don't create a new ToolTip each time. Add a ToolTip to the form using the visual designer, like you would for any other control or component. Call toolTip.SetToolTip(...) on the form's tool tip each time. The ToolTip will be disposed when the Form is disposed.
Yes, you do not need to create a new ToolTip each time, a single ToolTipwill do. There is no issue if you do not know how many ToolTips you want, because if there is only one ToolTip say toolTip1, then you can use the following every time you want to change the ToolTip caption and control on some event. You only need one ToolTip instance per form.
toolTip1.SetToolTip(Current_pictureBox, "<tool tip string>");
You only need one ToolTip instance per form.
toolTip.SetToolTip(control, caption) - can use with many control, you can set caption for each control
toolTip.ToolTipTitle - set tool tip title, the title is one for all control bonded with tool tip
for example :
public Form1()
{
InitializeComponent();
toolTip1.SetToolTip(button1, "btn1");
toolTip1.SetToolTip(button2, "btn2");
toolTip1.SetToolTip(button3, "btn3");
}
private void button4_Click(object sender, EventArgs e)
{
toolTip1.ToolTipTitle = textBox1.Text;
}

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