?
Solved

Problem Upgrading VB6 Picturebox to .NET

Posted on 2006-03-31
14
Medium Priority
?
442 Views
Last Modified: 2008-02-01
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
0
Comment
Question by:JR2003
  • 6
  • 4
  • 2
  • +2
14 Comments
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 16343890
Hi JR2003;

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

Fernando
0
 
LVL 5

Expert Comment

by:Tertioptus
ID: 16343948
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
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16344667
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 16347045
Hey Mikey,

4.  Graphics handle for drawing lines, text, rectangles

This is how I read that ;)

Bob
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 16347189
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16349592
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
 
LVL 18

Author Comment

by:JR2003
ID: 16359068
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16360083
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
 
LVL 18

Author Comment

by:JR2003
ID: 16360415
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16360640
Ok, you win. =:)  You will have to stay with a UserControl:

Public Class ContainerPanel
  Inherits System.Windows.Forms.UserControl

End Class

Bob
0
 
LVL 18

Author Comment

by:JR2003
ID: 16362157
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
 
LVL 96

Expert Comment

by:Bob Learned
ID: 16362334
How about the Enter event?

Bob
0
 
LVL 18

Author Comment

by:JR2003
ID: 16362615
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
 
LVL 96

Accepted Solution

by:
Bob Learned earned 2000 total points
ID: 16362808
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

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses
Course of the Month13 days, 18 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question