Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set Icon in Title Bar?

Posted on 2011-09-26
8
Medium Priority
?
373 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
  • 4
  • 3
8 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 1000 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 1000 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

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!
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

782 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