Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8909033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:20:05+00:00 2026-06-15T03:20:05+00:00

Delphi’s VCL has a very useful class, CustomControl. This class is a direct base

  • 0

Delphi’s VCL has a very useful class, CustomControl. This class is a direct base class of Control, which is equivalent to C# WF’s UserControl.

For those, who are not familiar with VCL, CustomControl differs very little from Control; the main difference is that most of properties are protected; when implementing the new control, developer may decide, which ones does he want to publish and which ones shall remain hidden.

I’m developing my own control for Windows Forms and I want to hide some properties and events. For instance, I don’t want to expose the MouseDown event – instead I allow capturing clicking on control’s elements.

Is there an equivalent of VCL’s CustomControl in Windows Forms? If not, how can I hide unwanted public properties and events in my control?


In response to answers:

This is not a matter of security, but rather a matter of code elegance. In Delphi I can derive from CustomControl, leave the OnMouseDown event protected (as in C#’s protected) and say to the control’s user:

You cannot use OnMouseDown, because there is none. If you want to react to user clicking on control, simply use OnElementClicked – you’ll even get detailed information about which element was clicked and what was its state.

I may disable calling the MouseDown event as Hans Passant suggested, but then I would have to include the following in the control’s user’s manual:

Please do not use the MouseDown event, because I’ve overridden the OnMouseDown method, such that it won’t call the MouseDown event. This is because the control’s logic is designed in such way, that you should use OnElementClicked rather than OnMouseDown. Please don’t criticize the control because of MouseDown not working. Please don’t report it as a bug, because it is by design. Please don’t post messages in forums or create blog entries explaining how to fix the MouseDown problem by inheriting the class and manually calling the MouseDown event, because it would break the control’s logic. Pleas don’t… damnit, told you so!

If someone actually inherits from my control – I assume then, that he knows, what he’s doing (also because one would then gain access to my control’s internal logic as well). But if someone just uses my control, I would give him only these properties, events and methods, that I’m sure will work as designed.

I hope it explains my motives 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:20:06+00:00Added an answer on June 15, 2026 at 3:20 am

    There’s a fundamental difference between hiding, what you asked for, and making it inaccessible, what I assume Delphi does. Hiding is simple, just repeat the declaration and apply attributes:

    using System;
    using System.ComponentModel;
    using System.Windows.Forms;
    
    class MyControl : Control {
        [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
        private new event MouseEventHandler MouseDown;
    }
    

    Which prevents the event from being displayed in the Properties window, it won’t show up in the IntelliSense dropdown and generates a compile error when he tries to assign the event in code anyway.

    It is however not an absolute guarantee that the client programmer couldn’t work around the restriction anyway. By casting or overriding your class for example. But the ultimate backdoor is implementing the IMessageFilter interface, nothing you can do about that. So this ought to be good enough if elegance is the goal.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Delphi. How from DLL to learn Handle the appendix which has caused this DLL?
Delphi (and probably a lot of other languages) has class helpers. These provide a
Delphi 8 introduced Class Helpers for the purposes of mapping the VCL/RTL to the
Delphi 2010 has a nice set of new file access functions in IOUtils.pas (I
Delphi 2010 Windows 7 - 64 bit. I have an app which is reasonably
Delphi XE2, so Indy 10. My client sends a command which is processed by
In Delphi we can delegate the implementation of an interface to another class, I'm
Delphi 2010 introduced custom attributes which can be added to type declarations and methods.
Delphi 2010, Win32 VCL. I need to create a main menu for my application
Delphi implementation of the TFlowPanel control seems to lack an important feature of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.