Solved

Set Icon in Title Bar?

Posted on 2011-09-26
8
365 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
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
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

 
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.net Use code to open two DateTimePickers at the same time 7 44
Reactjs with .NET 3 70
Need help converting bitmap to image in VB.Net 8 44
C# Linq Select From List 3 41
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
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.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

679 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