1

I have this form that I've been trying to make it work on a display setting set to 150% (Windows 7): enter image description here

I discover that when I comment out "myTableAdapter.Fill();" it works perfectly fine.

private void Form_Load(object sender, EventArgs e)
    {
        //myTableAdapter.Fill(myDatabaseDataSet.myaccessdatabase);
    }

enter image description here

The problem is that I need "myTableAdapter.Fill();" to load in order to be able to get the list of items that will be added to the combobox, but when the table adapter loads, things go a bit out of control (fonts are different sizes and at different places). enter image description here

I know this is NOT a known issue about the combobox showing up at the top left corner of the screen but rather an issue happening when datagridview loads. This ONLY happens when the Display font size is set to 150%.

This is my code:

 private void Form_Load(object sender, EventArgs e)
    {
        myTableAdapter.Fill(myDatabaseDataSet.MyAccessDatabase);

        //fixes the bug that makes the dropdown menus to pop up in the left
        //corner of the screen. This sample if repeats for each 
        //individual combobox...

        var item1 = toolStripComboBox1;
        var createControl1 = item1.Control.Parent.GetType().GetMethod("CreateControl", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
        createControl1.Invoke(item1.Control.Parent, new object[] { true });

             //combobox menustrip code to populate the list of names
             //coming from the access database (in this case for        
             //Managers). It is the same code for "Buyer"; "XP" 
             //and "Aging"...
             for (int intCount = 0; intCount < myDatabaseDataSet.Tables[0].Rows.Count; intCount++)
        {
            var val = myDatabaseDataSet.Tables[0].Rows[intCount][0].ToString();
            if (!toolStripComboBox1.Items.Contains(val))
            {
                toolStripComboBox1.Items.Add(val);
            }
        }
  }

Again, this does not happen when the display font is set to any other percentage. One of my theories is that this part of the code might need some tweaking so it does not cause the combobox to go bersek:

for (int intCount = 0; intCount < myDatabaseDataSet.Tables[0].Rows.Count; intCount++)
        {
            var val = myDatabaseDataSet.Tables[0].Rows[intCount][0].ToString();
            if (!toolStripComboBox1.Items.Contains(val))
            {
                toolStripComboBox1.Items.Add(val);
            }
        }

Is there perhaps an alternative way to load the combobox items where this rendering issue can be avoided?

Community
  • 1
  • 1
Pucho
  • 370
  • 2
  • 20
  • 1
    I couldn't reproduce the problem on a Windows 8.1. I had no font-size issue. Also after invoking `CreateControl` method, the placement issue was solves. But you may want to take a look at [this post](https://stackoverflow.com/questions/33588241/windows-forms-graphic-issue-on-windows-10-os). – Reza Aghaei Nov 23 '16 at 21:42
  • That fixed the problem. I have no idea how you tied the two issues together, but you were right on the money. If you have time, would you mind posting a quick explanation? Thanks a lot! – Pucho Nov 23 '16 at 21:59
  • 1
    You're welcome :) Like the reason of location problem (which I could guess it will be solved by invoking `CreateControl` and it did), I have no idea about the real reason for such bug, but since you used 150% for DPI, I could guess the issue will be solved by setting your application DPI Aware. – Reza Aghaei Nov 23 '16 at 22:09
  • Thanks again Reza :) – Pucho Nov 23 '16 at 22:14

0 Answers0