private void redraw()
        {
            // Scale window to number of config words:
            int numUnusedConfigs = K_MAXCONFIGS - Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords;

            numUnusedConfigs *= (int)(48 * ScalefactH);
            numUnusedConfigs -= (int)(24 * ScalefactH); // add a bit of length to the window for Asian OSs
            this.Size         = new Size((int)(this.Size.Width), (int)(this.Size.Height - numUnusedConfigs));

            // defaults for Baseline, Midrange
            string[] cfgNames = new string[K_MAXCONFIGS];
            for (int i = 1; i <= cfgNames.Length; i++)
            {
                cfgNames[i - 1] = string.Format("CONFIG{0:G}", i);
            }

            int configAddress   = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr / 2;
            int configIncrement = 1;

            if (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords == 1)
            { // baseline or midrange
                cfgNames[0] = "CONFIG";
            }

            // PIC18
            if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue == 0xFFFF)
            {
                configAddress   = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr;
                configIncrement = 2;
            }
            // 16-bit
            else if (Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue == 0xFFFFFF)
            {
                // PIC24F
                if (Pk2.FamilyIsPIC24FJ())
                {
                    for (int cw = 1; cw <= Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords; cw++)
                    {
                        cfgNames[Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords - cw] = string.Format("CW{0:G}", cw);
                    }
                    configAddress   = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr / 2;
                    configIncrement = 2;
                }
                // PIC24H, dsPIC33, dsPIC30 SMPS, PIC24F-KA-
                else if (Pk2.FamilyIsPIC24H() || Pk2.FamilyIsdsPIC33F() || Pk2.FamilyIsdsPIC30SMPS() ||
                         (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords == 9))
                {
                    cfgNames[0]     = "FBS";
                    cfgNames[1]     = "FSS";
                    cfgNames[2]     = "FGS";
                    cfgNames[3]     = "FOSCSEL";
                    cfgNames[4]     = "FOSC";
                    cfgNames[5]     = "FWDT";
                    cfgNames[6]     = "FPOR";
                    cfgNames[7]     = "FICD";
                    cfgNames[8]     = "FDS";
                    configAddress   = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr / 2;
                    configIncrement = 2;
                }
                // dsPIC30
                else
                {
                    cfgNames[0]     = "FOSC";
                    cfgNames[1]     = "FWDT";
                    cfgNames[2]     = "FBORPOR";
                    cfgNames[3]     = "FBS";
                    cfgNames[4]     = "FSS";
                    cfgNames[5]     = "FGS";
                    cfgNames[6]     = "FICD";
                    configAddress   = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr / 2;
                    configIncrement = 2;
                }
            }
            // PIC32
            else if (Pk2.FamilyIsPIC32())
            {
                cfgNames[0]     = "DEVCFG2L";
                cfgNames[1]     = "DEVCFG2H";
                cfgNames[2]     = "DEVCFG1L";
                cfgNames[3]     = "DEVCFG1H";
                cfgNames[4]     = "DEVCFG0L";
                cfgNames[5]     = "DEVCFG0H";
                configAddress   = (int)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigAddr;
                configIncrement = 2;
            }

            for (int w = 0; w < K_MAXCONFIGS; w++)
            {
                if (w < Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigWords)
                {
                    if (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[w] == 0)
                    {
                    }
                    configWords[w].name.Text = cfgNames[w];
                    configWords[w].addr.Text = string.Format("{0:X}", configAddress + (w * configIncrement));
                    ushort cword = (ushort)Pk2.DeviceBuffers.ConfigWords[w];
                    if (displayMask == 0)
                    {
                        cword &= (ushort)Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[w];
                    }
                    else if (displayMask == 1)
                    {
                        cword |= (ushort)~Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[w];
                    }
                    cword &= (ushort)Pk2.DevFile.Families[Pk2.GetActiveFamily()].BlankValue;
                    configWords[w].value.Text = string.Format("{0:X4}", cword);
                    ushort mask = 1;
                    for (int b = 0; b < 16; b++)
                    {
                        if ((Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[w] & mask) > 0)
                        {
                            if ((Pk2.DeviceBuffers.ConfigWords[w] & mask) > 0)
                            {
                                configWords[w].bits[b].Text = "1";
                            }
                            else
                            {
                                configWords[w].bits[b].Text = "0";
                            }
                        }
                        else
                        {
                            configWords[w].bits[b].Text      = "-";
                            configWords[w].bits[b].BackColor = System.Drawing.SystemColors.Control;
                            configWords[w].bits[b].Enabled   = false;
                        }
                        mask <<= 1;
                    }
                    if (Pk2.DevFile.PartsList[Pk2.ActivePart].ConfigMasks[w] == 0)
                    {
                        configWords[w].configPanel.Enabled = false;
                    }
                }
                else
                {
                    configWords[w].configPanel.Visible = false;
                }
            }
        }