create picturbox and give location cocordinates at run time heres my code

vbMarkO

Centurion
Joined
Aug 19, 2005
Messages
157
This will move one to a given location

pic2.Location = New System.Drawing.Point(175, 252)
pic2.Visible = True


But I want to create them and I would like assign the locations based 2 things

1. Mouse click ......
2. but would also like doing this using variables o an array of coordinate integers

I tried this to create ...

Code:
Dim pct As New PictureBox()

        pct.Location = New System.Drawing.Point(177, 228)
        pct.Size = New System.Drawing.Size(5, 5)
        pct.BackColor = Color.Red
        pct.BringToFront()

        Me.Controls.Add(pct)
but I couldnt figure out how to ad the handler or assign address of for a picture box

not evn sur if this is right ... I sort of think Im on the right track though


This really worked fin with the button event ... I clicked on it and the red spot went right wer I wanted it to ... I know its not high end drawing stuff but I dont know about that and this is a great work around for me ..

I just need to figure out how to assign the coordinates and crate the picture boxes

or get the mouse click coordinate and assign it

The idea is to have multiple pictureboxs acting as my littl red dots to mark my map ... sure looks like a grat idea


All help appreciated ....

vbMarkO
 
Yes ..... but I am not sure how todo this this is why I cam up with that I have been searching fo just putting a point at the location but th only thing close I found was in C# ... I know its clos but I couldnt get it to work ... could you point me to a simple VB example or show an example?
 
I did find this but I get an eror but it oes seem to be what I might want

what do you think? Th error is with the e.graphics.drawimageun .... un something cant rember her is the code

Dim bm as new Bitmap(1,1)

bm.SetPixel(0,0,Color.Red)

e.Graphics.DrawImageUnscaled(bm,<xPosition>,<yPosition>)

Oh yeah unscaled ...
anyway
I tried to modify it ... but that didnt work

I tried to modify it to this .. but I am not sure this is right well I know its not as its not doing anything
Also this is within a Picturebpox1_MouseClick

Dim mPen As New Bitmap(1, 1)
mPen.SetPixel(0, 0, Color.Red)
Dim g As Graphics
g = PictureBox1.CreateGraphics
g.DrawImageUnscaled(mPen, e.X, e.Y)

Ok ... anythoughts
 
Hey that code is working ... its just so small I didnt see it

I have a pictur box with an image in it ... perhaps I should just put the image on the form and set the picbox color to transparent Yes?

Cool ... it at least is starting to do something
 
Ok the post was about making picboxes on the fly and the mouse click coordinates I hav now Solved that

and the code I showed allowing me to put a single red pixel works but the pixel is so small it wont work ....

I woujld lik to continue to play with that or see som help toward that or even better placing an icon like a red arrow or something like that at my coordinate

.... I am now looking at modifying the code I am about to show which works great by the way ... to p-lace this programatically outsode of a mouse click but to simply place them based on addresses I pull from data that is placed into arrays ...

The addresses I howed in another post of police calls in my area ... I am going to mark them on a map ... each call typ having a different color to show viloent crimes to simple traffic stops.
For the first time I really see this happening


Ok one last thought ... I do agree that to have a pixle or icon would be best .... SO I am open to example of how I might do this or at least see a working example of how to place multiple icons or plot points on my image map


Here is my Working code .... making this htread sort o resolved though I still want to learn more about the othe approach as I only se my code as a work around

Code:
 Dim PB As New PictureBox

        With PB
            .Location = New System.Drawing.Point(e.X, e.Y)
            .Size = New Size(5, 5)
            .BackColor = Color.Red
            .BringToFront()
        End With

        Me.PictureBox1.Controls.Add(PB)

        AddHandler PB.Click, AddressOf MyPicClicked


        
    End Sub

    Private Sub MyPicClicked(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' Additional code here for clcik event ... but its not needed
        ' the result of the other code works great it places little red picboxes but 
        ' they look like dots ... its not drawing but its functional
    End Sub
 
Back
Top