Click here to Skip to main content
15,895,142 members
Home / Discussions / C#
   

C#

 
GeneralRe: Copy file to server Pin
Daniel M. Edwards29-Sep-03 10:20
Daniel M. Edwards29-Sep-03 10:20 
GeneralTaskbar window button Pin
blade29-Sep-03 9:02
blade29-Sep-03 9:02 
QuestionWhich NUD called this MenuItem? Pin
james-cxx29-Sep-03 8:52
james-cxx29-Sep-03 8:52 
AnswerRe: Which NUD called this MenuItem? Pin
james-cxx29-Sep-03 13:16
james-cxx29-Sep-03 13:16 
Generalpostioning of printer dialog Pin
trythat29-Sep-03 8:06
trythat29-Sep-03 8:06 
GeneralRe: postioning of printer dialog Pin
Heath Stewart29-Sep-03 9:01
protectorHeath Stewart29-Sep-03 9:01 
Generaltoolbar rightclick Pin
trythat29-Sep-03 8:03
trythat29-Sep-03 8:03 
GeneralRe: toolbar rightclick Pin
Heath Stewart29-Sep-03 8:43
protectorHeath Stewart29-Sep-03 8:43 
Other than overriding the Toolbar class and using Win32 messages to do some of this, or using a pre-canned and much-better toolbar out there (like from Magic controls), there is a completely managed way of doing this.

Hook-up an event handler for either the Click event, or the MouseUp or MouseDown events. Using the Click event does warrant some extra code, but gives you some things for free (like detecting if the user escaped and message before you handle the "up" event). You can get the screen coordinates using the Click event, then use Control.MousePosition to get the screen coordinates, then use Control.PointToClient to get the form coordinates. If you use one of the Mouse* events, you are given the form coordinates.

Then, pass the Point to a function like so:
private ToolbarButton GetButtonFromPoint(Point p)
{
  foreach (ToolbarButton btn in myToolbar.Buttons)
  {
    Rectangle r = myToolbar.RectangleToClient(btn.Rectangle);
    if (r.Contains(myToolbar.PointToClient(p)))
      return btn;
  }
  return null;
}
You might have to fiddle with the coordinate conversion a little to make sure it works. This code is untested but should give you the basic idea.

 

-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
GeneralGDI+ Dashed line Pin
gadgetfbi29-Sep-03 7:35
gadgetfbi29-Sep-03 7:35 
GeneralRe: GDI+ Dashed line Pin
Heath Stewart29-Sep-03 9:04
protectorHeath Stewart29-Sep-03 9:04 
GeneralRe: GDI+ Dashed line Pin
Daniel M. Edwards29-Sep-03 10:25
Daniel M. Edwards29-Sep-03 10:25 
GeneralRe: GDI+ Dashed line Pin
gadgetfbi29-Sep-03 12:16
gadgetfbi29-Sep-03 12:16 
GeneralJPEG2000 Pin
gicio29-Sep-03 7:02
gicio29-Sep-03 7:02 
GeneralImport CSV File to MS Access Pin
raysot29-Sep-03 6:21
raysot29-Sep-03 6:21 
GeneralRe: Import CSV File to MS Access Pin
Steve McLenithan29-Sep-03 7:29
Steve McLenithan29-Sep-03 7:29 
GeneralReading StandardOutput Pin
Wjousts29-Sep-03 4:57
Wjousts29-Sep-03 4:57 
GeneralRe: Reading StandardOutput Pin
Heath Stewart29-Sep-03 9:09
protectorHeath Stewart29-Sep-03 9:09 
GeneralRe: Reading StandardOutput Pin
Wjousts29-Sep-03 10:25
Wjousts29-Sep-03 10:25 
GeneralRe: Reading StandardOutput Pin
Heath Stewart30-Sep-03 1:20
protectorHeath Stewart30-Sep-03 1:20 
GeneralRe: Reading StandardOutput Pin
Wjousts30-Sep-03 4:06
Wjousts30-Sep-03 4:06 
GeneralUrgent Help needed Pin
GenieUk29-Sep-03 4:02
GenieUk29-Sep-03 4:02 
GeneralValidating pasted text in textbox Pin
ecopilot29-Sep-03 4:01
ecopilot29-Sep-03 4:01 
GeneralRe: Validating pasted text in textbox Pin
Wjousts29-Sep-03 4:48
Wjousts29-Sep-03 4:48 
Generalhandling internet explorer events from a console application in VS.net Pin
Sonja-Hartmann29-Sep-03 3:29
Sonja-Hartmann29-Sep-03 3:29 
Questionhow to make a shortcut in .net cf Pin
tignatov29-Sep-03 0:21
tignatov29-Sep-03 0:21 

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.