Home All Groups Group Topic Archive Search About
Author
15 Mar 2007 2:21 PM
Clive Dixon
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.

Author
15 Mar 2007 2:50 PM
VJ
really catchy. You can't set icon null for a Form. Only way is to see if it
is default or not

VJ

Show quote
"Clive Dixon" <clived at digita dot com> wrote in message
news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
> 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.
>
Author
15 Mar 2007 2:59 PM
Clive Dixon
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).

Show quote
"VJ" <nonewsaddr***@yahoo.com> wrote in message
news:uEME7ExZHHA.5056@TK2MSFTNGP03.phx.gbl...
> really catchy. You can't set icon null for a Form. Only way is to see if
> it is default or not
>
> VJ
>
> "Clive Dixon" <clived at digita dot com> wrote in message
> news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
>> 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.
>>
>
>
Author
15 Mar 2007 3:15 PM
VJ
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

Show quote
"Clive Dixon" <clived at digita dot com> wrote in message
news:OopbCKxZHHA.3968@TK2MSFTNGP06.phx.gbl...
> 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).
>
> "VJ" <nonewsaddr***@yahoo.com> wrote in message
> news:uEME7ExZHHA.5056@TK2MSFTNGP03.phx.gbl...
>> really catchy. You can't set icon null for a Form. Only way is to see if
>> it is default or not
>>
>> VJ
>>
>> "Clive Dixon" <clived at digita dot com> wrote in message
>> news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
>>> 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.
>>>
>>
>>
>
>
Author
15 Mar 2007 5:27 PM
Clive Dixon
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...

Show quote
"VJ" <nonewsaddr***@yahoo.com> wrote in message
news:%23CuGJTxZHHA.5044@TK2MSFTNGP05.phx.gbl...
> 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
>
> "Clive Dixon" <clived at digita dot com> wrote in message
> news:OopbCKxZHHA.3968@TK2MSFTNGP06.phx.gbl...
>> 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).
>>
>> "VJ" <nonewsaddr***@yahoo.com> wrote in message
>> news:uEME7ExZHHA.5056@TK2MSFTNGP03.phx.gbl...
>>> really catchy. You can't set icon null for a Form. Only way is to see if
>>> it is default or not
>>>
>>> VJ
>>>
>>> "Clive Dixon" <clived at digita dot com> wrote in message
>>> news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
>>>> 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.
>>>>
>>>
>>>
>>
>>
>
>
Author
15 Mar 2007 7:00 PM
Matt Brunell
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


Show quote
On Mar 15, 12:27 pm, "Clive Dixon" <clived at digita dot com> wrote:
> 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...
>
> "VJ" <nonewsaddr***@yahoo.com> wrote in message
>
> news:%23CuGJTxZHHA.5044@TK2MSFTNGP05.phx.gbl...
>
>
>
> > 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
>
> > "Clive Dixon" <clived at digita dot com> wrote in message
> >news:OopbCKxZHHA.3968@TK2MSFTNGP06.phx.gbl...
> >> 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).
>
> >> "VJ" <nonewsaddr***@yahoo.com> wrote in message
> >>news:uEME7ExZHHA.5056@TK2MSFTNGP03.phx.gbl...
> >>> really catchy. You can't set icon null for a Form. Only way is to see if
> >>> it is default or not
>
> >>> VJ
>
> >>> "Clive Dixon" <clived at digita dot com> wrote in message
> >>>news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
> >>>> 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.- Hide quoted text -
>
> - Show quoted text -
Author
16 Mar 2007 11:01 AM
Clive Dixon
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.


Show quote
"Matt Brunell" <WellBre***@gmail.com> wrote in message
news:1173985249.175391.191180@e65g2000hsc.googlegroups.com...
> 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
>
>
> On Mar 15, 12:27 pm, "Clive Dixon" <clived at digita dot com> wrote:
>> 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...
>>
>> "VJ" <nonewsaddr***@yahoo.com> wrote in message
>>
>> news:%23CuGJTxZHHA.5044@TK2MSFTNGP05.phx.gbl...
>>
>>
>>
>> > 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
>>
>> > "Clive Dixon" <clived at digita dot com> wrote in message
>> >news:OopbCKxZHHA.3968@TK2MSFTNGP06.phx.gbl...
>> >> 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).
>>
>> >> "VJ" <nonewsaddr***@yahoo.com> wrote in message
>> >>news:uEME7ExZHHA.5056@TK2MSFTNGP03.phx.gbl...
>> >>> really catchy. You can't set icon null for a Form. Only way is to see
>> >>> if
>> >>> it is default or not
>>
>> >>> VJ
>>
>> >>> "Clive Dixon" <clived at digita dot com> wrote in message
>> >>>news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
>> >>>> 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.- Hide quoted text -
>>
>> - Show quoted text -
>
>
Author
15 Mar 2007 7:35 PM
VJ
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

Show quote
"Clive Dixon" <clived at digita dot com> wrote in message
news:ecdsz0wZHHA.4616@TK2MSFTNGP03.phx.gbl...
> 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.
>

AddThis Social Bookmark Button