Solved

Set Icon in Title Bar?

Posted on 2011-09-26
8
368 Views
Last Modified: 2013-12-17
How can I get my icon (.ico file icon) to appear in the upper left corner of my Form1 titlebar?

In Visual Studio I have Form1 Properties Icon set to my icon, ShowIcon=Ture, ShowInTaskbar=True, icon size 16x16. I tried a .ico file which had icons of several sizes in it: 16x16, 32x32, 48x48. The icon shows in the taskbar when I run the program.

Still icon does not appear in upper left corner of title bar.
0
Comment
Question by:deleyd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 250 total points
ID: 36599896
Did you change the FormBorderStyle of the form? Did you remove the ControlBox.

Some combinations of those create a type of form that does not support an icon.
0
 
LVL 14

Assisted Solution

by:binaryevo
binaryevo earned 250 total points
ID: 36600864
0
 

Author Comment

by:deleyd
ID: 36601666
OK I had 'ControlBox' set to False to get rid of the minimize, maximize, and close buttons on the upper right. Setting that back to True fixed the icon problem. Now I just need to find another way to get rid of the minimize, maximize, and close (red X) buttons, without deleting the upper left icon.
0
[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

 
LVL 40
ID: 36601854
MinimizedBox and MaximizedBox have their own properties. So you can turn them off individually.

Now, the ControlBox (the Red X) is something else. The reason is that the icon is not there for decoration, it is a menu, that can be used to close the form. If there is no need for the ControlBox, then Microsoft assumes that there is no need for the icon.

So you cannot get rid of the ControlBox except maybe, and I insist on the maybe, by subclassing the form, a process that lets you connect direct to Windows instead of using the framework to do the job. Maybe somebody can guide you on that, I can't.

Now one could wonder why you want to get rid of the ControlBox. The user will have to close the form at some point. No?

Could I suspect that it is because you want to do something when you close the form, that something is under a Button, and you want to force the user into using your button to close the form. If this is the case, then you are not closing the form in a proper way.

Your button should have only one command: Me.Close.

The code that you need to run when you close the form should be in the FormClosing event. This event will be called by Me.Close, but it will also be called by the Red X. Well, it will even be called when you close Windows.

Thus, there would be no reason to remove the ControlBox, and you could keep the icon.
0
 

Author Comment

by:deleyd
ID: 36602170
Thank you for the excellent info. I think what we want is a way to catch the FormClosing event and say, "Hey, wait a minute, you can't stop right now or the patient will die."

I'll look into FormClosing. I don't know if it's possible to abort the closing at that point or if it's already too late by that point.

:)
0
 

Author Comment

by:deleyd
ID: 36602198
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
  e.Cancel = true;
}

Open in new window


(of course there will be more to it in the real code.)
0
 
LVL 40
ID: 36602422
Be aware that FormClosing is called not matter how the application is called to close. Even a Task Manager call if the user wants to stop a frozen application.

If you set Cancel to True while Windows is closing for instance, Windows won't close.

Before setting Cancel to True, examine the CloseReason. If it comes from the TaskManager, your application is probably stuck, do not Cancel, otherwise the application won't lose.
0
 

Author Comment

by:deleyd
ID: 36602463
:) thank you for the info. we'll examine CloseReason.
0

Featured Post

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

626 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question