Solved

Set Icon in Title Bar?

Posted on 2011-09-26
8
366 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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