all groups > dotnet interop > august 2005 >
You're in the

dotnet interop

group:

Setting an icon and caption for a panel in VB.Net?


Setting an icon and caption for a panel in VB.Net? Joergen Bech <jbech<NOSPAM> NO[at]SPAM
8/26/2005 12:00:00 AM
dotnet interop:

Trying to make a panel appear as a form with caption, icon,
minimize, maximize, and close buttons (for replicating a
WinForms designer).

Trouble is, I would like to replace the icon and caption using
properties after the control has been created.

I believe the solution involves the WM_SETICON message,
but the details escape me at the moment. Or is there a more
"managed" way of doing it?

Initial work in code snippet below.

Anyone have an idea?

TIA,

Joergen Bech

---snip---

Option Explicit On
Option Strict On

Imports System.Windows.Forms
Imports Geac.Runtime.Shared
Imports System.Drawing

Public Class FormPanel
Inherits System.Windows.Forms.Panel

#Region " Windows Form Designer generated code "

Public Sub New()
MyBase.New()

'This call is required by the Windows Form Designer.
InitializeComponent()

'Add any initialization after the InitializeComponent()
call
Me.BackColor = Color.FromKnownColor(KnownColor.Control)

End Sub

'UserControl overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As
Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Windows Form
Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
components = New System.ComponentModel.Container
End Sub

#End Region

Protected Overrides ReadOnly Property CreateParams() As
CreateParams
Get
Dim cp As CreateParams = MyBase.CreateParams
cp.Caption = "This is a test"

cp.Style = Win32API.WindowStyle.WS_OVERLAPPEDWINDOW
cp.Style = cp.Style Or
Win32API.WindowStyle.WS_CLIPSIBLINGS
cp.Style = cp.Style Or
Win32API.WindowStyle.WS_CLIPCHILDREN
cp.Style = cp.Style Or Win32API.WindowStyle.WS_VISIBLE
cp.Style = cp.Style Or Win32API.WindowStyle.WS_CHILD

cp.ExStyle =
Win32API.WindowStyleEx.WS_EX_CONTROLPARENT

cp.ClassStyle = 0

Return cp
End Get
End Property
End Class


Re: Setting an icon and caption for a panel in VB.Net? Joergen Bech <jbech<NOSPAM> NO[at]SPAM
8/28/2005 11:36:36 PM

No answer? Guess I'll write a quick follow-up:

Haven't solved it yet, but found this in the framework using
Reflector.
Probably needs a bit of cleaning up, but seems to be what I'm
looking for. Haven't tried it yet:

---snip---

Private Sub UpdateWindowIcon(ByVal redrawFrame As Boolean)
If MyBase.IsHandleCreated Then
Dim icon1 As Icon
If (((Me.FormBorderStyle = FormBorderStyle.FixedDialog)
AndAlso (Me.formState.Item(Form.FormStateIconSet) = 0)) AndAlso Not
Me.IsRestrictedWindow) Then
icon1 = Nothing
Else
icon1 = Me.Icon
End If
If (Not icon1 Is Nothing) Then
If (Me.smallIcon Is Nothing) Then
Try
Me.smallIcon = New Icon(icon1,
SystemInformation.SmallIconSize)
Catch obj1 As Object
End Try
End If
If (Not Me.smallIcon Is Nothing) Then
MyBase.SendMessage(128, 0,
Me.smallIcon.Handle)
End If
MyBase.SendMessage(128, 1, icon1.Handle)
Else
MyBase.SendMessage(128, 0, 0)
MyBase.SendMessage(128, 1, 0)
End If
If redrawFrame Then
SafeNativeMethods.RedrawWindow(New HandleRef(Me,
MyBase.Handle), CType(Nothing, COMRECT), NativeMethods.NullHandleRef,
1025)
End If
End If
End Sub








On Fri, 26 Aug 2005 16:16:17 +0200, Joergen Bech
[quoted text, click to view]
AddThis Social Bookmark Button