DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 10 of 10

Thread: What is the right way?

  1. #1
    John Guest

    What is the right way?


    Hi...

    I am a beginner in VB world and I'd like to program directly in VB.NET.
    I am curious whether I am doing this thing the right way or not. Please shed
    some light.

    In VB 6 and before, I can do this

    private sub command2_click
    command1.click()
    end sub

    How to do the same in VB.NET? My current solution is:

    private sub button2_click()
    me.button1_click(sender, e)
    end sub

    Right or wrong?

    tq

    /john
    "Be all you can be!"


  2. #2
    Michael Culley Guest

    Re: What is the right way?

    > private sub command2_click
    > command1.click()
    > end sub


    This does not work, but I presume you meant command1_Click. IMO this was bad
    practice in VB6 becuase you could never tell whether command1_click was
    being called as the result of an event or being called from another
    function. As error handling varies depending on this you didn't know what
    sort of error handling to use. I used this sort of approach in VB6 and would
    recommend it in dot not.

    Sub Command1_Click
    DoSomething
    End Sub

    Sub Command2_Click
    DoSomething
    End Sub

    Sub DoSomething ()
    ....
    End Sub

    --
    Michael Culley
    www.vbdotcom.com


    "John" <maverick@office.naver.co.id> wrote in message
    news:3cfd99b7$1@10.1.10.29...
    >
    > Hi...
    >
    > I am a beginner in VB world and I'd like to program directly in VB.NET.
    > I am curious whether I am doing this thing the right way or not. Please

    shed
    > some light.
    >
    > In VB 6 and before, I can do this
    >
    > private sub command2_click
    > command1.click()
    > end sub
    >
    > How to do the same in VB.NET? My current solution is:
    >
    > private sub button2_click()
    > me.button1_click(sender, e)
    > end sub
    >
    > Right or wrong?
    >
    > tq
    >
    > /john
    > "Be all you can be!"
    >




  3. #3
    Jim Pragit Guest

    Re: What is the right way?


    Hi John,

    In VB.NET, you can now assign the same event procedure to multiple events:

    Private Sub Button_Click(sender, e) Handles Button1.Click, Button2.Click
    'do something
    End sub

    - Jim

    "John" <maverick@office.naver.co.id> wrote:
    >
    >Hi...
    >
    >I am a beginner in VB world and I'd like to program directly in VB.NET.
    >I am curious whether I am doing this thing the right way or not. Please

    shed
    >some light.
    >
    >In VB 6 and before, I can do this
    >
    >private sub command2_click
    > command1.click()
    >end sub
    >
    >How to do the same in VB.NET? My current solution is:
    >
    >private sub button2_click()
    > me.button1_click(sender, e)
    >end sub
    >
    >Right or wrong?
    >
    >tq
    >
    >/john
    >"Be all you can be!"
    >



  4. #4
    Jay B. Harlow Guest

    Re: What is the right way?

    John,
    In addition to what Michael & Jim stated.

    You can use the Button.PerformClick method to simulate the clicking of a
    command button on a form. This will ensure that all Click event handlers
    tied to the control are called...

    Hope this helps
    Jay

    "John" <maverick@office.naver.co.id> wrote in message
    news:3cfd99b7$1@10.1.10.29...
    >
    > Hi...
    >
    > I am a beginner in VB world and I'd like to program directly in VB.NET.
    > I am curious whether I am doing this thing the right way or not. Please

    shed
    > some light.
    >
    > In VB 6 and before, I can do this
    >
    > private sub command2_click
    > command1.click()
    > end sub
    >
    > How to do the same in VB.NET? My current solution is:
    >
    > private sub button2_click()
    > me.button1_click(sender, e)
    > end sub
    >
    > Right or wrong?
    >
    > tq
    >
    > /john
    > "Be all you can be!"
    >




  5. #5
    rmeklo Guest

    Re: What is the right way?


    I have what I think is a related question:

    What is the best way to perform a dropdown (raise the event) when a toolbar
    button is clicked? (not just the arrow, the whole button)
    I tried calling the toolbar's OnDropdown method, but I get a message that
    it (the Sub) is Protected.

    Do I need to send a windows message?

    "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    >John,
    >In addition to what Michael & Jim stated.
    >
    >You can use the Button.PerformClick method to simulate the clicking of a
    >command button on a form. This will ensure that all Click event handlers
    >tied to the control are called...
    >
    >Hope this helps
    >Jay
    >
    >"John" <maverick@office.naver.co.id> wrote in message
    >news:3cfd99b7$1@10.1.10.29...
    >>
    >> Hi...
    >>
    >> I am a beginner in VB world and I'd like to program directly in VB.NET.
    >> I am curious whether I am doing this thing the right way or not. Please

    >shed
    >> some light.
    >>
    >> In VB 6 and before, I can do this
    >>
    >> private sub command2_click
    >> command1.click()
    >> end sub
    >>
    >> How to do the same in VB.NET? My current solution is:
    >>
    >> private sub button2_click()
    >> me.button1_click(sender, e)
    >> end sub
    >>
    >> Right or wrong?
    >>
    >> tq
    >>
    >> /john
    >> "Be all you can be!"
    >>

    >
    >



  6. #6
    Michael Culley Guest

    Re: What is the right way?

    Why do you need to similar a click at all, why can't you just call the
    function that performs the action?

    --
    Michael Culley
    www.vbdotcom.com


    "rmeklo" <rbmeklo@attbi.com> wrote in message news:3d022047$1@10.1.10.29...
    >
    > I have what I think is a related question:
    >
    > What is the best way to perform a dropdown (raise the event) when a

    toolbar
    > button is clicked? (not just the arrow, the whole button)
    > I tried calling the toolbar's OnDropdown method, but I get a message that
    > it (the Sub) is Protected.
    >
    > Do I need to send a windows message?
    >
    > "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    > >John,
    > >In addition to what Michael & Jim stated.
    > >
    > >You can use the Button.PerformClick method to simulate the clicking of a
    > >command button on a form. This will ensure that all Click event handlers
    > >tied to the control are called...
    > >
    > >Hope this helps
    > >Jay
    > >
    > >"John" <maverick@office.naver.co.id> wrote in message
    > >news:3cfd99b7$1@10.1.10.29...
    > >>
    > >> Hi...
    > >>
    > >> I am a beginner in VB world and I'd like to program directly in VB.NET.
    > >> I am curious whether I am doing this thing the right way or not. Please

    > >shed
    > >> some light.
    > >>
    > >> In VB 6 and before, I can do this
    > >>
    > >> private sub command2_click
    > >> command1.click()
    > >> end sub
    > >>
    > >> How to do the same in VB.NET? My current solution is:
    > >>
    > >> private sub button2_click()
    > >> me.button1_click(sender, e)
    > >> end sub
    > >>
    > >> Right or wrong?
    > >>
    > >> tq
    > >>
    > >> /john
    > >> "Be all you can be!"
    > >>

    > >
    > >

    >




  7. #7
    rmeklo Guest

    Re: What is the right way?


    Sorry, I was not clear.
    I need some toolbar buttons to visually dropdown
    when either their dropdown or click events fire.

    May I raise the dropdown event from the click handler?


    "Michael Culley" <m_culley@hotmail.com> wrote:
    >Why do you need to similar a click at all, why can't you just call the
    >function that performs the action?
    >
    >--
    >Michael Culley
    >www.vbdotcom.com
    >
    >
    >"rmeklo" <rbmeklo@attbi.com> wrote in message news:3d022047$1@10.1.10.29...
    >>
    >> I have what I think is a related question:
    >>
    >> What is the best way to perform a dropdown (raise the event) when a

    >toolbar
    >> button is clicked? (not just the arrow, the whole button)
    >> I tried calling the toolbar's OnDropdown method, but I get a message that
    >> it (the Sub) is Protected.
    >>
    >> Do I need to send a windows message?
    >>
    >> "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    >> >John,
    >> >In addition to what Michael & Jim stated.
    >> >
    >> >You can use the Button.PerformClick method to simulate the clicking of

    a
    >> >command button on a form. This will ensure that all Click event handlers
    >> >tied to the control are called...
    >> >
    >> >Hope this helps
    >> >Jay
    >> >
    >> >"John" <maverick@office.naver.co.id> wrote in message
    >> >news:3cfd99b7$1@10.1.10.29...
    >> >>
    >> >> Hi...
    >> >>
    >> >> I am a beginner in VB world and I'd like to program directly in VB.NET.
    >> >> I am curious whether I am doing this thing the right way or not. Please
    >> >shed
    >> >> some light.
    >> >>
    >> >> In VB 6 and before, I can do this
    >> >>
    >> >> private sub command2_click
    >> >> command1.click()
    >> >> end sub
    >> >>
    >> >> How to do the same in VB.NET? My current solution is:
    >> >>
    >> >> private sub button2_click()
    >> >> me.button1_click(sender, e)
    >> >> end sub
    >> >>
    >> >> Right or wrong?
    >> >>
    >> >> tq
    >> >>
    >> >> /john
    >> >> "Be all you can be!"
    >> >>
    >> >
    >> >

    >>

    >
    >



  8. #8
    rmeklo Guest

    Re: What is the right way?


    Further clarification --
    When I asked:
    >> Do I need to send a windows message?


    I meant like TBN_DROPDOWN as in the "Using Toolbar Controls"
    (Windows Shell) example. I was hoping to avoid converting the following
    to VB.NET if there's a simpler implementation now available.
    The application user just want the whole button to act like the dropdown
    arrow.

    BOOL DoNotify(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
    {
    #define lpnm ((LPNMHDR)lParam)
    #define lpnmTB ((LPNMTOOLBAR)lParam)

    RECT rc;
    TPMPARAMS tpm;
    HMENU hPopupMenu = NULL;
    HMENU hMenuLoaded;
    BOOL bRet = FALSE;

    switch(lpnm->code){
    case TBN_DROPDOWN:
    SendMessage(lpnmTB->hdr.hwndFrom, TB_GETRECT,
    (WPARAM)lpnmTB->iItem, (LPARAM)&rc);

    MapWindowPoints(lpnmTB->hdr.hwndFrom,
    HWND_DESKTOP, (LPPOINT)&rc, 2);


    tpm.cbSize = sizeof(TPMPARAMS);
    tpm.rcExclude = rc;
    hMenuLoaded = LoadMenu(g_hinst, MAKEINTRESOURCE(IDR_POPUP));
    hPopupMenu = GetSubMenu(LoadMenu(g_hinst,
    MAKEINTRESOURCE(IDR_POPUP)),0);
    TrackPopupMenuEx(hPopupMenu,
    TPM_LEFTALIGN|TPM_LEFTBUTTON|TPM_VERTICAL,
    rc.left, rc.bottom, g_hwndMain, &tpm);
    DestroyMenu(hMenuLoaded);
    return (FALSE);
    }

    return FALSE;
    }


    >>
    >> "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    >> >John,
    >> >In addition to what Michael & Jim stated.
    >> >
    >> >You can use the Button.PerformClick method to simulate the clicking of

    a
    >> >command button on a form. This will ensure that all Click event handlers
    >> >tied to the control are called...
    >> >
    >> >Hope this helps
    >> >Jay
    >> >
    >> >"John" <maverick@office.naver.co.id> wrote in message
    >> >news:3cfd99b7$1@10.1.10.29...
    >> >>
    >> >> Hi...
    >> >>
    >> >> I am a beginner in VB world and I'd like to program directly in VB.NET.
    >> >> I am curious whether I am doing this thing the right way or not. Please
    >> >shed
    >> >> some light.
    >> >>
    >> >> In VB 6 and before, I can do this
    >> >>
    >> >> private sub command2_click
    >> >> command1.click()
    >> >> end sub
    >> >>
    >> >> How to do the same in VB.NET? My current solution is:
    >> >>
    >> >> private sub button2_click()
    >> >> me.button1_click(sender, e)
    >> >> end sub
    >> >>
    >> >> Right or wrong?
    >> >>
    >> >> tq
    >> >>
    >> >> /john
    >> >> "Be all you can be!"
    >> >>
    >> >
    >> >

    >>

    >
    >



  9. #9
    Jay B. Harlow Guest

    Re: What is the right way?

    Rmeklo,
    I do not believe that 'method' is exposed, I suspose you could use your code
    from your other post, however that is not portable. If Mono and some of
    these other .NET Framework implementations become a reality you may have
    problems...

    Hope this helps
    Jay

    "rmeklo" <rbmeklo@attbi.com> wrote in message news:3d022047$1@10.1.10.29...
    >
    > I have what I think is a related question:
    >
    > What is the best way to perform a dropdown (raise the event) when a

    toolbar
    > button is clicked? (not just the arrow, the whole button)
    > I tried calling the toolbar's OnDropdown method, but I get a message that
    > it (the Sub) is Protected.
    >
    > Do I need to send a windows message?
    >
    > "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    > >John,
    > >In addition to what Michael & Jim stated.
    > >
    > >You can use the Button.PerformClick method to simulate the clicking of a
    > >command button on a form. This will ensure that all Click event handlers
    > >tied to the control are called...
    > >
    > >Hope this helps
    > >Jay
    > >
    > >"John" <maverick@office.naver.co.id> wrote in message
    > >news:3cfd99b7$1@10.1.10.29...
    > >>
    > >> Hi...
    > >>
    > >> I am a beginner in VB world and I'd like to program directly in VB.NET.
    > >> I am curious whether I am doing this thing the right way or not. Please

    > >shed
    > >> some light.
    > >>
    > >> In VB 6 and before, I can do this
    > >>
    > >> private sub command2_click
    > >> command1.click()
    > >> end sub
    > >>
    > >> How to do the same in VB.NET? My current solution is:
    > >>
    > >> private sub button2_click()
    > >> me.button1_click(sender, e)
    > >> end sub
    > >>
    > >> Right or wrong?
    > >>
    > >> tq
    > >>
    > >> /john
    > >> "Be all you can be!"
    > >>

    > >
    > >

    >




  10. #10
    rmeklo Guest

    Re: What is the right way?


    Thank you very much.

    In lieu of using (the Protected) OnDropdown, I will use the API.
    Portablity is not an issue in my current case -- the client just wants
    some toolbar buttons to have a "bigger target area" than the dropdown arrow.
    I am also considering writing a subclassed toolbar control that
    will allow the "desired style" (BTNS_WHOLEDROPDOWN)
    I welcome any suggestions on how best to do this (preferably with VB syntax
    since I will not be supporting this directly)

    "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    >Rmeklo,
    >I do not believe that 'method' is exposed, I suspose you could use your

    code
    >from your other post, however that is not portable. If Mono and some of
    >these other .NET Framework implementations become a reality you may have
    >problems...
    >
    >Hope this helps
    >Jay
    >
    >"rmeklo" <rbmeklo@attbi.com> wrote in message news:3d022047$1@10.1.10.29...
    >>
    >> I have what I think is a related question:
    >>
    >> What is the best way to perform a dropdown (raise the event) when a

    >toolbar
    >> button is clicked? (not just the arrow, the whole button)
    >> I tried calling the toolbar's OnDropdown method, but I get a message that
    >> it (the Sub) is Protected.
    >>
    >> Do I need to send a windows message?
    >>
    >> "Jay B. Harlow" <Jay_Harlow@email.msn.com> wrote:
    >> >John,
    >> >In addition to what Michael & Jim stated.
    >> >
    >> >You can use the Button.PerformClick method to simulate the clicking of

    a
    >> >command button on a form. This will ensure that all Click event handlers
    >> >tied to the control are called...
    >> >
    >> >Hope this helps
    >> >Jay
    >> >
    >> >"John" <maverick@office.naver.co.id> wrote in message
    >> >news:3cfd99b7$1@10.1.10.29...
    >> >>
    >> >> Hi...
    >> >>
    >> >> I am a beginner in VB world and I'd like to program directly in VB.NET.
    >> >> I am curious whether I am doing this thing the right way or not. Please
    >> >shed
    >> >> some light.
    >> >>
    >> >> In VB 6 and before, I can do this
    >> >>
    >> >> private sub command2_click
    >> >> command1.click()
    >> >> end sub
    >> >>
    >> >> How to do the same in VB.NET? My current solution is:
    >> >>
    >> >> private sub button2_click()
    >> >> me.button1_click(sender, e)
    >> >> end sub
    >> >>
    >> >> Right or wrong?
    >> >>
    >> >> tq
    >> >>
    >> >> /john
    >> >> "Be all you can be!"
    >> >>
    >> >
    >> >

    >>

    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center