Dear All

I`m tring to add a PictureBox to a Form. My code as below.

Dim myPic as new PictureBox
myPic.Location = new Point(10,10)
myPic.Size = new Size(100,100)
FrmMain.Controls.Add(myPic)

Then I got a "ArgumentException" at this line
FrmMain.Controls.Add(myPic)

Somebody help?
Thanks a lot !!

Joey

Re: Dynamic Add Control by Chris

Chris
Sat Oct 02 10:00:43 CDT 2004

FrmMain is an instance of your main Form, not just the name? If you're in
the Form code itself, it should be Me.Controls.Add(...)

-Chris

"Joey Wu" <Joey Wu@discussions.microsoft.com> wrote in message
news:D191F782-B53E-460F-B066-EF3D3D986250@microsoft.com...
> Dear All
>
> I`m tring to add a PictureBox to a Form. My code as below.
>
> Dim myPic as new PictureBox
> myPic.Location = new Point(10,10)
> myPic.Size = new Size(100,100)
> FrmMain.Controls.Add(myPic)
>
> Then I got a "ArgumentException" at this line
> FrmMain.Controls.Add(myPic)
>
> Somebody help?
> Thanks a lot !!
>
> Joey



Re: Dynamic Add Control by JoeyWu

JoeyWu
Sat Oct 02 10:59:02 CDT 2004

Hi~ Chris.

The problem is I wrote those code in another thread......
But now I have another problem.
I added this to my code.

AddHandler myPic.Click, AddressOf myPic_Click

Private Sub myPic_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs)
End Sub

The event "myPic_Click" can be fired but sender is nothing @@"
How can I get this "sender" then I can know which one of PictureBox fire
this event?

Thanks a lot !!

"Chris Tacke, eMVP" wrote:

> FrmMain is an instance of your main Form, not just the name? If you're in
> the Form code itself, it should be Me.Controls.Add(...)
>
> -Chris
>
> "Joey Wu" <Joey Wu@discussions.microsoft.com> wrote in message
> news:D191F782-B53E-460F-B066-EF3D3D986250@microsoft.com...
> > Dear All
> >
> > I`m tring to add a PictureBox to a Form. My code as below.
> >
> > Dim myPic as new PictureBox
> > myPic.Location = new Point(10,10)
> > myPic.Size = new Size(100,100)
> > FrmMain.Controls.Add(myPic)
> >
> > Then I got a "ArgumentException" at this line
> > FrmMain.Controls.Add(myPic)
> >
> > Somebody help?
> > Thanks a lot !!
> >
> > Joey
>
>
>

Re: Dynamic Add Control by Ginny

Ginny
Mon Oct 04 09:26:29 CDT 2004

Joey,

You really want to only change controls, add controls, or add handlers for
controls on the same thread that the controls were created on. Look at
Control.Invoke to see what you can safely do to controls from outside the
thread that created them.

--
Ginny Caughey
.Net Compact Framework MVP



"Joey Wu" <JoeyWu@discussions.microsoft.com> wrote in message
news:E180440B-080C-4C72-8A03-9539A791575D@microsoft.com...
> Hi~ Chris.
>
> The problem is I wrote those code in another thread......
> But now I have another problem.
> I added this to my code.
>
> AddHandler myPic.Click, AddressOf myPic_Click
>
> Private Sub myPic_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs)
> End Sub
>
> The event "myPic_Click" can be fired but sender is nothing @@"
> How can I get this "sender" then I can know which one of PictureBox fire
> this event?
>
> Thanks a lot !!
>
> "Chris Tacke, eMVP" wrote:
>
>> FrmMain is an instance of your main Form, not just the name? If you're
>> in
>> the Form code itself, it should be Me.Controls.Add(...)
>>
>> -Chris
>>
>> "Joey Wu" <Joey Wu@discussions.microsoft.com> wrote in message
>> news:D191F782-B53E-460F-B066-EF3D3D986250@microsoft.com...
>> > Dear All
>> >
>> > I`m tring to add a PictureBox to a Form. My code as below.
>> >
>> > Dim myPic as new PictureBox
>> > myPic.Location = new Point(10,10)
>> > myPic.Size = new Size(100,100)
>> > FrmMain.Controls.Add(myPic)
>> >
>> > Then I got a "ArgumentException" at this line
>> > FrmMain.Controls.Add(myPic)
>> >
>> > Somebody help?
>> > Thanks a lot !!
>> >
>> > Joey
>>
>>
>>