Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Components
|
VB Components Issues specific to components in VB.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Components section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 31st, 2006, 09:53 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Best way to initialize values for design mode?

Hi all,

(I hope I am in the right forum)

I am working on a custom Control. I would like to initialize certain properties. I've done it various ways, and can successfully initialize the properties several ways; however, there is a slight problem.

[u]The Problem</u>
This only happens ONCE after the BUILD. I drop the control on the form, and it sets its initial property values fine. Then I adjust those values. Then I go into debug mode. The debug-mode control is correct, but the design-mode control re-initializes itself. I repeat, this behavior only happens once after the build.

[u]My question is this:</u>
Is there a standard way of initializing property values for custom controls for design-mode? For instance, say you want the custom control's Height property initialized at 50 when dropped on the form. How would you do that?

Just in case anyone cares, below is the code I'm using. It's nothing special: its something I whipped up trying to isolate this and a couple of other issues I was having.

Code:
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.Drawing

Public Class UserControl1

    Private WithEvents myContainer As Control
    Private isInitialized As Boolean
    Private defaultValuesAreSet As Boolean

    Private initHeight As Integer = 50

    <DefaultValue(False)> _
    Public Property IsInit() As Boolean
        Get
            Return Me.isInitialized
        End Get
        Set(ByVal value As Boolean)
            Me.isInitialized = value
        End Set
    End Property


    Sub New()

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

        ' Add any initialization after the InitializeComponent() call.
        If Not Me.isInitialized Then
            Me.defaultValuesAreSet = False
        Else
            Me.defaultValuesAreSet = True
        End If

    End Sub


    Protected Overrides Sub OnPaint( _
    ByVal e As System.Windows.Forms.PaintEventArgs)
        MyBase.OnPaint(e)

        If Me.isInitialized Then

            If Me.DesignMode And Not Me.defaultValuesAreSet Then
                Me.Height = Me.initHeight
                Me.defaultValuesAreSet = True
            End If

            Me.Top = 0
            Me.Left = 0
            Me.Width = Me.Parent.ClientRectangle.Width
            Me.BackColor = Color.Red

        End If

    End Sub


    Protected Overrides Sub InitLayout()
        MyBase.InitLayout()
        Me.isInitialized = True
        Me.myContainer = Me.Parent
    End Sub


    Private Sub myContainer_SizeChanged( _
    ByVal sender As Object, _
    ByVal e As System.EventArgs) _
    Handles myContainer.SizeChanged
        Me.Refresh()
    End Sub
End Class




Thanks all,
--William
 
Old March 31st, 2006, 09:55 AM
Registered User
 
Join Date: Mar 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well...The referencing parent problem is something I was experiencing earlier but seemed to have solved...I forgot to change the title.

*doh*

--William

AddedByEdit:
Title edited, once I figured out how.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Document design mode image dont show in IE7 h2c357 Javascript 0 May 3rd, 2007 09:21 AM
ASP.NET and Design mode bergkarl Dreamweaver (all versions) 0 October 13th, 2006 02:38 PM
Crystal reports design view mode subhanak Crystal Reports 2 May 4th, 2006 01:29 PM
XM 2004: Design and Split mode disabled? tawxic Dreamweaver (all versions) 1 December 2nd, 2004 04:53 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.