Solved

Set Icon in Title Bar?

Posted on 2011-09-26
8
360 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 250 total points
Comment Utility
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
Comment Utility
0
 

Author Comment

by:deleyd
Comment Utility
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
 
LVL 40

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:deleyd
Comment Utility
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
Comment Utility
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

Expert Comment

by:Jacques Bourgeois (James Burger)
Comment Utility
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
Comment Utility
:) thank you for the info. we'll examine CloseReason.
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

772 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now