|
分類:[VB.NET/VB2005 以降]
下記の様なC#のソースをVBに変換したら、(AAAA 部)で
エラー 2 'Public Event CurrentChanged(sender As Object, e As Autodesk.Windows.RibbonPropertyChangedEventArgs)' はイベントであるため、直接呼び出すことはできません。イベントを発生させるには 'RaiseEvent' ステートメントを使用してください。
というエラーメッセージが出て、変換出来ません。
'RaiseEvent'について,当サイト、その他を調べましたが、理解出来ません。
可能なら、どの様に変換するれば良いか、教えて頂けないでしょうか?
環境は、下記の通りです。
Windows 8.1 64Bit
Microsoft Visual Studio 2010
Visual Basic クラスライブラリー
'*************************************************************************************
//----------------- 元のC#ソース----------------------------------------------
public void createLUNITSRibbonCombo()
{
RibbonControl ribCntrl
= RibbonServices.RibbonPaletteSet.RibbonControl;
RibbonTab ribTab = new RibbonTab();
ribTab.Title = "My custom tab";
ribTab.Name = "MyTab";
ribTab.Id = "MY_TAB_ID";
ribCntrl.Tabs.Add(ribTab);
RibbonPanelSource ribSourcePanel = new RibbonPanelSource();
ribSourcePanel.Title = "MyPanel1";
RibbonPanel ribPanel = new RibbonPanel();
ribPanel.Source = ribSourcePanel;
ribTab.Panels.Add(ribPanel);
RibbonCombo lunitsRibbonCombo = new RibbonCombo();
lunitsRibbonCombo.Name = "LUNITSCombo";
lunitsRibbonCombo.Id = "AdskLUNITSCombo";
System.Windows.Data.Binding bind1
= new System.Windows.Data.Binding();
bind1.Source = lunitValues;
lunitsRibbonCombo.ShowText = true;
lunitsRibbonCombo.Size = RibbonItemSize.Large;
lunitsRibbonCombo.ShowImage = false;
lunitsRibbonCombo.ItemsSourceBinding = bind1;
System.Windows.Data.Binding bind2
= new System.Windows.Data.Binding();
bind2.Path = new System.Windows.PropertyPath(".");
lunitsRibbonCombo.ItemTemplateTextBinding = bind2;
// Set its intial value
Int16 index = (Int16)
//Application.UIBindings.SystemVariables["LUNITS"].Value;
acadApp.UIBindings.SystemVariables["LUNITS"].Value;
lunitsRibbonCombo.Current = lunitValues[index];
lunitsRibbonCombo.CurrentChanged
+= new EventHandler<RibbonPropertyChangedEventArgs>
(ribCombo_CurrentChanged);
ribSourcePanel.Items.Add(lunitsRibbonCombo);
ribTab.IsActive = true;
}
// Callback to track changes to LUNIT made using the combobox
// Update the system variable based on the changes
void ribCombo_CurrentChanged(object sender,RibbonPropertyChangedEventArgs e)
{
//ILookup<SystemVariable> sysvars = Application.UIBindings.SystemVariables;
ILookup<SystemVariable> sysvars = acadApp.UIBindings.SystemVariables;
SystemVariable sv = sysvars["LUNITS"];
String newValue = e.NewValue.ToString();
int lunits = 1;
// Set the system variable based on the combobox new value
if (int.TryParse(newValue[0].ToString(), out lunits))
{
if (!lunits.ToString().Equals(
acadApp.UIBindings.SystemVariables["LUNITS"]
.Value.ToString()))
{
acadApp.UIBindings.SystemVariables["LUNITS"]
.Value = lunits;
}
}
}
//----------------------------------------------------------------------------
'*************************************************************************************
'----------------- VBに変換されたソース---------------------------------------
Public Sub createLUNITSRibbonCombo()
Dim ribCntrl As RibbonControl = RibbonServices.RibbonPaletteSet.RibbonControl
Dim ribTab As New RibbonTab()
ribTab.Title = "My custom tab"
ribTab.Name = "MyTab"
ribTab.Id = "MY_TAB_ID"
ribCntrl.Tabs.Add(ribTab)
Dim ribSourcePanel As New RibbonPanelSource()
ribSourcePanel.Title = "MyPanel1"
Dim ribPanel As New RibbonPanel()
ribPanel.Source = ribSourcePanel
ribTab.Panels.Add(ribPanel)
Dim lunitsRibbonCombo As New RibbonCombo()
lunitsRibbonCombo.Name = "LUNITSCombo"
lunitsRibbonCombo.Id = "AdskLUNITSCombo"
Dim bind1 As New System.Windows.Data.Binding()
bind1.Source = lunitValues
lunitsRibbonCombo.ShowText = True
lunitsRibbonCombo.Size = RibbonItemSize.Large
lunitsRibbonCombo.ShowImage = False
lunitsRibbonCombo.ItemsSourceBinding = bind1
Dim bind2 As New System.Windows.Data.Binding()
bind2.Path = New System.Windows.PropertyPath(".")
lunitsRibbonCombo.ItemTemplateTextBinding = bind2
' Set its intial value
'Application.UIBindings.SystemVariables["LUNITS"].Value;
Dim index As Int16 = CType(acadApp.UIBindings.SystemVariables("LUNITS").Value, Int16)
lunitsRibbonCombo.Current = lunitValues(index)
'--------------------------AAAA 部---------------------------------
' 下行でエラーが出る????
lunitsRibbonCombo.CurrentChanged += New EventHandler(Of RibbonPropertyChangedEventArgs)(AddressOf ribCombo_CurrentChanged)
'-----------------------------------------------------------------
ribSourcePanel.Items.Add(lunitsRibbonCombo)
ribTab.IsActive = True
End Sub
Private Sub ribCombo_CurrentChanged(ByVal sender As Object, ByVal e As RibbonPropertyChangedEventArgs)
'ILookup<SystemVariable> sysvars = Application.UIBindings.SystemVariables;
Dim sysvars As ILookup(Of SystemVariable) = acadApp.UIBindings.SystemVariables
Dim sv As SystemVariable = sysvars("LUNITS")
Dim newValue As [String] = e.NewValue.ToString()
Dim lunits As Integer = 1
' Set the system variable based on the combobox new value
If Integer.TryParse(newValue(0).ToString(), lunits) Then
If Not lunits.ToString().Equals(acadApp.UIBindings.SystemVariables("LUNITS").Value.ToString()) Then
acadApp.UIBindings.SystemVariables("LUNITS").Value = lunits
End If
End If
End Sub
'----------------------------------------------------------------------------
(以上)
|