Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does anyone have a code snippet for doing this in Visual Studio.Net 20

Status
Not open for further replies.

piscis

Programmer
Jun 26, 2003
29
PR
Gentleman:

Does anyone have a code snippet for doing this in Visual Studio.Net 2003?

At form1 on Button1_Click I need to temporarily copy a bitmap (found at installation folder) reduce its size to 125 Width to 175 Height and place it on form2 centered inside panel1?

Here is the tricky part, panel1 is only one of 18 therefore if panel1 has a bitmap already in it then panel2 must be the one receiving the bitmap, so on and so forth.

Finally: On Button2_Click located on form2 all placed bitmaps must be deleted.


Thanks everyone
 
A much easier approach is to create the panel only when you need it at runtime and at the same time assign the bitmap to it. This way you don't have to worry about which panel to use, etc.

For example:

Code:
Public Sub Add()
  '
  Dim P As Panel
  P = New Panel
  P.Location = 'the location to use
  P.Size = New Size(125, 175)
  P.BackgroundImage = 'your code for getting the bitmap
  'set any other property of the panel if you wish
  Me.Controls.Add(P)
  '
End Sub

By adjusting the snippet you can set all properties of the panel, add the bitmap to it and display it on the form.

To remove all bitmaps, you simply remove all panels:

Code:
Dim Ctl As Control

For Each Ctl in Me.Controls
  If TypeOf Ctl Is Panel then
    Me.Controls.Remove(Ctl)
    Ctl.Dispose()
  End If
Next

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Ruffnekk:

I like your idea the only problem I see is to figure out how would you know the location for placing the second panel or the third?

Any ideas?

Andy

Puerto Rico

 
There are some options here. You could dock the panel to the top for example. This will automatically display the panels from top to bottom. Another option is to declare to (global) variables to store the x and y coordinates of the last panel's location. Every time you add a panel to the form, you would set x and y to increment as needed.

It gets a little trickier if you want to display, let's say 3 horizontal and 6 vertical panels. A plain English description of the procedure would be:

Start off with x = 0 and y = 0. This will set the location of the first panel to (0,0): P.Location = New Point(x, y)
After adding this panel, increment x with 125. The next panel would then be placed at (125, 0). However, we only want 3 panels next to each other, so if x > 250 then we set x = 0 again and increment y with 175. The fourth panel would thus be placed at (0, 175).

In code this would roughly translate to:

Code:
'
'Code to add the panel here first
'
x += 125

If x > 250 Then
  x = 0
  Y += 175
End If
'
'

Just make sure x and y are declared form-wide, to ensure the values will be 'remembered' after the method ends.

Regards, Ruffnekk
---
Is it my imagination or do buffalo wings taste just like chicken?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top