Ejemplo n.º 1
0
    //</snippet1>

    // The following method shows the use of the DpiX and DpiY
    // properties. This example is designed for use with a Windows Form.
    // To run this example, paste it into a form that contains a ListBox named
    // listBox1 and call this method from the form's constructor or Load event.
    //<snippet4>
    private void PopulateListBoxWithGraphicsResolution()
    {
        Graphics boxGraphics  = listBox1.CreateGraphics();
        Graphics formGraphics = this.CreateGraphics();

        listBox1.Items.Add("ListBox horizontal resolution: "
                           + boxGraphics.DpiX);
        listBox1.Items.Add("ListBox vertical resolution: "
                           + boxGraphics.DpiY);

        boxGraphics.Dispose();
    }
Ejemplo n.º 2
0
        public Printer()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            // A graphic context will prove handy to align text.
            graphics = listBox.CreateGraphics();

            emptyLinesAtTop   = lines;
            lastPrintedColumn = Column.Instruction;

            // It is very important to measure the strings using a formatter that takes trailing
            // spaces into account.  Otherwise we would end up padding too much, and the trailing
            // spaces would disappear.
            stringFormatter.FormatFlags = StringFormatFlags.MeasureTrailingSpaces;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Add messages to Log
        /// </summary>
        /// <param name="dateTime">Time Stamp</param>
        /// <param name="message">String message that needs to be added</param>
        public void AddMessageToLog(DateTime dateTime, string message)
        {
            if (message != null)
            {
                log.Items.Add(dateTime.ToString() + " " + message);
                log.SelectedIndex   = log.Items.Count - 1;
                toolBarSave.Enabled = toolBarClear.Enabled = true;

                log.HorizontalScrollbar = true;
                Graphics g      = log.CreateGraphics();
                int      hzSize = (int)g.MeasureString(dateTime.ToString() + " " + message, log.Font).Width;
                if (hzSize > log.HorizontalExtent)
                {
                    log.HorizontalExtent = hzSize;
                }

                // This should only have to execute once.
                while (log.Items.Count > maxMessages)
                {
                    log.Items.RemoveAt(0);
                }
            }
        }
Ejemplo n.º 4
0
        //<Snippet1>
        private void DisplayHScroll()
        {
            // Make sure no items are displayed partially.
            listBox1.IntegralHeight = true;

            // Add items that are wide to the ListBox.
            for (int x = 0; x < 10; x++)
            {
                listBox1.Items.Add("Item  " + x.ToString() + " is a very large value that requires scroll bars");
            }

            // Display a horizontal scroll bar.
            listBox1.HorizontalScrollbar = true;

            // Create a Graphics object to use when determining the size of the largest item in the ListBox.
            Graphics g = listBox1.CreateGraphics();

            // Determine the size for HorizontalExtent using the MeasureString method using the last item in the list.
            int hzSize = (int)g.MeasureString(listBox1.Items[listBox1.Items.Count - 1].ToString(), listBox1.Font).Width;

            // Set the HorizontalExtent property.
            listBox1.HorizontalExtent = hzSize;
        }
Ejemplo n.º 5
0
        // Fix for Dev10 Bug 592077: Display Horizontal Scroll bar if the name exceeds the container.
        internal static void DisplayHScrollOnListBoxIfNecessary(ListBox listBox)
        {
            // Display a horizontal scroll bar if necessary.
            listBox.HorizontalScrollbar = true;

            // Create a Graphics object to use when determining the size of the largest item in the ListBox.
            var g = listBox.CreateGraphics();

            // Determine the size for HorizontalExtent using the MeasureString method.
            var maxHorizontalSize = -1;
            for (var i = 0; i < listBox.Items.Count; i++)
            {
                var hzSize = (int)g.MeasureString(listBox.Items[i].ToString(), listBox.Font).Width;
                if (hzSize > maxHorizontalSize)
                {
                    maxHorizontalSize = hzSize;
                }
            }
            // Set the HorizontalExtent property.
            if (maxHorizontalSize != -1)
            {
                listBox.HorizontalExtent = maxHorizontalSize;
            }
        }
