From: Webbiz on 4 Feb 2009 15:25 Greetings. I'm really trying to wrap my mind around this task. Say you have a form with 1 picturebox. We will call this picMain. Say you want to add additional, smaller height pictureboxes to the form during runtime. These are picSmall. ================= When the program starts, you see picMain covering the whole form. You can select a menu item or click a button (either way) and a new picturebox will show up directly below picMain with the same width as picMain but only a fraction of the height. This causes picMain to adjust its height to accomodate the new picSmall below it inside the form. If I click to add another one, a new picSmall will show up just below picMain (and of course above the last picSmall). Therefore, once again picMain must adjust its height to accomodate the new picSmall picturebox. Each time I click the button (or select the menu item), picMain will shrink in height to accomodate a new picSmall, that will stack on top of the previous picSmall pictureboxes. A mechanicism to close each picSmall picturebox (you cannot close picMain as it should always be visible) is incorporated (for simplicity or testing, say a right-click inside the respective picSmall will close it). When any picSmall picturebox is closed, the remaining picSmall pb's will adjust so they continue to stack onto each other, with ONLY picMain adjusting in actual size (height) to fill in the new available empty space left by the deleted picSmall. ================== I'm trying to figure out the BASICS of creating new picSmall pictureboxes in code. I'm thinking that I only need to have two pictureboxes on my form during design time. One is picMain and one picSmall. Then in code, I suspect I should be able to make duplicates of picSmall, with each having the same properties, methods, etc., much like a Class object. How is this done if possible? Or do I have to create an array of picSmall pictureboxes, say 5 or 10 of them, whatever my maximum will be, during design time, and then enable/disable them (visible true/false) during run-time? I'd like to be able to create as many picSmall as I like during run-time without knowing how many the user will want to place on the form. I'm still very green when it comes to this kind of stuff, so please be easy on me. Thanks. Webbiz
From: James Hahn on 4 Feb 2009 16:04 The best solution is an array of controls (picSmall), but you do not need to create all of them at design time - you can create them at run time and add them to the array. You get the same set of properties by default, so all you will need to adjust is the top and the height, as per this example: http://www.vbexplorer.com/VBExplorer/vb_feature/april2000/april2000.asp "Webbiz" <nospam(a)formethanks.com> wrote in message news:1Rmil.5756$Bk7.5711(a)newsfe02.iad... > Greetings. > > I'm really trying to wrap my mind around this task. > > Say you have a form with 1 picturebox. We will call this picMain. > > Say you want to add additional, smaller height pictureboxes to the form > during runtime. These are picSmall. > > ================= > > When the program starts, you see picMain covering the whole form. > > You can select a menu item or click a button (either way) and a new > picturebox will show up directly below picMain with the same width as > picMain but only a fraction of the height. This causes picMain to adjust > its height to accomodate the new picSmall below it inside the form. > > If I click to add another one, a new picSmall will show up just below > picMain (and of course above the last picSmall). Therefore, once again > picMain must adjust its height to accomodate the new picSmall picturebox. > > Each time I click the button (or select the menu item), picMain will > shrink in height to accomodate a new picSmall, that will stack on top of > the previous picSmall pictureboxes. > > A mechanicism to close each picSmall picturebox (you cannot close picMain > as it should always be visible) is incorporated (for simplicity or > testing, say a right-click inside the respective picSmall will close it). > > When any picSmall picturebox is closed, the remaining picSmall pb's will > adjust so they continue to stack onto each other, with ONLY picMain > adjusting in actual size (height) to fill in the new available empty space > left by the deleted picSmall. > > ================== > > I'm trying to figure out the BASICS of creating new picSmall pictureboxes > in code. I'm thinking that I only need to have two pictureboxes on my form > during design time. One is picMain and one picSmall. Then in code, I > suspect I should be able to make duplicates of picSmall, with each having > the same properties, methods, etc., much like a Class object. > > How is this done if possible? Or do I have to create an array of picSmall > pictureboxes, say 5 or 10 of them, whatever my maximum will be, during > design time, and then enable/disable them (visible true/false) during > run-time? > > I'd like to be able to create as many picSmall as I like during run-time > without knowing how many the user will want to place on the form. > > I'm still very green when it comes to this kind of stuff, so please be > easy on me. > > Thanks. > > Webbiz > > >
From: Webbiz on 4 Feb 2009 16:22 I've got the page up and looking it over right now. I'm going to assume that what I'm about to learn can be placed into a Class module. Why? Because I'm thinking that what would make this work really cool is if each time I wanted to add a new picSmall (create a new instance of the class), it will not only add the control, but it will self-adjust its size to match the width of the picMain, will also cause picMain to shrink in height. Will also know how to place itself directly beneath picMain, and will know how to clean up when destroyed, such as resizing picMain and moving any existing picSmall to take up the empty space, etc. Thanks James. "James Hahn" <jhahn(a)yahoo.com> wrote in message news:e5nnqwwhJHA.1388(a)TK2MSFTNGP06.phx.gbl... > The best solution is an array of controls (picSmall), but you do not need > to create all of them at design time - you can create them at run time and > add them to the array. You get the same set of properties by default, so > all you will need to adjust is the top and the height, as per this > example: > http://www.vbexplorer.com/VBExplorer/vb_feature/april2000/april2000.asp > > > "Webbiz" <nospam(a)formethanks.com> wrote in message > news:1Rmil.5756$Bk7.5711(a)newsfe02.iad... >> Greetings. >> >> I'm really trying to wrap my mind around this task. >> >> Say you have a form with 1 picturebox. We will call this picMain. >> >> Say you want to add additional, smaller height pictureboxes to the form >> during runtime. These are picSmall. >> >> ================= >> >> When the program starts, you see picMain covering the whole form. >> >> You can select a menu item or click a button (either way) and a new >> picturebox will show up directly below picMain with the same width as >> picMain but only a fraction of the height. This causes picMain to adjust >> its height to accomodate the new picSmall below it inside the form. >> >> If I click to add another one, a new picSmall will show up just below >> picMain (and of course above the last picSmall). Therefore, once again >> picMain must adjust its height to accomodate the new picSmall picturebox. >> >> Each time I click the button (or select the menu item), picMain will >> shrink in height to accomodate a new picSmall, that will stack on top of >> the previous picSmall pictureboxes. >> >> A mechanicism to close each picSmall picturebox (you cannot close picMain >> as it should always be visible) is incorporated (for simplicity or >> testing, say a right-click inside the respective picSmall will close it). >> >> When any picSmall picturebox is closed, the remaining picSmall pb's will >> adjust so they continue to stack onto each other, with ONLY picMain >> adjusting in actual size (height) to fill in the new available empty >> space left by the deleted picSmall. >> >> ================== >> >> I'm trying to figure out the BASICS of creating new picSmall pictureboxes >> in code. I'm thinking that I only need to have two pictureboxes on my >> form during design time. One is picMain and one picSmall. Then in code, I >> suspect I should be able to make duplicates of picSmall, with each having >> the same properties, methods, etc., much like a Class object. >> >> How is this done if possible? Or do I have to create an array of picSmall >> pictureboxes, say 5 or 10 of them, whatever my maximum will be, during >> design time, and then enable/disable them (visible true/false) during >> run-time? >> >> I'd like to be able to create as many picSmall as I like during run-time >> without knowing how many the user will want to place on the form. >> >> I'm still very green when it comes to this kind of stuff, so please be >> easy on me. >> >> Thanks. >> >> Webbiz >> >> >> >
From: Webbiz on 4 Feb 2009 20:05 Here is what I've done (and yes, it does not work). I created a CLASS and this is its Initialization code: Private Sub Class_Initialize() 'Declare my control Dim ctlPictureBox As Control 'Add a new picturebox to the Control Collection Set ctlPictureBox = frmChart.Controls.Add("VB.Picturebox", "picIndWin", frmChart) 'Set its initial height as 10% of the overall container form's height ctlPictureBox.height = frmChart.height * 0.1 'Decrease the main picturebox height by the size of the new picturebox being added frmChart.pctChart.height = frmChart.height - ctlPictureBox.height 'Move newly created picturebox just under main picturebox ctlPictureBox.Top = frmChart.pctChart.height + 1 ctlPictureBox.Left = frmChart.pctChart.Left ctlPictureBox.width = frmChart.pctChart.width 'Now make the picturebox show up on the form ctlPictureBox.Visible = True End Sub Then in the main program code for the pctChart (picturebox for the chart), under the KeyUp method, I have it run this when you press the "I" key: Public Sub AddIndicatorWindow() Dim IndWin As cIndWindows Set IndWin = New cIndWindows End Sub Two problems arises: 1. The pctChart picturebox does not appear to resize and remains covering the form from top to bottom. 2. When I didn't see the pctChart resize and therefore didn't see my new picturebox show up below it (because apparently pctChart didn't resize, thus probably covering it), I tried to hit the "I" key and it gave me an error: Run-time error '727': There is already a control with the name 'picIndWin'. Why do you think my pctChart is not resizing? How do I change this so that I can add additional picIndWin each time I press my "I" key? Thanks. Webbiz "Webbiz" <nospam(a)formethanks.com> wrote in message news:1Rmil.5756$Bk7.5711(a)newsfe02.iad... > Greetings. > > I'm really trying to wrap my mind around this task. > > Say you have a form with 1 picturebox. We will call this picMain. > > Say you want to add additional, smaller height pictureboxes to the form > during runtime. These are picSmall. > > ================= > > When the program starts, you see picMain covering the whole form. > > You can select a menu item or click a button (either way) and a new > picturebox will show up directly below picMain with the same width as > picMain but only a fraction of the height. This causes picMain to adjust > its height to accomodate the new picSmall below it inside the form. > > If I click to add another one, a new picSmall will show up just below > picMain (and of course above the last picSmall). Therefore, once again > picMain must adjust its height to accomodate the new picSmall picturebox. > > Each time I click the button (or select the menu item), picMain will > shrink in height to accomodate a new picSmall, that will stack on top of > the previous picSmall pictureboxes. > > A mechanicism to close each picSmall picturebox (you cannot close picMain > as it should always be visible) is incorporated (for simplicity or > testing, say a right-click inside the respective picSmall will close it). > > When any picSmall picturebox is closed, the remaining picSmall pb's will > adjust so they continue to stack onto each other, with ONLY picMain > adjusting in actual size (height) to fill in the new available empty space > left by the deleted picSmall. > > ================== > > I'm trying to figure out the BASICS of creating new picSmall pictureboxes > in code. I'm thinking that I only need to have two pictureboxes on my form > during design time. One is picMain and one picSmall. Then in code, I > suspect I should be able to make duplicates of picSmall, with each having > the same properties, methods, etc., much like a Class object. > > How is this done if possible? Or do I have to create an array of picSmall > pictureboxes, say 5 or 10 of them, whatever my maximum will be, during > design time, and then enable/disable them (visible true/false) during > run-time? > > I'd like to be able to create as many picSmall as I like during run-time > without knowing how many the user will want to place on the form. > > I'm still very green when it comes to this kind of stuff, so please be > easy on me. > > Thanks. > > Webbiz > > >
From: Ivar on 4 Feb 2009 22:04 Sounds like overkill Is this something like what you want On a form put a picturebox (PicMain) and a Picturebox (PicSmall) and a commandButton(Command1) Set the Index of PicSmall to 0 (Use the Unload method to remove pictureboxes) Then Paste this code Then click the command button :-) Ivar Option Explicit Private Sub Command1_Click() Dim I As Integer I = PicSmall.Count PicMain.Height = PicMain.Height - 20 * _ Screen.TwipsPerPixelY Load PicSmall(I) With PicSmall(I) ..Move PicMain.Left, _ PicMain.Top + PicMain.Height + 3 * Screen.TwipsPerPixelY _ , PicMain.Width, 20 * Screen.TwipsPerPixelY ..Visible = True ..ZOrder ..AutoRedraw = True ..BackColor = vbWhite * Rnd PicSmall(I).Print "I am " & .Name & _ ": My Index = " & .Index End With End Sub Private Sub Form_Activate() PicMain.Move 10, 10, Me.Width * 0.8, Me.Height * 0.9 Command1.Move Me.Width * 0.8, 10, Me.Width * 0.1 PicSmall(0).Visible = False PicMain.Print "I am " & PicMain.Name End Sub
|
Next
|
Last
Pages: 1 2 3 Prev: EM_CHARFROMPOS in RichEdit Next: Printing ALL content in large PictureBox which has scrollbars |