private void ItemParameterChanged(object sender, EventArgs e)
        {
            if (TargetCollection == null || targetCollection.Count < 1 ||
                Index < 0 || Index >= targetCollection.Count)
            {
                return;
            }

            MASM_FormattingItem updatedValues = TargetCollection[Index];

            updatedValues.enable         = EnableToggle.Checked;
            updatedValues.prefix         = PrefixField.Text;
            updatedValues.postfix        = PostfixField.Text;
            updatedValues.property       = PropertyField.Text;
            updatedValues.mode           = ModeField.ToEnum(MASM_FormattingItem.ItemMode.Property);
            updatedValues.operationValue = ParseFloat(ValueField.Text);
            updatedValues.operationType  = OperationField.ToEnum(MASM_FormattingItem.OperationType.None);
            updatedValues.targetData     = TargetField.ToEnum(MASM_FormattingItem.TargetData.PropertyValue);
            updatedValues.roundMode      = RoundField.ToEnum(MASM_FormattingItem.RoundingType.None);
            updatedValues.modulo         = ModuloToggle.Checked;
            updatedValues.outFormat      = OutFormatField.Text;

            if (TargetCollection[Index] != updatedValues)
            {
                TargetCollection[Index] = updatedValues;
            }

            if (sender == CopyButton)
            {
                TargetCollection.Insert(index + 1, TargetCollection[Index]);
            }

            if (sender == MoveUpButton && index - 1 > -1)
            {
                TargetCollection.Move(index, index - 1);
            }

            if (sender == MoveDownButton && index + 1 < TargetCollection.Count)
            {
                TargetCollection.Move(index, index + 1);
            }

            if (sender == RemoveButton &&
                MessageBox.Show("Are you sure to delete item " + index + "?",
                                "Confirm Delete!", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                TargetCollection.RemoveAt(index);
                return;
            }
        }
        internal short GetModeField(ModeField field, short defaultValue, IntPtr modeHandle)
        {
            short dmOrientation;
            bool flag = false;
            try
            {
                if (modeHandle == IntPtr.Zero)
                {
                    try
                    {
                        modeHandle = this.GetHdevmodeInternal();
                        flag = true;
                    }
                    catch (InvalidPrinterException)
                    {
                        return defaultValue;
                    }
                }
                SafeNativeMethods.DEVMODE devmode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(SafeNativeMethods.GlobalLock(new HandleRef(this, modeHandle)), typeof(SafeNativeMethods.DEVMODE));
                switch (field)
                {
                    case ModeField.Orientation:
                        dmOrientation = devmode.dmOrientation;
                        break;

                    case ModeField.PaperSize:
                        dmOrientation = devmode.dmPaperSize;
                        break;

                    case ModeField.PaperLength:
                        dmOrientation = devmode.dmPaperLength;
                        break;

                    case ModeField.PaperWidth:
                        dmOrientation = devmode.dmPaperWidth;
                        break;

                    case ModeField.Copies:
                        dmOrientation = devmode.dmCopies;
                        break;

                    case ModeField.DefaultSource:
                        dmOrientation = devmode.dmDefaultSource;
                        break;

                    case ModeField.PrintQuality:
                        dmOrientation = devmode.dmPrintQuality;
                        break;

                    case ModeField.Color:
                        dmOrientation = devmode.dmColor;
                        break;

                    case ModeField.Duplex:
                        dmOrientation = devmode.dmDuplex;
                        break;

                    case ModeField.YResolution:
                        dmOrientation = devmode.dmYResolution;
                        break;

                    case ModeField.TTOption:
                        dmOrientation = devmode.dmTTOption;
                        break;

                    case ModeField.Collate:
                        dmOrientation = devmode.dmCollate;
                        break;

                    default:
                        dmOrientation = defaultValue;
                        break;
                }
                SafeNativeMethods.GlobalUnlock(new HandleRef(this, modeHandle));
            }
            finally
            {
                if (flag)
                {
                    SafeNativeMethods.GlobalFree(new HandleRef(this, modeHandle));
                }
            }
            return dmOrientation;
        }
 internal short GetModeField(ModeField field, short defaultValue)
 {
     return this.GetModeField(field, defaultValue, IntPtr.Zero);
 }
     internal short GetModeField(ModeField field, short defaultValue, IntPtr modeHandle) {
         bool ownHandle = false;
         short result;
         try {
         
             if (modeHandle == IntPtr.Zero) {
                 try {
                     modeHandle = GetHdevmodeInternal();
                     ownHandle = true;
                 }
                 catch (InvalidPrinterException) {
                     return defaultValue;
                 }
             }
 
             IntPtr modePointer = SafeNativeMethods.GlobalLock(new HandleRef(this, modeHandle));
             SafeNativeMethods.DEVMODE mode = (SafeNativeMethods.DEVMODE) UnsafeNativeMethods.PtrToStructure(modePointer, typeof(SafeNativeMethods.DEVMODE));
             switch (field) {
                 case ModeField.Orientation: result = mode.dmOrientation; break;
                 case ModeField.PaperSize: result = mode.dmPaperSize; break;
                 case ModeField.PaperLength: result = mode.dmPaperLength; break;
                 case ModeField.PaperWidth: result = mode.dmPaperWidth; break;
                 case ModeField.Copies: result = mode.dmCopies; break;
                 case ModeField.DefaultSource: result = mode.dmDefaultSource; break;
                 case ModeField.PrintQuality: result = mode.dmPrintQuality; break;
                 case ModeField.Color: result = mode.dmColor; break;
                 case ModeField.Duplex: result = mode.dmDuplex; break;
                 case ModeField.YResolution: result = mode.dmYResolution; break;
                 case ModeField.TTOption: result = mode.dmTTOption; break;
                 case ModeField.Collate: result = mode.dmCollate; break;
                 default:
                     Debug.Fail("Invalid field in GetModeField");
                     result = defaultValue;
                     break;
             }
             SafeNativeMethods.GlobalUnlock(new HandleRef(this, modeHandle));
         }
         finally
         {
             if (ownHandle) {
                 SafeNativeMethods.GlobalFree(new HandleRef(this, modeHandle));
             }
             
         }
         return result;
     }