From: Eduardo on 10 Sep 2009 23:54 Karl E. Peterson escribi�: >> You already have the reference, it's in the Parent property. > > Hmmmm, ... > > Y'know, I don't recall using *that* one together with WithEvents. Of course, you > can't sink any custom events using it, just the standard ones. (Because you have to > declare As Form instead of As Form1 since you'd never know the latter, more specific > interface.) > > That's kinda cool. It definitely alters my view of the utility of invisible > controls. This was my quick/dirty test: > > Private WithEvents m_Parent As Form > > Private Sub m_Parent_MouseMove(Button As Integer, Shift As Integer, X As Single, > Y As Single) > Debug.Print X, Y > End Sub > > Private Sub UserControl_ReadProperties(PropBag As PropertyBag) > If Ambient.UserMode Then > Set m_Parent = UserControl.Parent > End If > End Sub Exactly > There aren't any serious ones. I mean, you do get the added system overhead of > another window, which to the Ancient Byte Counters in the crowd is every bit to be > avoided as having an unused array element. Mostly it's an "elegance" argument, I > think. The phrase "added system overhead" makes me think in languages with "dot" in their names, but... nowadays a little window is not so much overhead, and we have it from VB3 (or VB1, I don't know) with Windows 3. But yes, it's overhead. These features may be not very serious ones, but VB is BASIC, B of Beginners, so the language must be as easy as possible for beginners.
From: Eduardo on 10 Sep 2009 23:57 Karl E. Peterson escribi�: > Eduardo wrote: >> I don't get it... so you want to go back and have to write everything by >> code again? > > Not necessarily again. (That's why so many of us were *so* pissed at MSFT with the > VFred fiasco, afterall! <g>) But yeah, we'd like to have *total* control over the > source code. Yes, I agree with the *total* control, but I want both features: total control and easy to use. That's why VB (our) is a language good for beginners, easy to learn and start programming, and still powerful for advanced programmers.
From: Nobody on 11 Sep 2009 07:48 "Webbiz" <nospam(a)forme.thanks.com> wrote in message news:jcjea59l6vapq76ct8fk3dpnsrpem8u2dr(a)4ax.com... > If I managed the sizing of the different instances (indicators) in the > form's code, why bother than with this custom control? The way I would do it is by making the form manage the space by calling the Move method on the UserControl, and this fires the UserControl's Resize event, which does the actual redrawing to fit in the new size. Example: - Start a new Standard EXE Project. - Go to Project-->Add User Control, and click Open. - Close the UserControl designer window. - Place the UserControl on Form1, and set Index property for the UserControl to 0. - Add Form1 and UserControl code below. This example will draw 12 user controls on a 4x3 grid, and it auto resizes them when the form is resized. It also shows on the form's Caption which control the mouse is over. ' Form1 code Option Explicit Const MAX_CHARTS_COUNT As Long = 12 ' 4 Columns x 3 Rows Private Sub Form_Load() Dim i As Long For i = 1 To MAX_CHARTS_COUNT - 1 Load UserControl11(i) UserControl11(i).Visible = True Next End Sub Private Sub Form_Resize() Dim i As Long Dim X As Long, Y As Long Dim w As Long, h As Long If Me.WindowState = vbMinimized Then Exit Sub End If w = Me.ScaleWidth / 4 h = Me.ScaleHeight / 3 For i = 0 To MAX_CHARTS_COUNT - 1 X = (i Mod 4) * w Y = (i \ 4) * h UserControl11(i).Move X, Y, w, h Next End Sub Private Sub UserControl11_MouseMove(Index As Integer, Button As Integer, _ Shift As Integer, X As Single, Y As Single) Me.Caption = "Mouse is over UserControl " & UserControl11( _ Index).Index & "(" & X & "," & Y & ")" End Sub ' UserControl code Option Explicit Event MouseMove(Button As Integer, Shift As Integer, X As Single, _ Y As Single) Private Sub UserControl_Paint() RedrawMe End Sub Private Sub UserControl_Resize() RedrawMe End Sub Private Sub RedrawMe() UserControl.Cls UserControl.Line (0, 0)-(UserControl.Width, UserControl.Height) UserControl.Line (0, UserControl.Height)-(UserControl.Width, 0) End Sub Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, _ X As Single, Y As Single) RaiseEvent MouseMove(Button, Shift, X, Y) End Sub For improvement, you could put the code that is in "Form_Load" and "Form_Resize" in a class(CChartsManager). This class could have a reference to the form and do what is needed to create and manage the charts. Example: ' New Form1 code Option Explicit Private oChartsManager As New CChartsManager Private Sub Form_Load() oChartsManager.SetForm Me oChartsManager.SetChartsCount 12 End Sub Private Sub Form_Resize() If Me.WindowState <> vbMinimized Then oChartsManager.Resize End If End Sub Private Sub UserControl11_MouseMove(Index As Integer, Button As Integer, _ Shift As Integer, X As Single, Y As Single) Me.Caption = "Mouse is over UserControl " & UserControl11(Index).Index End Sub ' CChartsManager code Option Explicit Private frm As Form Public Enum ChartTypes ctBar ctLine ctPie End Enum Private Type TCharts ChartType As ChartTypes Width As Single Height As Single End Type Private Charts() As TCharts Private ChartsCount As Long Public Sub SetForm(f As Form) Set frm = f End Sub Public Sub SetChartsCount(ByVal Count As Long) Dim i As Long ChartsCount = Count ReDim Charts(1 To ChartsCount) As TCharts For i = 1 To ChartsCount - 1 Load frm.UserControl11(i) frm.UserControl11(i).Visible = True Next End Sub Public Sub Resize() Dim i As Long Dim X As Long, Y As Long Dim w As Long, h As Long w = frm.ScaleWidth / 4 h = frm.ScaleHeight / 3 For i = 0 To ChartsCount - 1 X = (i Mod 4) * w Y = (i \ 4) * h frm.UserControl11(i).Move X, Y, w, h Next End Sub Private Sub Class_Terminate() Set frm = Nothing End Sub Finally, at the page below, look for "Splitter Bar Demo". This demo shows how to let the user resize your controls by using the mouse, just like many other programs. http://www.mvps.org/vbvision/Sample_Projects.htm
From: Karl E. Peterson on 14 Sep 2009 21:25 Eduardo wrote: > Karl E. Peterson escribi�: >> Eduardo wrote: >>> I don't get it... so you want to go back and have to write everything by >>> code again? >> >> Not necessarily again. (That's why so many of us were *so* pissed at MSFT with >> the VFred fiasco, afterall! <g>) But yeah, we'd like to have *total* control >> over the source code. > > Yes, I agree with the *total* control, but I want both features: total > control and easy to use. > > That's why VB (our) is a language good for beginners, easy to learn and > start programming, and still powerful for advanced programmers. Hey, check out the "The UC - Windowless or Not" thread for a pretty stark example of why I don't like to use design time property assignments. <g> -- ..NET: It's About Trust! http://vfred.mvps.org
From: Webbiz on 15 Sep 2009 22:51
Nobody, I'm a tad baffled here. I cannot find where in the UC that you named this puppy UserControl11. When I put the mouse over the UC icon, it's UserControl1. When I go to the UC code itself, it's UserControl1. I even looked at the properties and nothing. Why is it calling itself UserControl11? On Fri, 11 Sep 2009 07:48:49 -0400, "Nobody" <nobody(a)nobody.com> wrote: >"Webbiz" <nospam(a)forme.thanks.com> wrote in message >news:jcjea59l6vapq76ct8fk3dpnsrpem8u2dr(a)4ax.com... >> If I managed the sizing of the different instances (indicators) in the >> form's code, why bother than with this custom control? > >The way I would do it is by making the form manage the space by calling the >Move method on the UserControl, and this fires the UserControl's Resize >event, which does the actual redrawing to fit in the new size. Example: > >- Start a new Standard EXE Project. >- Go to Project-->Add User Control, and click Open. >- Close the UserControl designer window. >- Place the UserControl on Form1, and set Index property for the UserControl >to 0. >- Add Form1 and UserControl code below. > >This example will draw 12 user controls on a 4x3 grid, and it auto resizes >them when the form is resized. It also shows on the form's Caption which >control the mouse is over. > >' Form1 code > >Option Explicit > >Const MAX_CHARTS_COUNT As Long = 12 ' 4 Columns x 3 Rows > >Private Sub Form_Load() > Dim i As Long > > For i = 1 To MAX_CHARTS_COUNT - 1 > Load UserControl11(i) > UserControl11(i).Visible = True > Next > >End Sub > >Private Sub Form_Resize() > Dim i As Long > Dim X As Long, Y As Long > Dim w As Long, h As Long > > If Me.WindowState = vbMinimized Then > Exit Sub > End If > > w = Me.ScaleWidth / 4 > h = Me.ScaleHeight / 3 > For i = 0 To MAX_CHARTS_COUNT - 1 > X = (i Mod 4) * w > Y = (i \ 4) * h > UserControl11(i).Move X, Y, w, h > Next >End Sub > >Private Sub UserControl11_MouseMove(Index As Integer, Button As Integer, _ > Shift As Integer, X As Single, Y As Single) > Me.Caption = "Mouse is over UserControl " & UserControl11( _ > Index).Index & "(" & X & "," & Y & ")" >End Sub > > > > >' UserControl code > >Option Explicit > >Event MouseMove(Button As Integer, Shift As Integer, X As Single, _ > Y As Single) > >Private Sub UserControl_Paint() > RedrawMe >End Sub > >Private Sub UserControl_Resize() > RedrawMe >End Sub > >Private Sub RedrawMe() > UserControl.Cls > UserControl.Line (0, 0)-(UserControl.Width, UserControl.Height) > UserControl.Line (0, UserControl.Height)-(UserControl.Width, 0) >End Sub > >Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, _ > X As Single, Y As Single) > RaiseEvent MouseMove(Button, Shift, X, Y) >End Sub > > > >For improvement, you could put the code that is in "Form_Load" and >"Form_Resize" in a class(CChartsManager). This class could have a reference >to the form and do what is needed to create and manage the charts. Example: > >' New Form1 code > >Option Explicit > >Private oChartsManager As New CChartsManager > >Private Sub Form_Load() > oChartsManager.SetForm Me > oChartsManager.SetChartsCount 12 >End Sub > >Private Sub Form_Resize() > If Me.WindowState <> vbMinimized Then > oChartsManager.Resize > End If >End Sub > >Private Sub UserControl11_MouseMove(Index As Integer, Button As Integer, _ > Shift As Integer, X As Single, Y As Single) > Me.Caption = "Mouse is over UserControl " & UserControl11(Index).Index >End Sub > > > >' CChartsManager code > >Option Explicit > >Private frm As Form > >Public Enum ChartTypes > ctBar > ctLine > ctPie >End Enum > >Private Type TCharts > ChartType As ChartTypes > Width As Single > Height As Single >End Type > >Private Charts() As TCharts >Private ChartsCount As Long > >Public Sub SetForm(f As Form) > Set frm = f >End Sub > >Public Sub SetChartsCount(ByVal Count As Long) > Dim i As Long > > ChartsCount = Count > ReDim Charts(1 To ChartsCount) As TCharts > > For i = 1 To ChartsCount - 1 > Load frm.UserControl11(i) > frm.UserControl11(i).Visible = True > Next > >End Sub > >Public Sub Resize() > Dim i As Long > Dim X As Long, Y As Long > Dim w As Long, h As Long > > w = frm.ScaleWidth / 4 > h = frm.ScaleHeight / 3 > For i = 0 To ChartsCount - 1 > X = (i Mod 4) * w > Y = (i \ 4) * h > frm.UserControl11(i).Move X, Y, w, h > Next >End Sub > >Private Sub Class_Terminate() > Set frm = Nothing >End Sub > > > >Finally, at the page below, look for "Splitter Bar Demo". This demo shows >how to let the user resize your controls by using the mouse, just like many >other programs. > >http://www.mvps.org/vbvision/Sample_Projects.htm > |