Ejemplo n.º 6
0
        public void generateLadderFromSelection(double parentMZ, List <LadderInstance> currentListInstances)
        {
            m_currentInstances = currentListInstances;
            m_currentParentMZ  = parentMZ;

            m_currentlyDrawing = true;

            // This is a counter the fragment ladder instances
            int i = 0;

            // This is a counter for the list boxes.
            int listBoxCounter = 0;

            //this.columnCheckedListBox.Items.AddRange(currentListInstances[0].mzValueHeaders.ToArray());
            tabControl1.TabPages.Clear();
            tabControl1.Visible = false;
            tabControl1.TabPages.Add("Original");

            int indexOfFirstHalfEnd = 0;

            //find index of first non "b" checked item
            for (int j = 0; j < columnCheckedListBox.CheckedItems.Count; j++)
            {
                if (columnCheckedListBox.CheckedItems[j].ToString()[0] != 'b' && columnCheckedListBox.CheckedItems[j].ToString()[0] != 'c')
                {
                    indexOfFirstHalfEnd = j;
                    break;
                }
            }

            if (columnCheckedListBox.CheckedItems.Count != 0)
            {
                if (indexOfFirstHalfEnd == 0 && columnCheckedListBox.CheckedItems[columnCheckedListBox.CheckedItems.Count - 1].ToString()[0] == 'b')
                {
                    indexOfFirstHalfEnd = columnCheckedListBox.CheckedItems.Count;
                }
            }

            if (currentListInstances != null)
            {
                foreach (LadderInstance currentInstance in currentListInstances)
                {
                    // If plot is detached this value is incremented for each list box that represents
                    // an ion series.  For vertical fragment ladder orientation.
                    int xListBoxPosition = 6;

                    // If plot is detached this value is incremented for each list box that represents
                    // an ion series.  For horizontal fragment ladder orientation.
                    int yListBoxPosition = 6;

                    if (i > 0)
                    {
                        tabControl1.TabPages.Add("Modified" + i.ToString());
                    }
                    ListBox tempListBox = new System.Windows.Forms.ListBox();

                    //print all b or c ions that exist before the peptide sequence
                    for (int index = 0; index < indexOfFirstHalfEnd; index++)
                    {
                        //if (i == tabControl1.SelectedIndex)
                        peptideEditorTextBox.Text = currentInstance.PeptideString.ToString();
                        tempListBox                   = new System.Windows.Forms.ListBox();
                        tempListBox.BackColor         = System.Drawing.SystemColors.Control;
                        tempListBox.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                        tempListBox.ColumnWidth       = 40;
                        tempListBox.FormattingEnabled = true;
                        tempListBox.Location          = new System.Drawing.Point(xListBoxPosition, yListBoxPosition);
                        if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                        {
                            tempListBox.MultiColumn = true;
                        }
                        else
                        {
                            tempListBox.MultiColumn = false;
                        }
                        tempListBox.Size         = new System.Drawing.Size(45, 15);
                        tempListBox.BorderStyle  = BorderStyle.None;
                        tempListBox.DrawMode     = DrawMode.OwnerDrawFixed;
                        tempListBox.DrawItem    += new DrawItemEventHandler(tempListBox_DrawItem);
                        tempListBox.Click       += new EventHandler(tempListBox_Click);
                        tempListBox.DoubleClick += new EventHandler(tempListBox_DoubleClick);
                        tempListBox.Items.Add(columnCheckedListBox.CheckedItems[index].ToString());

                        for (int ind = 0; ind < currentInstance.mzValueHeaders.Count; ind++)
                        {
                            if (currentInstance.mzValueHeaders[ind] == columnCheckedListBox.CheckedItems[index].ToString())
                            {
                                listBoxCounter = ind;
                            }
                        }

                        // Reverse Array for y and z series
                        //This Reverse stuff should really be done in the ladder Instance Builder.

                        /*if ((columnCheckedListBox.CheckedItems[index].ToString().Contains("y")) ||
                         *  (columnCheckedListBox.CheckedItems[index].ToString().Contains("z")))
                         * {
                         *  string[] tempArray = currentInstance.mzValue[listBoxCounter];
                         *  int findNonNull = 0;
                         *  while ((findNonNull < tempArray.Length) && (tempArray[findNonNull] == ""))
                         ++findNonNull;
                         *  string[] splittedSubArrayOne = tempArray[findNonNull].Split('|');
                         *  string[] splittedSubArrayTwo = tempArray[(findNonNull + 1)].Split('|');
                         *  double outValue1 = 0.0;
                         *  double outValue2 = 0.0;
                         *
                         *  double.TryParse(splittedSubArrayOne[0], out outValue1);
                         *  double.TryParse(splittedSubArrayTwo[0], out outValue2);
                         *  if (outValue2 > outValue1)
                         *  {
                         *      Array.Reverse(tempArray);
                         *  }
                         *  tempListBox.Items.AddRange(tempArray);
                         * }
                         * else
                         * {*/
                        int currentLadderValueIndex = 0;
                        while (currentLadderValueIndex < currentInstance.mzValue[listBoxCounter].Length)
                        {
                            if (currentInstance.mzValue[listBoxCounter][currentLadderValueIndex] == "")
                            {
                                tempListBox.Items.Insert((currentLadderValueIndex + 1), "");
                            }
                            else
                            {
                                tempListBox.Items.Insert((currentLadderValueIndex + 1), currentInstance.mzValue[listBoxCounter][currentLadderValueIndex]);
                            }
                            ++currentLadderValueIndex;
                        }
                        //}

                        /**************This is to find the largest string. **************/
                        Graphics g = tempListBox.CreateGraphics();

                        SizeF largestSize = g.MeasureString(tempListBox.Items[0].ToString(), tempListBox.Font);

                        for (int k = 1; k < tempListBox.Items.Count; ++k)
                        {
                            string tempString = tempListBox.Items[k].ToString();
                            if (tempString != "")
                            {
                                if (largestSize.Width < g.MeasureString(tempString.Split('|')[0], tempListBox.Font).Width)
                                {
                                    largestSize = g.MeasureString(tempString.Split('|')[0], tempListBox.Font);
                                }
                            }
                        }

                        if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                        {
                            tempListBox.Size = new System.Drawing.Size(((tempListBox.Items.Count * 40) + 40), 13);
                        }
                        else
                        {
                            tempListBox.Size = new System.Drawing.Size((int)largestSize.Width, ((tempListBox.Items.Count * 13) + 15));
                        }
                        tempListBox.Location = new Point(xListBoxPosition, yListBoxPosition);
                        /**************************************************/

                        if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                        {
                            yListBoxPosition += 20 + 3;
                        }
                        else
                        {
                            xListBoxPosition += (int)largestSize.Width + 3;
                        }
                        tabControl1.TabPages[i].CreateControl();
                        tabControl1.TabPages[i].Controls.Add(tempListBox);
                    }


                    //print the index from the front of the peptide sequence
                    tempListBox                   = new System.Windows.Forms.ListBox();
                    tempListBox.BackColor         = System.Drawing.SystemColors.Control;
                    tempListBox.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                    tempListBox.ColumnWidth       = 40;
                    tempListBox.FormattingEnabled = true;
                    tempListBox.Location          = new System.Drawing.Point(xListBoxPosition, yListBoxPosition);
                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        tempListBox.MultiColumn = true;
                    }
                    else
                    {
                        tempListBox.MultiColumn = false;
                    }
                    tempListBox.Size        = new System.Drawing.Size(45, 15);
                    tempListBox.BorderStyle = BorderStyle.None;
                    tempListBox.Click      += new EventHandler(tempListBox_Click);
                    tempListBox.Items.Add((object)(" "));

                    int    lengthMinusMods  = 0;
                    String modificationList = "*+@!&#$%~`";

                    //calculate length of string minus modifications
                    foreach (char curChar in currentInstance.PeptideString.ToCharArray())
                    {
                        if (!modificationList.Contains(curChar))
                        {
                            lengthMinusMods++;
                        }
                    }

                    for (int peptideIndex = 0; peptideIndex < lengthMinusMods; peptideIndex++)
                    {
                        String indexStr = (peptideIndex + 1).ToString();
                        tempListBox.Items.Add((object)indexStr);
                    }

                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        tempListBox.Size = new System.Drawing.Size(((tempListBox.Items.Count * 40) + 40), 13);
                    }
                    else
                    {
                        tempListBox.Size = new System.Drawing.Size(40, ((tempListBox.Items.Count * 13) + 15));
                    }
                    tempListBox.Location = new Point(xListBoxPosition, yListBoxPosition);
                    tabControl1.TabPages[i].CreateControl();
                    tabControl1.TabPages[i].Controls.Add(tempListBox);
                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        yListBoxPosition += 20 + 3;
                    }
                    else
                    {
                        xListBoxPosition += 40 + 3;
                    }

                    //draw the peptide sequence
                    tempListBox                   = new System.Windows.Forms.ListBox();
                    tempListBox.BackColor         = System.Drawing.SystemColors.Control;
                    tempListBox.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                    tempListBox.ColumnWidth       = 40;
                    tempListBox.FormattingEnabled = true;
                    tempListBox.Location          = new System.Drawing.Point(xListBoxPosition, yListBoxPosition);
                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        tempListBox.MultiColumn = true;
                    }
                    else
                    {
                        tempListBox.MultiColumn = false;
                    }
                    tempListBox.Size        = new System.Drawing.Size(45, 15);
                    tempListBox.BorderStyle = BorderStyle.None;
                    tempListBox.Click      += new EventHandler(tempListBox_Click);
                    char[] peptide = currentInstance.PeptideString.ToCharArray();
                    tempListBox.Items.Add(" ");

                    for (int peptideStringIndex = 0; peptideStringIndex < peptide.Length; ++peptideStringIndex)
                    {
                        string aminoAcidCode = " " + peptide[peptideStringIndex];
                        if ((peptideStringIndex + 1) < peptide.Length &&
                            this.fragmentLadderOptions.modificationList.ContainsKey(peptide[(peptideStringIndex + 1)]))
                        {
                            aminoAcidCode += peptide[(peptideStringIndex + 1)];
                            ++peptideStringIndex;
                        }
                        tempListBox.Items.Add(aminoAcidCode);
                    }

                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        tempListBox.Size = new System.Drawing.Size(((tempListBox.Items.Count * 40) + 40), 13);
                    }
                    else
                    {
                        tempListBox.Size = new System.Drawing.Size(40, ((tempListBox.Items.Count * 13) + 15));
                    }
                    tempListBox.Location = new Point(xListBoxPosition, yListBoxPosition);
                    tabControl1.TabPages[i].CreateControl();
                    tabControl1.TabPages[i].Controls.Add(tempListBox);
                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        yListBoxPosition += 20 + 3;
                    }
                    else
                    {
                        xListBoxPosition += 40 + 3;
                    }
                    //end drawing peptide sequence

                    //print the index from the front of the peptide sequence
                    tempListBox                   = new System.Windows.Forms.ListBox();
                    tempListBox.BackColor         = System.Drawing.SystemColors.Control;
                    tempListBox.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                    tempListBox.ColumnWidth       = 40;
                    tempListBox.FormattingEnabled = true;
                    tempListBox.Location          = new System.Drawing.Point(xListBoxPosition, yListBoxPosition);
                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        tempListBox.MultiColumn = true;
                    }
                    else
                    {
                        tempListBox.MultiColumn = false;
                    }
                    tempListBox.Size        = new System.Drawing.Size(45, 15);
                    tempListBox.BorderStyle = BorderStyle.None;
                    tempListBox.Click      += new EventHandler(tempListBox_Click);
                    tempListBox.Items.Add((object)(" "));

                    for (int peptideIndex = 0; peptideIndex < lengthMinusMods; peptideIndex++)
                    {
                        String indexStr = (lengthMinusMods - peptideIndex).ToString();
                        tempListBox.Items.Add((object)indexStr);
                    }

                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        tempListBox.Size = new System.Drawing.Size(((tempListBox.Items.Count * 40) + 40), 13);
                    }
                    else
                    {
                        tempListBox.Size = new System.Drawing.Size(40, ((tempListBox.Items.Count * 13) + 15));
                    }
                    tempListBox.Location = new Point(xListBoxPosition, yListBoxPosition);
                    tabControl1.TabPages[i].CreateControl();
                    tabControl1.TabPages[i].Controls.Add(tempListBox);
                    if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                    {
                        yListBoxPosition += 20 + 3;
                    }
                    else
                    {
                        xListBoxPosition += 40 + 3;
                    }

                    //draw the y or z ions that occur after the peptide sequence
                    for (int index = indexOfFirstHalfEnd; index < columnCheckedListBox.CheckedItems.Count; index++)
                    {
                        //if (i == tabControl1.SelectedIndex)
                        peptideEditorTextBox.Text = currentInstance.PeptideString.ToString();
                        tempListBox                   = new System.Windows.Forms.ListBox();
                        tempListBox.BackColor         = System.Drawing.SystemColors.Control;
                        tempListBox.BorderStyle       = System.Windows.Forms.BorderStyle.FixedSingle;
                        tempListBox.ColumnWidth       = 40;
                        tempListBox.FormattingEnabled = true;
                        tempListBox.Location          = new System.Drawing.Point(xListBoxPosition, yListBoxPosition);
                        if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                        {
                            tempListBox.MultiColumn = true;
                        }
                        else
                        {
                            tempListBox.MultiColumn = false;
                        }
                        tempListBox.Size         = new System.Drawing.Size(45, 15);
                        tempListBox.BorderStyle  = BorderStyle.None;
                        tempListBox.DrawMode     = DrawMode.OwnerDrawFixed;
                        tempListBox.DrawItem    += new DrawItemEventHandler(tempListBox_DrawItem);
                        tempListBox.Click       += new EventHandler(tempListBox_Click);
                        tempListBox.DoubleClick += new EventHandler(tempListBox_DoubleClick);
                        tempListBox.Items.Add(columnCheckedListBox.CheckedItems[index].ToString());

                        for (int ind = 0; ind < currentInstance.mzValueHeaders.Count; ind++)
                        {
                            if (currentInstance.mzValueHeaders[ind] == columnCheckedListBox.CheckedItems[index].ToString())
                            {
                                listBoxCounter = ind;
                            }
                        }

                        // Reverse Array for y and z series
                        //This Reverse stuff should really be done in the ladder Instance Builder.

                        /*if ((columnCheckedListBox.CheckedItems[index].ToString().Contains("y")) ||
                         *  (columnCheckedListBox.CheckedItems[index].ToString().Contains("z")))
                         * {*/
                        string[] tempArray   = currentInstance.mzValue[listBoxCounter];
                        int      findNonNull = 0;
                        while ((findNonNull < tempArray.Length) && (tempArray[findNonNull] == ""))
                        {
                            ++findNonNull;
                        }
                        string[] splittedSubArrayOne = tempArray[findNonNull].Split('|');
                        string[] splittedSubArrayTwo = tempArray[(findNonNull + 1)].Split('|');
                        double   outValue1           = 0.0;
                        double   outValue2           = 0.0;

                        double.TryParse(splittedSubArrayOne[0], out outValue1);
                        double.TryParse(splittedSubArrayTwo[0], out outValue2);
                        if (outValue2 > outValue1)
                        {
                            Array.Reverse(tempArray);
                        }
                        tempListBox.Items.AddRange(tempArray);

                        /*}
                         * else
                         * {
                         *  int currentLadderValueIndex = 0;
                         *  while (currentLadderValueIndex < currentInstance.mzValue[listBoxCounter].Length)
                         *  {
                         *      if (currentInstance.mzValue[listBoxCounter][currentLadderValueIndex] == "")
                         *      {
                         *          tempListBox.Items.Insert((currentLadderValueIndex + 1), "");
                         *      }
                         *      else
                         *      {
                         *          tempListBox.Items.Insert((currentLadderValueIndex + 1), currentInstance.mzValue[listBoxCounter][currentLadderValueIndex]);
                         *      }
                         ++currentLadderValueIndex;
                         *  }
                         * }*/

                        /**************This is to find the largest string. **************/
                        Graphics g = tempListBox.CreateGraphics();

                        SizeF largestSize = g.MeasureString(tempListBox.Items[0].ToString(), tempListBox.Font);

                        for (int k = 1; k < tempListBox.Items.Count; ++k)
                        {
                            string tempString = tempListBox.Items[k].ToString();
                            if (tempString != "")
                            {
                                if (largestSize.Width < g.MeasureString(tempString.Split('|')[0], tempListBox.Font).Width)
                                {
                                    largestSize = g.MeasureString(tempString.Split('|')[0], tempListBox.Font);
                                }
                            }
                        }

                        if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                        {
                            tempListBox.Size = new System.Drawing.Size(((tempListBox.Items.Count * 40) + 40), 13);
                        }
                        else
                        {
                            tempListBox.Size = new System.Drawing.Size((int)largestSize.Width, ((tempListBox.Items.Count * 13) + 15));
                        }
                        tempListBox.Location = new Point(xListBoxPosition, yListBoxPosition);
                        /**************************************************/

                        if (!m_manager.m_mainForm.m_currentOptions.isPlotInMainForm)// m_fragmentLadderOptions.plotDetached)
                        {
                            yListBoxPosition += 20 + 3;
                        }
                        else
                        {
                            xListBoxPosition += (int)largestSize.Width + 3;
                        }
                        tabControl1.TabPages[i].CreateControl();
                        tabControl1.TabPages[i].Controls.Add(tempListBox);
                    }

                    tabControl1.TabPages[i].AutoScroll = true;
                    tabControl1.SelectedIndex          = i;
                    ++i;
                }
            }
            tabControl1.SelectedIndex = 0;
            tabControl1.Visible       = true;
            m_currentlyDrawing        = false;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Edits the specified object's value using the editor style indicated by the
        /// System.Drawing.Design.UITypeEditor.GetEditStyle() method</summary>
        /// <param name="context">An System.ComponentModel.ITypeDescriptorContext that can be used to gain
        /// additional context information</param>
        /// <param name="provider">An System.IServiceProvider that this editor can use to obtain services</param>
        /// <param name="value">The object to edit</param>
        /// <returns>The new value of the object. If the value of the object has not changed, this should
        /// return the same object it was passed.</returns>
        public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
        {
            m_editorService =
                provider.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;

            if (m_editorService != null)
            {
                ListBox listBox = new ListBox();
                listBox.DrawMode = DrawMode.OwnerDrawFixed;
                listBox.DrawItem += listBox_DrawItem;
                listBox.MouseMove += listBox_MouseMove;

                for (int i = 0; i < m_names.Length; i++)
                {
                    listBox.Items.Add(m_names[i]);
                    if (m_names[i].Equals(value) ||
                        m_values[i].Equals(value))
                    {
                        listBox.SelectedIndex = i;
                    }
                }

                // size control so all strings are completely visible
                using (Graphics g = listBox.CreateGraphics())
                {
                    float width = 0f;

                    foreach (string name in m_names)
                    {
                        float w = g.MeasureString(name, listBox.Font).Width;
                        width = Math.Max(width, w);
                    }

                    float height = m_names.Length * listBox.ItemHeight;
                    int scrollBarThickness = SystemInformation.VerticalScrollBarWidth;
                    if (height > listBox.Height - 4) // vertical scrollbar?
                        width += SystemInformation.VerticalScrollBarWidth;

                    if (width > listBox.Width)
                        listBox.Width = (int)width + 6;
                }

                listBox.SelectedIndexChanged += listBox_SelectedIndexChanged;
                listBox.MouseDown += listBox_OnMouseDown;
                listBox.MouseUp += listBox_OnMouseUp;
                listBox.MouseLeave += listBox_OnMouseLeave;
                listBox.PreviewKeyDown += listBox_OnPreviewKeyDown;

                m_editorService.DropDownControl(listBox);
                int index = listBox.SelectedIndex;
                if (index >= 0)
                {
                    object newValue = null;
                    if (value is int)
                        newValue = m_values[index];
                    else
                        newValue = m_names[index];
                    // be careful to return the same object if the value didn't change
                    if (!newValue.Equals(value))
                        value = newValue;
                }
            }

            return value;
        }
