-
April 11th, 2011, 04:56 AM
#1
[RESOLVED] Custom Control that you can add other controls too at Design time....
This one is a little tricky to explain but i will try..
Client asked if it posible to create a Form where the controls on it are scrollable, (Done this on a small scale before with placing Holding controls within a Holding control, adding a scrollbar and linking the lot.
However i'm looking at creating this into a User Control that i can simply Drop into a Form, Drop The controls into it, Set the defaults (Size etc) and go..
However the problems I've got right out the gate is ...
#1 The Scroller is not active during design time, so i cant scroll the inner holder..
#2 Cannot drop other controls into the Usercontrol at design time ..
I've been mucking around with this now for 4 hours, and could have done it the long way and been finished .. but now that i'm semi committed to this, i want to know if it can be done..)
My Progress So Far
Code:
Public Class ControlScroll
Private _MinHeight As Integer
Public Property ControlHeight() As Integer
Get
Return GroupBox1.Height
End Get
Set(ByVal value As Integer)
If value > Me.Height Then
GroupBox1.Height = value
Else
GroupBox1.Height = Me.Height
End If
RecalkScrollSize()
End Set
End Property
Public Property ControlMinHeight() As Integer
Get
Return _MinHeight
End Get
Set(ByVal value As Integer)
_MinHeight = value
End Set
End Property
Public Property ControlPosition() As Integer
Get
Return VScrollBar1.Value
End Get
Set(ByVal value As Integer)
VScrollBar1.Value = value
End Set
End Property
Private Sub ControlScroll_DragDrop(ByVal sender As Object, ByVal e As System.Windows.Forms.DragEventArgs) Handles Me.DragDrop
GroupBox1.Controls.Add(e.Data)
End Sub
Private Sub ControlScroll_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
VScrollBar1.Top = 0
VScrollBar1.Left = Me.Width - VScrollBar1.Width
VScrollBar1.Height = Me.Height
GroupBox1.Top = -VScrollBar1.Value
GroupBox1.Left = 0
GroupBox1.Width = Me.Width - VScrollBar1.Width
If Me.Height < _MinHeight Then
GroupBox1.Height = _MinHeight
Else
GroupBox1.Height = Me.Height
End If
RecalkScrollSize()
End Sub
Public Sub New()
' This call is required by the Windows Form Designer.
InitializeComponent()
' Add any initialization after the InitializeComponent() call.
Me.Controls.Add(GroupBox1)
Me.Controls.Add(VScrollBar1)
VScrollBar1.Visible = True
GroupBox1.Visible = True
GroupBox1.Height = 100
RecalkScrollSize()
End Sub
Private Sub VScrollBar1_ValueChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles VScrollBar1.ValueChanged
GroupBox1.Top = -VScrollBar1.Value
End Sub
Private Sub RecalkScrollSize()
If GroupBox1.Height > Me.Height Then
VScrollBar1.Enabled = True
VScrollBar1.Maximum = GroupBox1.Height - Me.Height
VScrollBar1.LargeChange = Me.Height
VScrollBar1.SmallChange = 1
Else
VScrollBar1.Enabled = False
End If
End Sub
End Class
Articles VB6 : Break the 2G limit - Animation 1, 2 VB.NET : 2005/8 : Moving Images , Animation 1 , 2 , 3 , User Controls
WPF Articles : 3D Animation 1 , 2 , 3
Code snips: VB6 Hex Edit, IP Chat, Copy Prot., Crop, Zoom : .NET IP Chat (V4), Adv. ContextMenus, click Hotspot, Scroll Controls
Find me in ASP.NET., VB6., VB.NET , Writing Articles, My Genealogy, Forum
All VS.NET: posts refer to VS.NET 2008 (Pro) unless otherwise stated.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|