From: Webbiz on 5 Feb 2009 17:28 Okay. I can see this as doable. Because in reality, I may only be dealing with 4 of these maximum at any given time. Yes. Good comment. Thanks. It gives me pause for thought. :-) Webbiz "James Hahn" <jhahn(a)yahoo.com> wrote in message news:eEPyLD4hJHA.1168(a)TK2MSFTNGP05.phx.gbl... > There's no need to delete unused controls in the array - just set them to > not visible and adjust the .top of any array elements that are lower in > the 'stack'. When traversing the array, ignore elements that are not > visible. When adding new elements first check to see if there are any > currently set to not visible, and re-use one of them, if available. The > .top property is setting the display order, so if you juggle that > correctly for the delete process (and assuming that the add process simply > positions the new control at the top of the 'stack', as per the sample > code) then everything falls into place and the actual index values don't > really matter, and do not need to change. > > "Webbiz" <nospam(a)formethanks.com> wrote in message > news:4fvil.12485$Yz.11849(a)newsfe01.iad... >> I'm just not sure how this should be managed. >> >> When a picIndWin is created, it is sized. The main picMain is resized to >> accomodate the new picIndWin. >> >> But say I add a couple more, and then decide to delete one of them in the >> middle. >> >> I have to move around those still active to fill the gap left. >> >> Say it is picIndWin(3) that I deleted, and 0, 1, 2, 4, 5 still remain. >> >> If I rely on picIndWin.count to get the next index, it will fail at this >> point. >> >> And I imagine that I'll need to shift the higher index controls to fill >> in the missing one, right? >> >> Or do I leave gaps in the array? >> >> It's just not clear to me how to juggle these dynamically created >> picIndWin controls. >> >> One thing for sure, if the index references change, this would muck up >> the reference that the indicator code is using to draw on them. For >> example, if I create picIndWin(2) to draw lines based on some code I >> have, and for some reason the index 2 is changed, the code would have to >> know this and adjust to it. In other words, there cannot be a break in >> connection between the code that is drawing and the picbox that it is >> drawing to. >> >> So how would I manage the adding and deleting of these picIndWin and >> still maintain proper connection to drawing code? >> >> Thanks. >> >> Webbiz >
From: Webbiz on 5 Feb 2009 17:42 Yes. A few months ago I took that code and saved it on my drive for study. For some reason, it was incomplete when I came back as if some of my files got messed up. Since I did not know the subject keywords, I spent too much time looking for that code again and gave up. I'll try not to lose this one. ;^b Thanks. On another note, prior to looking at this code, I just want to make this comment. Let's suppose I have code (which I do) that draws my price bars on the pctChart picbox. To reference the real estate of this picbox, I simply reference some distance from 0 to the width, 0 to the height. But if I add an indicator to this same picbox, I have to make sure that the routine that draws the price bars ALSO subtracts the height of this indicator space. Anywhere in my massive code that refers to this pctChart picbox by doing math on the height or width would also have to have modifications to account for my changing the height/width reference points so my indicator areas are not drawn over by them. That just seems like a real headache. So like I mentioned in another message, I could leave all that existing code (and there is so much code relying on other code) alone by simply adding a new drawing space with its own coordinates. Existing code can be left alone, and I simply create my indicator code to draw on its own picbox. Do more trying to make sure that code that references the pctChart picbox height and width doesn't also have to have size subtracted from them based on how many indicators are added and what their individual heights are. Also, I want the ability to size each indicator window individually of each other and the chart window, and perhaps allow the user to change their order from top to bottom. It just seems more flexible to give each their own space for manipulation purposes and avoid also changing code that other code is dependant on. Thanks again. :-) Webbiz "Larry Serflaten" <serflaten(a)usinternet.com> wrote in message news:eKwcr85hJHA.448(a)TK2MSFTNGP05.phx.gbl... > > "Webbiz" <nospam(a)formethanks.com> wrote >> Currently, >> when I want to add an indicator to the bottom of the chart, I am actually >> stealing a portion of the bottom of this picturebox to draw the >> indicator, >> thus having to make size adjustments within my code so that my price >> chart >> will not over write my indicator window that shares the same picturebox. >> Personally, I find this to be lame and not effective. Instead, if each >> indicator I add to the bottom of the chart can be its own picturebox, I >> won't have to keep track of what real estate is available on the main >> chart >> picturebox (pctChart). > > We went over this last year. I think one time in March and again in > September. But the laws of physics have not changed since then. > In order to move your indicators about, you have to keep track of them. > They don't know how to keep track of themselves, you have to add code > to do all their 'thinking'. > > When you write the code to do the manipulations, you have the majority > of the work done, and therefore do not need Picture boxes to keep > things separate. They will only cause you to add more effort to load > and hide them as needed. > > You indicated you have to make size adjustments in your code to > avoid overwriting the indicator areas, but that is not necessary. > The area you draw on is completely under your control, if you want > your chart to remain a constant size even when things are added, > then make it stay the same size. > > Here is a quick example of adding colored bars to the bottom of > the form. With just minimal code you can add (left click the form) > and remove (right click on a bar) them at will and they fill whatever > space is available on the form. All the while you add and remove > those bars, the *_chart code does not change_*, yet it adjusts to > make room for the bars..... > > HTH > LFS > > ' Paste the following code to a new form: > > Option Explicit > Private Panes As Collection > Private RePaint As Long > > Private Sub Form_Load() > Set Panes = New Collection > End Sub > > Private Sub Form_Paint() > DrawChart > DrawPanes > End Sub > > Private Sub Form_Resize() > ' Adjust canvas > Me.Scale (0, 0)-(1000, 1000 + (200 * Panes.Count)) > > 'Catch Downsizing > If (Width * Height) < RePaint Then > Form_Paint > End If > RePaint = (Width * Height) > End Sub > > Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As > Single, Y As Single) > Select Case Button > Case vbLeftButton > AddPane > Case vbRightButton > RemovePane Y > End Select > End Sub > > Private Sub DrawChart() > Dim X As Long > 'No size adjustments, its always the same code > Me.Line (0, 0)-(1000, 1000), vbWhite, BF > Me.DrawWidth = 3 > For X = 100 To 400 Step 100 > Me.Line (X, X)-(1000 - X, 1000 - X), vbBlack, B > Next > Me.DrawWidth = 1 > End Sub > > Private Sub DrawPanes() > Dim idx As Long, top As Long > top = 1000 > For idx = 1 To Panes.Count > Me.Line (0, top)-(1000, top + 200), Panes(idx), BF > top = top + 200 > Next > End Sub > > Private Sub AddPane() > Static K As Long > Panes.Add QBColor(K) > K = (K + 1) And 15 > Form_Resize > Form_Paint > End Sub > > Private Sub RemovePane(ByVal Y As Long) > Dim idx As Long > idx = (Y - 800) \ 200 > If idx < 1 Then Exit Sub > Panes.Remove idx > Form_Resize > Form_Paint > End Sub > > >
From: Larry Serflaten on 5 Feb 2009 19:55 "Webbiz" <nospam(a)formethanks.com> wrote > Let's suppose I have code (which I do) that draws my price bars on the > pctChart picbox. To reference the real estate of this picbox, I simply > reference some distance from 0 to the width, 0 to the height. > > But if I add an indicator to this same picbox, I have to make sure that the > routine that draws the price bars ALSO subtracts the height of this > indicator space. As I said before, that is a false assumption. Rather than change the drawing code, change the canvas that you are drawing on. Specifically, make it taller to add room for more indicators. You do not need to change the size of the form to change the drawing surface. You do it all the time when you adjust the ScaleMode property. Using Twips gives you some dimensions (ScaleWidth and ScaleHeight) and using Pixels gives you other dimensions, even when the size of the form remains constant. Likewise you can use a custom scalemode, as was shown in the earlier post. > Also, I want the > ability to size each indicator window individually of each other and the > chart window, and perhaps allow the user to change their order from top to > bottom. And, that will be 'smarts' that you will have to add via code. You will need to add code whether you use pictureboxes or not. It may be easier to think of pictureboxes being separate entities, but they are actually more effort. But, its not going to be that much more (if handled properly), so if you're set on using pictureboxes, then go for it! I'm a bit pressed for time at the moment, but I'll see if I can't post something using pictureboxes tomorrow.... LFS
From: Larry Serflaten on 6 Feb 2009 10:09 "Larry Serflaten" <serflaten(a)usinternet.com> wrote > > Also, I want the > > ability to size each indicator window individually of each other and the > > chart window, and perhaps allow the user to change their order from top to > > bottom. > > I'm a bit pressed for time at the moment, but I'll see if I can't post something > using pictureboxes tomorrow.... I've quickly put something together that does as you say. I've added comments, but its still a little rough. See if you can gather how it was done by looking at what it does, and then studying the code that does that part (and I do mean look at individual parts, creating, hiding, up size, down size, redrawing the display, etc... look at them as individual tasks.) In a new form add 1 picturebox and set its Appearance to 0 (Flat) and its Index property to 0. Then paste in the code below and try it out..... Have fun! LFS Option Explicit Private Panes As Collection Private PixelHeight As Long Private Sub Form_Load() ' Initialize collection / Picturebox Set Panes = New Collection Picture1(0).ScaleMode = vbPixels ' Show picturebox ResizeDisplay End Sub Private Sub Form_Resize() ResizeDisplay End Sub Private Sub Picture1_Paint(Index As Integer) If Index = 0 Then ' chart ClickMessage Else ' panes DrawButtons Index End If End Sub Private Sub Picture1_MouseDown(Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single) If Index = 0 Then ' Chart hit AddPane Else ' Pane hit ClickButton Index, X End If End Sub Sub ResizeDisplay() Dim tot As Long, cht As Long, hgt As Long, pic ' Tally sizes needed (in pixels) For Each pic In Panes tot = tot + Val(pic.Tag) Next ' Get Current form height (in pixels) Me.ScaleMode = vbPixels PixelHeight = Me.ScaleHeight ' Find Chart height cht = PixelHeight - tot ' Adjust scale Me.Scale (0, 0)-(1000, 1000 + (tot * 1000 / cht)) ' Reposition panes (from bottom up) tot = Me.ScaleHeight For pic = Panes.Count To 1 Step -1 ' Convert desired pixels to scalemode hgt = Me.ScaleY(Panes(pic).Tag, vbPixels, Me.ScaleMode) ' Find top tot = tot - hgt ' Avoid error If tot < 1 Then MsgBox "Display limits reached." Exit Sub End If ' Position pane Panes(pic).Move 0, tot, 1000, hgt Next ' Reposition chart (remainder of form) Picture1(0).Move 0, 0, 1000, tot ' Draw chart ClickMessage End Sub Sub ClickButton(Index, ByVal X) Dim pic As PictureBox, itm ' Calc button hit Set pic = Picture1(Index) X = X \ 40 ' Act on button hit Select Case X Case 0 ' + (Increase height) pic.Tag = pic.Tag + 10 Case 1 ' - (Decrease height) If Val(pic.Tag) > 20 Then pic.Tag = pic.Tag - 10 End If Case 2 ' Up (move up in Panes collection) For itm = Panes.Count To 1 Step -1 If Panes(itm).Index = Index Then If itm > 1 Then Panes.Remove itm Panes.Add Picture1(Index), , itm - 1 Exit For End If End If Next Case 3 ' Dn (move down in Panes collection) For itm = Panes.Count To 1 Step -1 If Panes(itm).Index = Index Then If itm < Panes.Count Then Panes.Remove itm Panes.Add Picture1(Index), , , itm Exit For End If End If Next Case 4 ' Hide (unload, and remove from Panes) For itm = Panes.Count To 1 Step -1 If Panes(itm).Index = Index Then Panes.Remove itm Unload Picture1(Index) Exit For End If Next End Select ' Show change ResizeDisplay End Sub Sub ClickMessage() Dim msg As String ' Draw Chart (just a click message for demo) msg = "Click here to add more panes." With Picture1(0) .Cls Picture1(0).PSet ((.ScaleWidth - .TextWidth(msg)) / 2, (.ScaleHeight - .TextHeight(msg)) / 2), vbWhite Picture1(0).Print msg End With End Sub Sub AddPane() Dim free As Long Static klr As Long ' Find next free index On Error GoTo Found Do While Picture1(free).Visible free = free + 1 Loop Found: On Error GoTo 0 ' Create new pane Load Picture1(free) Picture1(free).Visible = True ' Save desired pixel height Picture1(free).Tag = 30 ' Convert height to form scale Picture1(free).Height = Me.ScaleY(30, vbPixels, Me.ScaleMode) ' Add color for visual ID (demo) klr = (klr And 7) + 1 Picture1(free).BackColor = QBColor(klr + 7) ' Add to collection / adjust display Panes.Add Picture1(free) ResizeDisplay End Sub Sub DrawButtons(Index) Dim X ' Print buttons to panes Picture1(Index).PSet (3, 3), Picture1(Index).Point(3, 3) Picture1(Index).Print " + - UP DN HIDE" For X = 40 To 200 Step 40 Picture1(Index).Line (X, 0)-Step(0, Picture1(Index).ScaleHeight), vbBlack Next End Sub
First
|
Prev
|
Pages: 1 2 3 Prev: EM_CHARFROMPOS in RichEdit Next: Printing ALL content in large PictureBox which has scrollbars |