Problem Upgrading VB6 Picturebox to .NET

I am upgrading an VB6 application to .NET.

The application uses pictureboxes controls.
I need a .NET control that has the following attirbutes:

1. Is a container control
2. Can get the focus
3. Has Keystroke events
4. Has a drawing canvas

Is there a control in .NET that will do all this?
Or there a way to write a custom control that will do this?

The picturebox control in .NET is no longer a container control.

Thanks
LVL 18
JR2003Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
Hi JR2003;

How about placing the PictureBox in a Panel control, the Panel control will provide the container.

Fernando
0
TertioptusCommented:
Yes,

Then dock the PictureBox with the "Fill" option.

objPictureBox.Dock = DockStyle.Fill


OR

Place your Picturebox in a usercontrol.  Dock if you need to.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
I think you need to elaborate on item #4:

    4. Has a drawing canvas

The approach and methodology of drawing in .Net is significantly different from that of VB6.

From your requirements it sounds like this will not simply be a matter of replacing one control with another.  Can you give us a bigger picture?
0
Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Bob LearnedCommented:
Hey Mikey,

4.  Graphics handle for drawing lines, text, rectangles

This is how I read that ;)

Bob
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
Right...I agree.

My comment was more geared towards the fact that many VB6 drawing routines use the ~persistent~ state of a PictureBox with its AutoRedraw property set to True...often resulting in VB.Net induced "drawing shock" when they can't do the same "simple thing" in .Net.  =)
0
Bob LearnedCommented:
Yes, Mike, I agree that VB6 developers do go through some serious "shock" when transitioning to VB.NET.

Example of drawing persistent graphics in the Paint event handler:

  Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    e.Graphics.DrawRectangle(Pens.Red, CType(sender, PictureBox).DisplayRectangle)
  End Sub

Let's just carry on a conversation between ourselves =:).  It will not be so beneficial, though, since we both know a considerable amount about this stuff already.

Bob
0
JR2003Author Commented:
A picturebox doesn't have keystroke events neither does the panel so putting a picturebox in a panel won't satisfy my requirements.

I must be able to intercept keystroke events.
0
Bob LearnedCommented:
You can work around that limitation this way:

1) Set Form's KeyPreview = True

2) Handle the KeyDown event, and check the form's active control:

  Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles MyBase.KeyDown
    If Me.ActiveControl Is Me.PictureBox1 Then
      If e.KeyCode = Keys.A And e.Control Then
        ' Select all text.
       e.Handled = True
      End If
    End If
  End Sub

Bob
0
JR2003Author Commented:
The control I'm upgrading is an ActiveX ocx usercontrol that contains 2 independent sub-controls.
These sub-controls need to receive the focus and keystrokes.
A picturebox is non-selectable so cannot be the ActiveControl.
0
Bob LearnedCommented:
Ok, you win. =:)  You will have to stay with a UserControl:

Public Class ContainerPanel
  Inherits System.Windows.Forms.UserControl

End Class

Bob
0
JR2003Author Commented:
Can a user control get the focus?
Currently when I run the line
MyControl.Focus
The GotFocus event on the control doesn't fire.
0
Bob LearnedCommented:
How about the Enter event?

Bob
0
JR2003Author Commented:
Ok thanks.
When I use the arrow keys they move to the next control on the form.
I need to intercept the arrow keys and for focus to stay on the usercontrol.
0
Bob LearnedCommented:
Paste this into your UserControl class:

  Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
     Return keyData <> Keys.Right AndAlso keyData <> Keys.Left
  End Function

The arrow keys are dialog keys, and are processed differently than normal keypresses.  If you return True, they are handled, and if you return False, then they are blocked.  So, we are blocking Right and Left arrow keys.

Bob
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.