Ejemplo n.º 8
0
        private void ResizeToFit(ListBox list, string message)
        {
            using (var gfx = list.CreateGraphics())
            {
                var size = gfx.MeasureString(message, list.Font);
                var w = (int)Math.Ceiling(size.Width);
                list.Width = Math.Max(list.Width, w);
                list.Height = list.PreferredHeight;
            }

            Width = list.Width + (list.Left * 2);
            Height = list.Height + (list.Top * 2);
        }
Ejemplo n.º 9
0
        private void ListBox_initWidth(ListBox listBox)
        {
            int width = 0;
            Graphics g = listBox.CreateGraphics();

            foreach (object item in listBox.Items)
            {
                string text = item.ToString();
                SizeF s = g.MeasureString(text, listBox.Font);
                if (s.Width > width)
                    width = (int)s.Width;
            }
            listBox.HorizontalExtent = width + 2;
        }
Ejemplo n.º 10
0
 private void SetColumnWith(ListBox lb)
 {
     List<ITableInfo> ds = lb.DataSource as List<ITableInfo>;
     if (ds != null)
     {
         string txt = (from p in ds
                       orderby p.RawName.Length descending
                       select p.RawName).First();
         int width = (int)lb.CreateGraphics().MeasureString(txt, lb.Font).Width;
         lb.ColumnWidth = width;
     }
 }