in Combo_Box/C#/VsPkg.cs [380:463]
private void OnMenuMyDynamicCombo(object sender, EventArgs e)
{
if ((null == e) || (e == EventArgs.Empty))
{
// We should never get here; EventArgs are required.
throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown
}
OleMenuCmdEventArgs eventArgs = e as OleMenuCmdEventArgs;
if (eventArgs != null)
{
object input = eventArgs.InValue;
IntPtr vOut = eventArgs.OutValue;
if (vOut != IntPtr.Zero && input != null)
{
throw (new ArgumentException(Resources.BothInOutParamsIllegal)); // force an exception to be thrown
}
else if (vOut != IntPtr.Zero)
{
// when vOut is non-NULL, the IDE is requesting the current value for the combo
if (currentZoomFactor == 0)
{
Marshal.GetNativeVariantForObject(zoom_to_Fit, vOut);
}
else
{
string factorString = currentZoomFactor.ToString("P0", numberFormatInfo);
Marshal.GetNativeVariantForObject(factorString, vOut);
}
}
else if (input != null)
{
// new zoom value was selected or typed in
string inputString = input.ToString();
if (inputString.Equals(zoomToFit) || inputString.Equals(zoom_to_Fit))
{
currentZoomFactor = 0;
ShowMessage(Resources.MyDynamicCombo, zoom_to_Fit);
}
else
{
// There doesn't appear to be any percent-parsing routines in the framework (even though you can create
// a localized percentage in a string!). So, we need to remove any occurence of the localized Percent
// symbol, then parse the value that's left
try
{
float newZoom = Single.Parse(inputString.Replace(NumberFormatInfo.InvariantInfo.PercentSymbol, ""), CultureInfo.CurrentCulture);
newZoom = (float)Math.Round(newZoom);
if (newZoom < 0)
{
throw (new ArgumentException(Resources.ZoomMustBeGTZero)); // force an exception to be thrown
}
currentZoomFactor = newZoom / (float)100.0;
ShowMessage(Resources.MyDynamicCombo, newZoom.ToString(CultureInfo.CurrentCulture));
}
catch (FormatException)
{
// user typed in a non-numeric value, ignore it
}
catch (OverflowException)
{
// user typed in too large of a number, ignore it
}
}
}
else
{
// We should never get here
throw (new ArgumentException(Resources.InOutParamCantBeNULL)); // force an exception to be thrown
}
}
else
{
// We should never get here; EventArgs are required.
throw (new ArgumentException(Resources.EventArgsRequired)); // force an exception to be thrown
}
}