Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to customise the behaviour of a control when it is selected

How to customise the behaviour of a control when it is selected

Scheduled Pinned Locked Moved C#
questioncsshelptutorial
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Dave Midgley
    wrote on last edited by
    #1

    I am developing a control that displays a grid of pictures. I want to be able to select a picture by clicking on it, and change its appearance (eg. with a border) to show that it is selected. I have created: 1. a class derived from UserControl that contains a PictureBox for the picture 2. a class derived from FlowLayoutPanel to contain the pictures. This overrides CreateControlsInstance() to return an instance of... 3. a class derived from Control.ControlCollection to contain the picture objects. This overrides the Add(Control value) method in order to add a handler to the Click event of the control being added to the collection. It also contains the click event handler, and this is where my problem lies:- It seems to me that the logical next step is for the click event handler to identify the control that has been clicked (no problem) and to call its Select() method, which will then alter the appearance of the control as required. The problem is that Control.Select() cannot be overridden. This raises two questions: Q1: what does Control.Select() actually do? Q2: how do I implement the change in appearance of the control. Obviously I could just set the UserControl.BorderStyle property from within the click handler in collection class, but surely an object should make its own decision as to how it looks when it is selected. I can only assume that I've misunderstood something, or am doing it all the wrong way. Can anyone advise?

    Dave

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups