VB.Net - Setting all form icons to the application icon

Q

QLD_AU

Is their a way in a VB.Net application to set all sub form icons to the main
form ? or even set all icons to the Application icon, without having to
reference the icon as a filename ?

With Thanks

Jason
 
C

Cor Ligthert

Jason,

This answer is so not only for the icons.

Create your own basic form with everything basicly on it, and create from
that inherited forms. (That is an item in the add items in the project
explorer)

I hope this helps,

Cor
 
H

Herfried K. Wagner [MVP]

QLD_AU said:
Is their a way in a VB.Net application to set all sub form icons to the
main form ? or even set all icons to the Application icon, without having
to reference the icon as a filename ?

There are different ways to do that:

* You can assign the icon to all forms at designtime.

* You can create a base form that includes the icon and let
all other forms inherit from this base form.

* You can make a reference to the icon or main form available
and assign the icon at runtime, for example, in the forms' constructors:

Providing a reference to an application's main form
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=accessmainform&lang=en>

<URL:http://groups.google.de/[email protected]>

It's not recommended to assign icons to all forms of an application.
Especially dialogs (forms which are shown modally) typically don't have an
icon at all. Take a look at Microsoft's applications to see when using an
icon in the form's title bar makes sense.
 
B

Bob

Just in case this might help you managing icons...

Add some icons to your project, make them embedded resources, then put their
file names in the enum below. Then you can access them easily like so:

Dim i As Icon = Resources.GetIcon(Icons.IconName1)

Watch for line breaks...

------BEGIN CODE-------

Imports System.Reflection

Public Class Resources

Private Sub New()
End Sub

Public Enum Icons
IconName1
IconName2
IconName3
End Enum

Private Shared RootNameSpace As String = GetType(Resources).Namespace

Public Shared Function GetIcon(ByVal Icon As Icons) As Icon
Dim ret As Icon
Dim asm As [Assembly] = [Assembly].GetExecutingAssembly
Dim Name As String = _
RootNameSpace & "." & System.Enum.GetName(Icon.GetType, Icon) &
".ico"
Dim s As System.IO.Stream = asm.GetManifestResourceStream(Name)
If Not s Is Nothing Then
ret = New Icon(s)
s.Close()
End If
Return ret
End Function

End Class

------END CODE-------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top