Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / March 2007

Tip: Looking for answers? Try searching our database.

Checking for null icon

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Clive Dixon - 15 Mar 2007 15:21 GMT
If I create a form, not supplying an icon, if I get the value of the Icon
property I get the default icon back (even though no icon is being displayed
in the form). How can I determine whether the icon is set in a form or not?
I have been trying using PInvoke with Win32 APIs with no success.
VJ - 15 Mar 2007 15:50 GMT
really catchy. You can't set icon null for a Form. Only way is to see if it
is default or not

VJ

> If I create a form, not supplying an icon, if I get the value of the Icon
> property I get the default icon back (even though no icon is being
> displayed in the form). How can I determine whether the icon is set in a
> form or not? I have been trying using PInvoke with Win32 APIs with no
> success.
Clive Dixon - 15 Mar 2007 15:59 GMT
So the follow up question is "how can I tell that the Icon returned by
System.Windows.Forms.Form.Icon is the default icon or not?" It doesn't have
to be a neat solution, as I only need this information in NUnit test code. I
guess I would have to do something like create a dummy form and compare
handles (assuming that the handle is the same for all instances of the icon
in all forms).

> really catchy. You can't set icon null for a Form. Only way is to see if
> it is default or not
[quoted text clipped - 6 lines]
>> form or not? I have been trying using PInvoke with Win32 APIs with no
>> success.
VJ - 15 Mar 2007 16:15 GMT
Oh no Clive.. that sounds a hack.. may not work. So yours is a test bed app
that says oops you missed a icon for the Form?.. ahh...
Did u google and see if you get anything?

- keep the handle as last resort! (sometimes hack is a good practice,
although I hate it)
VJ

> So the follow up question is "how can I tell that the Icon returned by
> System.Windows.Forms.Form.Icon is the default icon or not?" It doesn't
[quoted text clipped - 13 lines]
>>> form or not? I have been trying using PInvoke with Win32 APIs with no
>>> success.
Clive Dixon - 15 Mar 2007 18:27 GMT
Actually I'm looking to check whether a form which *shouldn't* have an icon
displayed (it has FormBorderStyle = FixedDialog and the icon is not set,
which means no icon is displayed, not even the default one) has *not*
accidentally acquired one. We have localised forms, which means that the
visual designer will always modify the InitializeComponent to set the Icon
to something from the .resx. Hence every time somebody modifies one of these
localised forms, the visual designer adds back in code (thanks, Microsoft!)
to explicitly set the icon to a copy of the default icon, and thus it now
appears in the dialog. I want to write some NUnit tests to check when this
has happened and someone has forgotten to correct it, 'cos I'm getting fed
up.

I Googled and couldn't find anything useful. I tried my nasty hack comparing
the handle against a dummy form, and it appears to work, i.e. the handles
are the same if I do not set the icon, but if I do, they are different. Yes,
it is *very* yucky...

> Oh no Clive.. that sounds a hack.. may not work. So yours is a test bed
> app that says oops you missed a icon for the Form?.. ahh...
[quoted text clipped - 21 lines]
>>>> a form or not? I have been trying using PInvoke with Win32 APIs with no
>>>> success.
Matt Brunell - 15 Mar 2007 20:00 GMT
You could try name-hiding the "Icon" property.

like this:
class YourForm : Form
{
new public Icon Icon
{
  get { return null; }
  set { }
}
}

Name hiding is NOT polymorphic.
If you have a Form reference, your code will not be executed.

The InitializeCompoenent function calls
 this.Icon =  (get something form resources);

However, if you do this, the default icon still appears on the form.

I think you may just be better off using the Form.ShowIcon property.

--Matt

> Actually I'm looking to check whether a form which *shouldn't* have an icon
> displayed (it has FormBorderStyle = FixedDialog and the icon is not set,
[quoted text clipped - 40 lines]
>
> - Show quoted text -
Clive Dixon - 16 Mar 2007 12:01 GMT
ShowIcon: That's in 2.0 - we are still stuck with 1.1 unfortunately. Besides
which, the docs say

"This property has no effect if FormBorderStyle is set to FixedDialog.",

which is the case in my situation.

> You could try name-hiding the "Icon" property.
>
[quoted text clipped - 79 lines]
>>
>> - Show quoted text -
VJ - 15 Mar 2007 20:35 GMT
Belivie it or not this exists from VB days.. and nothing has been done. Well
maybe there is a inherent problem or reason to do.. I would love to learn.
One possibility I can think of is the association of the ControlBox to the
Icon, Maybe it has something to do with this.

Handle sounds ok to me.

VJ

> If I create a form, not supplying an icon, if I get the value of the Icon
> property I get the default icon back (even though no icon is being
> displayed in the form). How can I determine whether the icon is set in a
> form or not? I have been trying using PInvoke with Win32 APIs with no
> success.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.