Index: trunk/Include/Classes/System/Windows/Forms/Control.ab
===================================================================
--- trunk/Include/Classes/System/Windows/Forms/Control.ab	(revision 381)
+++ trunk/Include/Classes/System/Windows/Forms/Control.ab	(revision 388)
@@ -4,4 +4,5 @@
 #define __SYSTEM_WINDOWS_FORMS_CONTROL_AB__
 
+/*
 #require <Classes/System/Windows/Forms/misc.ab>
 #require <Classes/System/Windows/Forms/CreateParams.ab>
@@ -11,12 +12,14 @@
 #require <Classes/System/Math.ab>
 #require <Classes/System/Threading/WaitHandle.ab>
+*/
 #require <Classes/System/Drawing/Color.ab>
 #require <Classes/System/Drawing/Point.ab>
 #require <Classes/System/Drawing/Size.ab>
 #require <Classes/System/Drawing/Rectangle.ab>
+/*
 #require <Classes/System/Runtime/InteropServices/GCHandle.ab>
 #require <Classes/ActiveBasic/Windows/WindowHandle.sbp>
 #require <Classes/ActiveBasic/Strings/Strings.ab>
-
+*/
 Namespace System
 Namespace Windows
@@ -143,21 +146,21 @@
 		End If
 	End Function
-
+/* BoundsSpecifiedが使用不能なのでコメントアウト
 	Sub Bounds(r As Rectangle)
 		SetBoundsCore(r.X, r.Y, r.Width, r.Height, BoundsSpecified.All)
 	End Sub
-
+*/
 	Const Function Location() As Point
 		Return Bounds.Location
 	End Function
-
+/*
 	Sub Location(p As Point)
 		SetBoundsCore(p.X, p.Y, 0, 0, BoundsSpecified.Location)
 	End Sub
-
+*/
 	Const Function Size() As Size
 		Return Bounds.Size
 	End Function
-
+/*
 	Sub Size(s As Size)
 		SetBoundsCore(0, 0, s.Width, s.Height, BoundsSpecified.Size)
@@ -171,41 +174,41 @@
 		Return ClientRectangle.Size
 	End Function
-
+*/
 	Const Function Left() As Long
 		Dim b = Bounds
 		Return b.Left
 	End Function
-
+/*
 	Sub Left(l As Long)
 		SetBoundsCore(l, 0, 0, 0, BoundsSpecified.X)
 	End Sub
-
+*/
 	Const Function Top() As Long
 		Dim b = Bounds
 		Return b.Top
 	End Function
-
+/*
 	Sub Top(t As Long)
 		SetBoundsCore(0, t, 0, 0, BoundsSpecified.Y)
 	End Sub
-
+*/
 	Const Function Width() As Long
 		Dim b = Bounds
 		Return b.Width
 	End Function
-
+/*
 	Sub Width(w As Long)
 		SetBoundsCore(0, 0, w, 0, BoundsSpecified.Width)
 	End Sub
-
+*/
 	Const Function Height() As Long
 		Dim b = Bounds
 		Return b.Height
 	End Function
-
+/*
 	Sub Height(h As Long)
 		SetBoundsCore(0, 0, 0, h, BoundsSpecified.Height)
 	End Sub
-
+*/
 	Const Function Right() As Long
 		Dim b = Bounds
@@ -273,32 +276,37 @@
 
 	Sub Control()
-		Debug
 		Dim sz = DefaultSize()
-		Control("", 100, 100, sz.Width, sz.Height)
+		init(Nothing, "", 100, 100, sz.Width, sz.Height)
 	End Sub
 
 	Sub Control(text As String)
 		Dim sz = DefaultSize()
-		Control(text, 100, 100, sz.Width, sz.Height)
+		init(Nothing, text, 100, 100, sz.Width, sz.Height)
 	End Sub
 
 	Sub Control(parent As Control, text As String)
 		Dim sz = DefaultSize()
-		Control(parent, text, 100, 100, sz.Width, sz.Height)
+		init(parent, text, 100, 100, sz.Width, sz.Height)
 	End Sub
 
 	Sub Control(text As String, left As Long, top As Long, width As Long, height As Long)
