Click here to Skip to main content
15,891,431 members
Home / Discussions / C#
   

C#

 
GeneralUsing separate class to handle events of user controls Pin
jomargon23-Dec-04 3:44
jomargon23-Dec-04 3:44 
GeneralRe: Using separate class to handle events of user controls Pin
Heath Stewart23-Dec-04 6:03
protectorHeath Stewart23-Dec-04 6:03 
GeneralRe: Using separate class to handle events of user controls Pin
jomargon24-Dec-04 15:06
jomargon24-Dec-04 15:06 
GeneralRe: Using separate class to handle events of user controls Pin
Heath Stewart27-Dec-04 10:21
protectorHeath Stewart27-Dec-04 10:21 
GeneralAsa Client Pin
sreejith ss nair23-Dec-04 3:34
sreejith ss nair23-Dec-04 3:34 
GeneralRe: Asa Client Pin
Heath Stewart23-Dec-04 5:57
protectorHeath Stewart23-Dec-04 5:57 
GeneralDraw line between pictureboxes Pin
ninja260523-Dec-04 2:18
ninja260523-Dec-04 2:18 
GeneralRe: Draw line between pictureboxes Pin
Heath Stewart23-Dec-04 5:47
protectorHeath Stewart23-Dec-04 5:47 
ninja2605 wrote:
picturebox tags

What do you mean by "tags"?

This is possible, but you'll need to extend a container control - like UserControl - and override OnPaint (always override when possible instead of handling events from within derivative classes). Use the Graphics object passed to you in the PaintEventArgs.Graphics property to draw a line. You could also just handle the Paint event from outside the current container control (ex: the Form on which you placed the two PictureBox controls), but I (and pretty much any other developer) find that encapsulating functionality makes it esier to reuse.

Let me suggestion, however, that for complete control you should consider not using two PictureBox controls and instead drawing the pictures yourself. Now wait, don't get scared. Smile | :)

It's actually quite easy using the Graphics object in the OnPaint override that I mentioned before. It has a DrawImage method (overloaded methods, actually). All you need to take care of is where to draw the top-left corner.

Why do I suggest this? Because then you could have a single control (in this case, just extend Control to avoid unnecessary overhead) with a couple of Image type properties defined. Override a few of the mouse event handlers (like OnMouseDown, OnMouseMove, and OnMouseUp) to track the mouse and draw a line between the pictures. Without using complicated layered windows (which is only supported in Windows 2000 and newer anyway) this is the only way to have the line you draw overlap the images if that's what you want.

When overriding event handlers, be sure to call base.OnEventName otherwise the default implementation (when applicable, which is in most cases) is not executed and the actual event is not fired). Only in a few rare cases (like when handling windows messages in WndProc that you want ignored) should you not call the base class's implementation. In what order you do it greatly depends on what you're doing. For painting, for example, you'll want to call base.OnPaint first so that any owner-drawn decorations are drawn first, then draw your decorations on top of them.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: Draw line between pictureboxes Pin
ninja260523-Dec-04 18:37
ninja260523-Dec-04 18:37 
GeneralRe: Draw line between pictureboxes Pin
Heath Stewart23-Dec-04 19:24
protectorHeath Stewart23-Dec-04 19:24 
GeneralRe: Draw line between pictureboxes Pin
ninja260523-Dec-04 20:18
ninja260523-Dec-04 20:18 
GeneralRe: Draw line between pictureboxes Pin
Heath Stewart23-Dec-04 20:23
protectorHeath Stewart23-Dec-04 20:23 
GeneralRe: Draw line between pictureboxes Pin
ninja260524-Dec-04 0:33
ninja260524-Dec-04 0:33 
GeneralRe: Draw line between pictureboxes Pin
Heath Stewart27-Dec-04 10:09
protectorHeath Stewart27-Dec-04 10:09 
GeneralRe: Draw line between pictureboxes Pin
ninja260529-Dec-04 0:38
ninja260529-Dec-04 0:38 
GeneralRe: Draw line between pictureboxes Pin
Heath Stewart29-Dec-04 5:28
protectorHeath Stewart29-Dec-04 5:28 
GeneralRe: Draw line between pictureboxes Pin
ninja260510-Jan-05 0:49
ninja260510-Jan-05 0:49 
GeneralI wish myself a flicker free form Pin
TyronX23-Dec-04 2:09
TyronX23-Dec-04 2:09 
GeneralRe: I wish myself a flicker free form Pin
Heath Stewart23-Dec-04 5:27
protectorHeath Stewart23-Dec-04 5:27 
GeneralRe: I wish myself a flicker free form Pin
TyronX23-Dec-04 6:47
TyronX23-Dec-04 6:47 
GeneralRe: I wish myself a flicker free form Pin
Heath Stewart23-Dec-04 9:31
protectorHeath Stewart23-Dec-04 9:31 
GeneralRe: I wish myself a flicker free form Pin
TyronX23-Dec-04 10:23
TyronX23-Dec-04 10:23 
GeneralConnection to access database with C#.net Pin
Robske23-Dec-04 1:41
Robske23-Dec-04 1:41 
GeneralRe: Connection to access database with C#.net Pin
leppie23-Dec-04 3:27
leppie23-Dec-04 3:27 
GeneralRe: Connection to access database with C#.net Pin
Robske23-Dec-04 4:25
Robske23-Dec-04 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.