|
|
|
Supreme Being
      
участник
Last Login: 05.02.2007 6:22
Сообщ.: 329,
Visits: 3 602
|
|
В учебнике написано так:
Private Sub ToolBar1_ButtonClick(ByVal sender As System.Object, _ ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) _ Handles ToolBar1.ButtonClick If e.Button = ToolBarButton1 Then ....... ElseIf e.Button = ToolBarButton2 Then ....... End If End Sub
но на такие строки транслятор ругается Operator '=' is not defined for types 'System.Windows.Forms.ToolBarButton' and 'System.Windows.Forms.ToolBarButton'. Use 'Is' operator to compare two reference types.
Как же правильно это делается?
|
|
|
|
|
Forum Member
      
участник
Last Login: 14.11.2004 19:01
Сообщ.: 25,
Visits: 276
|
|
Protected Sub ToolBar1_ButtonClick(ByVal sender As Object, _ ByVal e As ToolBarButtonClickEventArgs) ' Evaluate the Button property of the ToolBarButtonClickEventArgs ' to determine which button was clicked. Select Case ToolBar1.Buttons.IndexOf(e.Button) Case 0 MessageBox.Show("First toolbar button clicked") Case 1 MessageBox.Show("Second toolbar button clicked") Case 2 MessageBox.Show("Third toolbar button clicked") End Select End Sub
|
|
|
|
|
Supreme Being
      
участник
Last Login: 05.02.2007 6:22
Сообщ.: 329,
Visits: 3 602
|
|
Да действительно работает. Но по моему есть один недостаток. Кнопки нельзя менять местами. Можно ли как то обращаться к именам кнопок?
|
|
|
|
|
новичок
      
участник
Last Login: 12.04.2005 16:02
Сообщ.: 8,
Visits: 89
|
|
Я, например, попробовал во так: ... Select Case ToolBar1.Buttons.IndexOf(e.Button) Case ToolBar1.Buttons.IndexOf(ToolBarButton1) MessageBox.Show("1") Case ToolBar1.Buttons.IndexOf(ToolBarButton2) MessageBox.Show("2") Case ToolBar1.Buttons.IndexOf(ToolBarButton3) MessageBox.Show("3") End Select ...
Наверно есть способ и проще :) С уважением, Алексей.
|
|
|
|
|
Supreme Being
      
участник
Last Login: 05.02.2007 6:22
Сообщ.: 329,
Visits: 3 602
|
|
Алексею... Чем Ваш пример отличается от выше приведенного? Я нашел способ, который обрабатывает кнопки, даже если их переставишь местами. Для этого надо в каждой кнопке прописать TEG А далее делаем так:
Private Sub MainToolBar_ButtonClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ToolBarButtonClickEventArgs) Handles MainToolBar.ButtonClick
If e.Button.Tag = "ИмяТэга1" Then ........ elseif e.Button.Tag = "ИмяТэга2" Then .......... End If
End Sub
Мне показалось так будет лучше... Есть другие мнения?
|
|
|
|
|
новичок
      
участник
Last Login: 12.04.2005 16:02
Сообщ.: 8,
Visits: 89
|
|
Олегу... Вы написали: "Но по моему есть один недостаток. Кнопки нельзя менять местами. Можно ли как то обращаться к именам кнопок?"
В моем примере вы обращаетесь к именам кнопок, хоть возможно и не самым красивым способоб. Вы осуществляете Case не по значениям индексов. Но вам решать.
|
|
|
|
|
Supreme Being
      
участник
Last Login: 15.10.2002 16:50
Сообщ.: 270,
Visits: 2 971
|
|
If e.Button is ToolBarButton1
Компилятор вроде этого поросил
|
|
|
|
|
Supreme Being
      
участник
Last Login: 05.02.2007 6:22
Сообщ.: 329,
Visits: 3 602
|
|
| На такую строку компилятор ругается...
|
|
|
|
|
Supreme Being
  | | | |