开发者

Application Title in Taskbar but not Titlebar

开发者 https://www.devze.com 2023-02-15 22:32 出处:网络
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 th

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号