-		This.text = text
-		bkColor = DefaultBackColor
+		init(Nothing, text, left, top, width, height)
 	End Sub
 
 	Sub Control(parent As Control, text As String, left As Long, top As Long, width As Long, height As Long)
+		init(parent, text, left, top, width, height)
+	End Sub
+
+Private
+
+	Sub init(parent As Control, text As String, left As Long, top As Long, width As Long, height As Long)
 		This.parent = parent
-		Control(text, left, top, width, height)
-	End Sub
+'		CreateControl()
+	End Sub
+	
 
 	'---------------------------------------------------------------------------
 	' Destractor
-
+Public
 	Virtual Sub ~Control()
 		If Not Object.ReferenceEquals(wnd, Nothing) Then
@@ -398,6 +406,5 @@
 
 	Virtual Function DefaultSize() As Size
-		Dim s As Size(300, 300)
-		Return s
+		Return New Size(300, 300)
 	End Function
 
@@ -411,12 +418,15 @@
 	' Protected Methods
 	Virtual Sub CreateHandle()
+		Debug
+		If Not Object.ReferenceEquals(wnd, Nothing) Then
+			If wnd.HWnd <> 0 Then
+				Exit Sub
+			End If
+		End If
+		
 		Dim createParams = CreateParams()
 		Dim gch = System.Runtime.InteropServices.GCHandle.Alloc(This)
 		TlsSetValue(tlsIndex, System.Runtime.InteropServices.GCHandle.ToIntPtr(gch) As VoidPtr)
 		With createParams
-			Dim hwndParent = 0 As HWND
-			If Not Object.ReferenceEquals(parent, Nothing) Then
-				hwndParent = parent.Handle
-			End If
 			Dim pText As PCTSTR
 			If String.IsNullOrEmpty(text) Then
@@ -427,15 +437,17 @@
 
 			If CreateWindowEx(.ExStyle, atom As ULONG_PTR As PCSTR, pText, .Style, _
-				CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
-				hwndParent, 0, hInstance, 0) = 0 Then
+				.X, .Y, .Width, .Height, _
+				.Parent, 0, hInstance, 0) = 0 Then
 				' Error
 				Dim buf[1023] As TCHAR
 				wsprintf(buf, ToTCStr(Ex"Control: CreateWindowEx failed. Error code: &h%08X\r\n"), GetLastError())
 				OutputDebugString(buf)
+
+				gch.Free()
 '				Debug
 				ExitThread(0)
 			End If
 		End With
-		gch.Free()
+		
 	End Sub
 
@@ -475,4 +487,8 @@
 				Case WM_DESTROY
 					OnHandleDestroyed(System.EventArgs.Empty)
+
+				Case WM_LBUTTONDOWN
+					Goto *ButtonDown
+*ButtonDown
 				Case Else
 					DefWndProc(m)
@@ -521,5 +537,5 @@
 	End Sub
 
-	Virtual Sub OnPaintBackground(e As PaintEventArgs) : End Sub
+'	Virtual Sub OnPaintBackground(e As PaintEventArgs) : End Sub
 	Virtual Sub OnEnabledChanged(e As System.EventArgs) : End Sub
 	Virtual Sub OnBackColorChanged(e As System.EventArgs) : End Sub
@@ -582,4 +598,9 @@
 			.Style = WS_OVERLAPPEDWINDOW
 			.ExStyle = WS_EX_APPWINDOW
+			.Caption = String.Empty
+			.X = 0
+			.Y = 0
+			.Width = 0
+			.Height = 0
 		End With
 	End Sub
@@ -608,4 +629,7 @@
 			rThis.wnd = New ActiveBasic.Windows.WindowHandle(hwnd)
 			SetWindowLongPtr(hwnd, GWLP_THIS, gchValue)
+		ElseIf msg = WM_NCDESTROY Then
+			Dim gch = System.Runtime.InteropServices.GCHandle.FromIntPtr(GetWindowLongPtr(hwnd, GWLP_THIS))
+			 gch.Free()
 		End If
 
