none
Is there a way to change the default method/property of a control in vb RRS feed

  • Question

  • When you display a form and double-click on a control, say a toolbar button, this transfers you from the form's design to the code page and creates a routine for the control's default method. I have toolbar buttons that are checkbox types, but they are designed to be activated by an "itempress" method. I only use them as checkboxes so that when they are clicked, depending on what happens, I can show them "checked" or not. So, in developing my program, I constantly get all these checkbox routines automatically, and then have to create the itempress routines manually. I keep accumulating these useless checkbox routines which I have to erase. Even after I've created an ItemPress routine for a toolbar checkbox button, if I click on the button, it doesn't put me right there in my previously-created itempress routine but creates another useless checkbox routine. Can I prevent this? or maybe change the default action for a checkbox to it's itempress method?


    Robert Homes

    Monday, September 25, 2017 2:28 PM

Answers

  •  Here is a link to the DefaultEventAttribute Class which Karen has shown for setting the default Event of a class.  There is also the DefaultPropertyAttribute Class. for setting the default Property of a class.   The msdn links i just gave for these attributes also have examples showing how to use them.  8)

    If you say it can`t be done then i`ll try it

    • Marked as answer by Robert Homes Monday, September 25, 2017 7:18 PM
    Monday, September 25, 2017 4:49 PM
  • When changing the default behavior you create a control such as I did and do any changes to it's behavior in the class file created such as the one I showed. My example showed only what you asked for but as just stated you do everything in a single file.

    Without doing the above the default behavior can not be changed.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Robert Homes Monday, September 25, 2017 7:18 PM
    Monday, September 25, 2017 6:21 PM
    Moderator

All replies

  • You can change the default e.g.

    Imports System.ComponentModel
    <DefaultEvent("KeyUp")> Public Class KarensButton
        Inherits Button
    End Class
    

    I placed one on a form, double click to get

    Private Sub KarensButton1_KeyUp(sender As Object, e As KeyEventArgs) Handles KarensButton1.KeyUp
    
    End Sub


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Proposed as answer by Frank L. Smith Monday, September 25, 2017 3:20 PM
    Monday, September 25, 2017 3:05 PM
    Moderator
  •  Here is a link to the DefaultEventAttribute Class which Karen has shown for setting the default Event of a class.  There is also the DefaultPropertyAttribute Class. for setting the default Property of a class.   The msdn links i just gave for these attributes also have examples showing how to use them.  8)

    If you say it can`t be done then i`ll try it

    • Marked as answer by Robert Homes Monday, September 25, 2017 7:18 PM
    Monday, September 25, 2017 4:49 PM
  • Karen,

    Do I have to create a separate Class file for each attribute of a control I want to change, or can I put them all into one class file? Or can I put the class(es) into a Module or Form file?


    Robert Homes


    • Edited by Robert Homes Monday, September 25, 2017 6:03 PM Added "or can I" etc.
    Monday, September 25, 2017 6:02 PM
  • When changing the default behavior you create a control such as I did and do any changes to it's behavior in the class file created such as the one I showed. My example showed only what you asked for but as just stated you do everything in a single file.

    Without doing the above the default behavior can not be changed.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    • Marked as answer by Robert Homes Monday, September 25, 2017 7:18 PM
    Monday, September 25, 2017 6:21 PM
    Moderator
  • This is what I tried, but it doesn't work:

    Imports System.ComponentModel

    <DefaultEvent("ItemClick")> Public Class DevExpress.XtraBars.barcheckitem
           Inherits DevExpress.xtrabars.barcheckitem
    End Class

    I'm using (or trying to) use DevExpress, and maybe that's the problem. Frankly, I don't know what I'm doing. Don't use Classes much and don't understand them much. For whatever reason, VB really, really doesn't like my code!

    I don't have time to study classes and everything else I need. I can do okay on easy things and have written many large programs. But with something like this, I am hoping that someone who knows what they're doing could just write the few lines of code I need for me. If not, I'll need to hire an expert programmer to help me. Thanks.


    Robert Homes


    Monday, September 25, 2017 6:31 PM
  • The problem most likely is what DevExpress is doing with their control as I'm sure they are inheriting from a native .NET control. Best to ask them in the Dev Express developer's forums.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Monday, September 25, 2017 7:12 PM
    Moderator
  • I can't ask them. My maintenance expired! Thanks for your help with the other stuff.

    Robert Homes

    Monday, September 25, 2017 7:18 PM